init
All checks were successful
/ upload (release) Successful in 1m54s

This commit is contained in:
pavel 2026-02-15 23:16:26 +01:00
commit 9ae6d88c21
24 changed files with 7589 additions and 0 deletions

11
migration/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "migration"
version = "0.1.0"
edition = "2024"
[lib]
name = "migration"
path = "src/lib.rs"
[dependencies]
sea-orm-migration = { version = "1.1.19" }

16
migration/src/lib.rs Normal file
View file

@ -0,0 +1,16 @@
pub use sea_orm_migration::prelude::*;
mod m20220101_000001_create_event_table;
mod m20250215_213300_create_user_table;
pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
Box::new(m20220101_000001_create_event_table::Migration),
Box::new(m20250215_213300_create_user_table::Migration),
]
}
}

View file

@ -0,0 +1,49 @@
use sea_orm_migration::prelude::*;
#[derive(Iden)]
enum Event {
Table,
Id,
Name,
From,
To,
}
#[derive(Iden)]
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20220101_000001_create_event_table"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(Event::Table)
.if_not_exists()
.col(
ColumnDef::new(Event::Id)
.big_integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Event::Name).string().not_null())
.col(ColumnDef::new(Event::From).timestamp().not_null())
.col(ColumnDef::new(Event::To).timestamp().not_null())
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Event::Table).to_owned())
.await
}
}

View file

@ -0,0 +1,87 @@
use sea_orm_migration::prelude::*;
#[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(User::Table)
.if_not_exists()
.col(
ColumnDef::new(User::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(User::Sub).string().not_null().unique_key())
.col(ColumnDef::new(User::Email).string().not_null())
.col(ColumnDef::new(User::Name).string().not_null())
.to_owned(),
)
.await?;
manager
.alter_table(
Table::alter()
.table(Event::Table)
.add_column(ColumnDef::new(Event::UserId).integer())
.to_owned(),
)
.await?;
manager
.create_foreign_key(
ForeignKey::create()
.name("fk-event-user_id")
.from(Event::Table, Event::UserId)
.to(User::Table, User::Id)
.on_delete(ForeignKeyAction::Cascade)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_foreign_key(
ForeignKey::drop()
.name("fk-event-user_id")
.table(Event::Table)
.to_owned(),
)
.await?;
manager
.alter_table(
Table::alter()
.table(Event::Table)
.drop_column(Event::UserId)
.to_owned(),
)
.await?;
manager
.drop_table(Table::drop().table(User::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum User {
Table,
Id,
Sub,
Email,
Name,
}
#[derive(DeriveIden)]
enum Event {
Table,
UserId,
}