land_migration/
m20230619_000001_create_projectdeployment_table.rs

1use sea_orm_migration::prelude::*;
2
3#[derive(DeriveMigrationName)]
4pub struct Migration;
5
6#[async_trait::async_trait]
7impl MigrationTrait for Migration {
8    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
9        manager
10            .create_table(
11                Table::create()
12                    .table(ProjectDeployment::Table)
13                    .if_not_exists()
14                    .col(
15                        ColumnDef::new(ProjectDeployment::Id)
16                            .integer()
17                            .not_null()
18                            .auto_increment()
19                            .primary_key(),
20                    )
21                    .col(
22                        ColumnDef::new(ProjectDeployment::OwnerId)
23                            .integer()
24                            .not_null(),
25                    )
26                    .col(
27                        ColumnDef::new(ProjectDeployment::ProjectId)
28                            .integer()
29                            .not_null(),
30                    )
31                    .col(
32                        ColumnDef::new(ProjectDeployment::Domain)
33                            .string_len(64)
34                            .not_null()
35                            .unique_key(),
36                    )
37                    .col(
38                        ColumnDef::new(ProjectDeployment::ProdDomain)
39                            .string_len(64)
40                            .not_null(),
41                    )
42                    .col(
43                        ColumnDef::new(ProjectDeployment::Uuid)
44                            .string_len(64)
45                            .not_null()
46                            .unique_key(),
47                    )
48                    .col(
49                        ColumnDef::new(ProjectDeployment::StoragePath)
50                            .string_len(128)
51                            .not_null(),
52                    )
53                    .col(
54                        ColumnDef::new(ProjectDeployment::CreatedAt)
55                            .timestamp()
56                            .extra("DEFAULT CURRENT_TIMESTAMP".to_string())
57                            .not_null(),
58                    )
59                    .col(
60                        ColumnDef::new(ProjectDeployment::UpdatedAt)
61                            .timestamp()
62                            .extra("DEFAULT CURRENT_TIMESTAMP".to_string())
63                            .not_null(),
64                    )
65                    .col(
66                        ColumnDef::new(ProjectDeployment::ProdStatus)
67                            .integer()
68                            .default(0)
69                            .not_null(),
70                    )
71                    .col(
72                        ColumnDef::new(ProjectDeployment::DeployStatus)
73                            .integer()
74                            .default(0)
75                            .not_null(),
76                    )
77                    .to_owned(),
78            )
79            .await?;
80
81        manager
82            .create_index(
83                Index::create()
84                    .if_not_exists()
85                    .name("idx-project-deployment-owner")
86                    .table(ProjectDeployment::Table)
87                    .col(ProjectDeployment::OwnerId)
88                    .to_owned(),
89            )
90            .await?;
91
92        manager
93            .create_index(
94                Index::create()
95                    .if_not_exists()
96                    .name("idx-project-deployment-domain")
97                    .table(ProjectDeployment::Table)
98                    .col(ProjectDeployment::Domain)
99                    .to_owned(),
100            )
101            .await?;
102        Ok(())
103    }
104
105    async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
106        Ok(())
107    }
108}
109
110#[derive(Iden)]
111enum ProjectDeployment {
112    Table,
113    Id,
114    OwnerId,
115    ProjectId,
116    Domain,
117    ProdDomain,
118    Uuid,
119    StoragePath,
120    CreatedAt,
121    UpdatedAt,
122    ProdStatus,
123    DeployStatus,
124}