wip
This commit is contained in:
@@ -12,11 +12,7 @@ path = "src/lib.rs"
|
||||
async-std = { version = "1", features = ["attributes", "tokio1"] }
|
||||
|
||||
[dependencies.sea-orm-migration]
|
||||
version = "1.1.0"
|
||||
version = "2.0.0-rc"
|
||||
features = [
|
||||
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
|
||||
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
|
||||
# e.g.
|
||||
# "runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
|
||||
# "sqlx-postgres", # `DATABASE_DRIVER` feature
|
||||
"sqlx-sqlite", "runtime-tokio-rustls"
|
||||
]
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20220101_000001_create_table;
|
||||
mod m20260325_145211_servers;
|
||||
mod m20260325_145717_members;
|
||||
mod m20260325_162920_messages;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![Box::new(m20220101_000001_create_table::Migration)]
|
||||
vec![
|
||||
Box::new(m20260325_145211_servers::Migration),
|
||||
Box::new(m20260325_145717_members::Migration),
|
||||
Box::new(m20260325_162920_messages::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
+8
-14
@@ -6,36 +6,30 @@ 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(Server::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_auto(Post::Id))
|
||||
.col(string(Post::Title))
|
||||
.col(string(Post::Text))
|
||||
.col(pk_auto(Server::Id))
|
||||
.col(string(Server::IdDiscord))
|
||||
.col(string(Server::Name))
|
||||
.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(Server::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Post {
|
||||
enum Server {
|
||||
Table,
|
||||
Id,
|
||||
Title,
|
||||
Text,
|
||||
IdDiscord,
|
||||
Name,
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Members::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_auto(Members::Id))
|
||||
.col(integer(Members::IdDiscord))
|
||||
.col(string(Members::Name))
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Members::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Members {
|
||||
Table,
|
||||
Id,
|
||||
IdDiscord,
|
||||
Name,
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Messages::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_auto(Messages::Id))
|
||||
.col(integer(Messages::IdDiscord))
|
||||
.col(integer(Messages::IdSender))
|
||||
.col(integer(Messages::IdContent)) // Change to foreign key
|
||||
.col(integer(Messages::IdServer))
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Messages::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Messages {
|
||||
Table,
|
||||
Id,
|
||||
IdDiscord,
|
||||
IdSender,
|
||||
IdContent,
|
||||
IdServer,
|
||||
}
|
||||
Reference in New Issue
Block a user