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(SoundboardSounds::Table) .if_not_exists() .col( ColumnDef::new(SoundboardSounds::Id) .uuid() .not_null() .primary_key(), ) .col(ColumnDef::new(SoundboardSounds::GuildId).uuid().not_null()) .col(ColumnDef::new(SoundboardSounds::Name).string().not_null()) .col(ColumnDef::new(SoundboardSounds::Icon).string().not_null()) .col( ColumnDef::new(SoundboardSounds::FilePath) .string() .not_null(), ) .col( ColumnDef::new(SoundboardSounds::CreatedByUserId) .uuid() .not_null(), ) .col( ColumnDef::new(SoundboardSounds::CreatedAt) .timestamp_with_time_zone() .not_null() .default(Expr::current_timestamp()), ) .foreign_key( ForeignKey::create() .name("fk_soundboard_sounds_guild") .from(SoundboardSounds::Table, SoundboardSounds::GuildId) .to(Guilds::Table, Guilds::Id) .on_delete(ForeignKeyAction::Cascade), ) .foreign_key( ForeignKey::create() .name("fk_soundboard_sounds_user") .from(SoundboardSounds::Table, SoundboardSounds::CreatedByUserId) .to(Users::Table, Users::Id), ) .to_owned(), ) .await } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager .drop_table(Table::drop().table(SoundboardSounds::Table).to_owned()) .await } } #[derive(DeriveIden)] enum SoundboardSounds { Table, Id, GuildId, Name, Icon, FilePath, CreatedByUserId, CreatedAt, } #[derive(DeriveIden)] enum Users { Table, Id, } #[derive(DeriveIden)] enum Guilds { Table, Id, }