wip: Migration works now, still writing mirgations

This commit is contained in:
2026-03-26 00:13:43 +00:00
parent ba4a702574
commit 27083de136
7 changed files with 57 additions and 3 deletions
+2
View File
@@ -3,6 +3,7 @@ pub use sea_orm_migration::prelude::*;
mod m20260325_145211_servers;
mod m20260325_145717_members;
mod m20260325_162920_messages;
mod m20260325_233947_content;
pub struct Migrator;
@@ -13,6 +14,7 @@ impl MigratorTrait for Migrator {
Box::new(m20260325_145211_servers::Migration),
Box::new(m20260325_145717_members::Migration),
Box::new(m20260325_162920_messages::Migration),
Box::new(m20260325_233947_content::Migration),
]
}
}
@@ -1,5 +1,7 @@
use sea_orm_migration::{prelude::*, schema::*};
use crate::m20260325_233947_content::Content;
#[derive(DeriveMigrationName)]
pub struct Migration;
@@ -14,7 +16,12 @@ impl MigrationTrait for Migration {
.col(pk_auto(Messages::Id))
.col(integer(Messages::IdDiscord))
.col(integer(Messages::IdSender))
.col(integer(Messages::IdContent)) // Change to foreign key
.col(integer(Messages::IdContent))
.foreign_key(
ForeignKey::create()
.from(Messages::Table, Messages::IdContent)
.to(Content::Table, Content::Id),
)
.col(integer(Messages::IdServer))
.to_owned(),
)
@@ -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(Content::Table)
.if_not_exists()
.col(pk_auto(Content::Id))
.col(string(Content::Content))
.col(string(Content::Type))
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Content::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
pub enum Content {
Table,
Id,
Content,
Type,
}
+9 -1
View File
@@ -1,6 +1,14 @@
use migration::sea_orm::{ConnectOptions, Database, DatabaseConnection};
use sea_orm_migration::prelude::*;
#[async_std::main]
async fn main() {
cli::run_cli(migration::Migrator).await;
let db = Database::connect("sqlite://./db.sqlite?mode=rwc")
.await
.unwrap();
db.execute_unprepared("PRAGMA foreign_keys = ON;")
.await
.unwrap();
let db_fn = async move |_| Ok((db));
cli::run_cli_with_connection(migration::Migrator, db_fn).await;
}