code: entity, migration, quick migration

This commit is contained in:
Gabor Körber
2023-12-20 23:12:02 +01:00
parent 099278a5d5
commit 52a69e4695
13 changed files with 784 additions and 54 deletions

View File

@@ -6,42 +6,36 @@ pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
todo!();
manager
.create_table(
Table::create()
.table(Post::Table)
.table(User::Table)
.if_not_exists()
.col(
ColumnDef::new(Post::Id)
ColumnDef::new(User::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Post::Title).string().not_null())
.col(ColumnDef::new(Post::Text).string().not_null())
.col(ColumnDef::new(User::Username).string().not_null())
.col(ColumnDef::new(User::Description).string().not_null())
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
todo!();
manager
.drop_table(Table::drop().table(Post::Table).to_owned())
.drop_table(Table::drop().table(User::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum Post {
enum User {
Table,
Id,
Title,
Text,
Username,
Description,
}