@@ -5,45 +5,45 @@ pub struct Migration;
55
66#[ async_trait:: async_trait]
77impl MigrationTrait for Migration {
8- async fn up ( & self , manager : & SchemaManager ) -> Result < ( ) , DbErr > {
9- manager
10- . create_table (
11- Table :: create ( )
12- . table ( "books" )
13- . if_not_exists ( )
14- . col (
15- ColumnDef :: new ( Book :: Id )
16- . integer ( )
17- . not_null ( )
18- . primary_key ( )
19- . auto_increment ( ) ,
20- )
21- . col ( ColumnDef :: new ( Book :: Title ) . string ( ) . not_null ( ) )
22- . col ( ColumnDef :: new ( Book :: Author ) . string ( ) . not_null ( ) )
23- . col ( ColumnDef :: new ( Book :: Isbn ) . string ( ) . unique_key ( ) )
24- . col ( ColumnDef :: new ( Book :: TotalCopies ) . integer ( ) . not_null ( ) )
25- . col ( ColumnDef :: new ( Book :: AvailableCopies ) . integer ( ) . not_null ( ) )
26- . col ( ColumnDef :: new ( Book :: PublishedYear ) . integer ( ) . null ( ) )
27- . to_owned ( ) ,
28- )
29- . await
30- }
8+ async fn up ( & self , manager : & SchemaManager ) -> Result < ( ) , DbErr > {
9+ manager
10+ . create_table (
11+ Table :: create ( )
12+ . table ( "books" )
13+ . if_not_exists ( )
14+ . col (
15+ ColumnDef :: new ( Book :: Id )
16+ . integer ( )
17+ . not_null ( )
18+ . primary_key ( )
19+ . auto_increment ( ) ,
20+ )
21+ . col ( ColumnDef :: new ( Book :: Title ) . string ( ) . not_null ( ) )
22+ . col ( ColumnDef :: new ( Book :: Author ) . string ( ) . not_null ( ) )
23+ . col ( ColumnDef :: new ( Book :: Isbn ) . string ( ) . unique_key ( ) )
24+ . col ( ColumnDef :: new ( Book :: TotalCopies ) . integer ( ) . not_null ( ) )
25+ . col ( ColumnDef :: new ( Book :: AvailableCopies ) . integer ( ) . not_null ( ) )
26+ . col ( ColumnDef :: new ( Book :: PublishedYear ) . integer ( ) . null ( ) )
27+ . to_owned ( ) ,
28+ )
29+ . await
30+ }
3131
32- async fn down ( & self , manager : & SchemaManager ) -> Result < ( ) , DbErr > {
33- manager
34- . drop_table ( Table :: drop ( ) . table ( Book :: Table ) . to_owned ( ) )
35- . await
36- }
32+ async fn down ( & self , manager : & SchemaManager ) -> Result < ( ) , DbErr > {
33+ manager
34+ . drop_table ( Table :: drop ( ) . table ( Book :: Table ) . to_owned ( ) )
35+ . await
36+ }
3737}
3838
3939#[ derive( Iden ) ]
4040enum Book {
41- Table ,
42- Id ,
43- Title ,
44- Author ,
45- Isbn ,
46- TotalCopies ,
47- AvailableCopies ,
48- PublishedYear ,
41+ Table ,
42+ Id ,
43+ Title ,
44+ Author ,
45+ Isbn ,
46+ TotalCopies ,
47+ AvailableCopies ,
48+ PublishedYear ,
4949}
0 commit comments