oauth2
This commit is contained in:
77
backend/src/migration/m20250116_000001_add_oauth_fields.rs
Normal file
77
backend/src/migration/m20250116_000001_add_oauth_fields.rs
Normal 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,
|
||||
}
|
||||
Reference in New Issue
Block a user