File tree Expand file tree Collapse file tree 2 files changed +58
-1
lines changed Expand file tree Collapse file tree 2 files changed +58
-1
lines changed Original file line number Diff line number Diff line change 1+ use sea_orm_migration:: { prelude:: * , schema:: * , sea_orm:: DatabaseBackend } ;
2+
3+ #[ derive( DeriveMigrationName ) ]
4+ pub struct Migration ;
5+
6+ #[ async_trait:: async_trait]
7+ impl MigrationTrait for Migration {
8+ async fn up ( & self , manager : & SchemaManager ) -> Result < ( ) , DbErr > {
9+ let backend = manager. get_database_backend ( ) ;
10+
11+ match backend {
12+ DatabaseBackend :: Postgres => {
13+ // ALTER TABLE builds ALTER COLUMN end_at DROP NOT NULL
14+ manager
15+ . alter_table (
16+ Table :: alter ( )
17+ . table ( Builds :: Table )
18+ . modify_column ( timestamp_null ( Builds :: EndAt ) . to_owned ( ) )
19+ . to_owned ( ) ,
20+ )
21+ . await ?;
22+ }
23+ DatabaseBackend :: Sqlite | DatabaseBackend :: MySql => { }
24+ }
25+
26+ Ok ( ( ) )
27+ }
28+
29+ async fn down ( & self , manager : & SchemaManager ) -> Result < ( ) , DbErr > {
30+ let backend = manager. get_database_backend ( ) ;
31+
32+ match backend {
33+ DatabaseBackend :: Postgres => {
34+ // Reverting the change - making end_at NOT NULL again
35+ // Note: This could fail if there are NULL values in the column
36+ manager
37+ . alter_table (
38+ Table :: alter ( )
39+ . table ( Builds :: Table )
40+ . modify_column ( timestamp ( Builds :: EndAt ) . to_owned ( ) )
41+ . to_owned ( ) ,
42+ )
43+ . await ?;
44+ }
45+ DatabaseBackend :: Sqlite | DatabaseBackend :: MySql => { }
46+ }
47+
48+ Ok ( ( ) )
49+ }
50+ }
51+
52+ #[ derive( DeriveIden ) ]
53+ enum Builds {
54+ Table ,
55+ EndAt ,
56+ }
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ mod m20250628_025312_add_username_in_conversation;
4545mod m20250702_072055_add_item_assignees;
4646mod m20250710_073119_create_reactions;
4747mod m20250725_103004_add_note;
48-
48+ mod m20250804_151214_alter_builds_end_at ;
4949/// Creates a primary key column definition with big integer type.
5050///
5151/// # Arguments
@@ -78,6 +78,7 @@ impl MigratorTrait for Migrator {
7878 Box :: new( m20250702_072055_add_item_assignees:: Migration ) ,
7979 Box :: new( m20250710_073119_create_reactions:: Migration ) ,
8080 Box :: new( m20250725_103004_add_note:: Migration ) ,
81+ Box :: new( m20250804_151214_alter_builds_end_at:: Migration ) ,
8182 ]
8283 }
8384}
You can’t perform that action at this time.
0 commit comments