This commit is contained in:
arrelin
2026-01-17 10:15:44 +03:00
parent 564adac629
commit a4b06fb057
26 changed files with 1542 additions and 346 deletions

View File

@@ -0,0 +1,77 @@
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
.alter_table(
Table::alter()
.table(User::Table)
.add_column(ColumnDef::new(User::Email).string().unique_key())
.add_column(ColumnDef::new(User::GoogleId).string().unique_key())
.add_column(ColumnDef::new(User::FamilyId).integer())
.modify_column(ColumnDef::new(User::PasswordHash).string().null())
.modify_column(ColumnDef::new(User::Username).string().null())
.to_owned(),
)
.await?;
manager
.create_foreign_key(
ForeignKey::create()
.name("fk_user_family")
.from(User::Table, User::FamilyId)
.to(Family::Table, Family::Id)
.on_delete(ForeignKeyAction::SetNull)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_foreign_key(
ForeignKey::drop()
.name("fk_user_family")
.table(User::Table)
.to_owned(),
)
.await?;
manager
.alter_table(
Table::alter()
.table(User::Table)
.drop_column(User::Email)
.drop_column(User::GoogleId)
.drop_column(User::FamilyId)
.modify_column(ColumnDef::new(User::PasswordHash).string().not_null())
.modify_column(ColumnDef::new(User::Username).string().not_null())
.to_owned(),
)
.await?;
Ok(())
}
}
#[derive(DeriveIden)]
enum User {
Table,
Email,
GoogleId,
FamilyId,
PasswordHash,
Username,
}
#[derive(DeriveIden)]
enum Family {
Table,
Id,
}