use sea_orm_migration::prelude::*; use crate::db_enums::*; #[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(TokensLocations::Table) .if_not_exists() .col( ColumnDef::new(TokensLocations::Id) .integer() .not_null() .auto_increment() .primary_key(), ) .col( ColumnDef::new(TokensLocations::TokenId) .integer().not_null().unique_key() ) .col( ColumnDef::new(TokensLocations::LocationId) .integer().not_null().unique_key() ) .foreign_key( ForeignKeyCreateStatement::new() .name("fk_token") .from(TokensLocations::Table, TokensLocations::TokenId) .to(UserTokens::Table, UserTokens::Id) ) .foreign_key( ForeignKeyCreateStatement::new() .name("fk_location") .from(TokensLocations::Table, TokensLocations::LocationId) .to(Locations::Table, Locations::Id) ) .to_owned(), ) .await } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { // Replace the sample below with your own migration scripts manager .drop_table(Table::drop().table(TokensLocations::Table).to_owned()) .await } }