basic generator
This commit is contained in:
12
tests/migration/src/lib.rs
Normal file
12
tests/migration/src/lib.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20250318_045009_create_user;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![Box::new(m20250318_045009_create_user::Migration)]
|
||||
}
|
||||
}
|
||||
68
tests/migration/src/m20250318_045009_create_user.rs
Normal file
68
tests/migration/src/m20250318_045009_create_user.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
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
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(User::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_auto(User::Id))
|
||||
.col(string(User::Username).unique_key().not_null())
|
||||
.col(string(User::Email).unique_key().not_null())
|
||||
.col(string(User::Password).not_null())
|
||||
.col(string(User::Test))
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.table(User::Table)
|
||||
.name("idx_test")
|
||||
.col(User::Test)
|
||||
.unique()
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
// manager
|
||||
// .create_index(
|
||||
// Index::create()
|
||||
// .table(User::Table)
|
||||
// .name("idx_id")
|
||||
// .col(User::Id)
|
||||
// .to_owned(),
|
||||
// )
|
||||
// .await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// Replace the sample below with your own migration scripts
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(User::Table).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().table(User::Table).name("idx_test").to_owned())
|
||||
.await
|
||||
// manager
|
||||
// .drop_index(Index::drop().table(User::Table).name("idx_id").to_owned())
|
||||
// .await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum User {
|
||||
Table,
|
||||
Id,
|
||||
Username,
|
||||
Email,
|
||||
Password,
|
||||
Test,
|
||||
}
|
||||
6
tests/migration/src/main.rs
Normal file
6
tests/migration/src/main.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
cli::run_cli(migration::Migrator).await;
|
||||
}
|
||||
Reference in New Issue
Block a user