Add track2groups table creation migration

This commit is contained in:
D. Scott Boggs 2023-06-06 12:38:31 -04:00
parent b8ffd5c0b5
commit c9c12a0ec7
2 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,61 @@
use sea_orm_migration::{async_trait::async_trait, prelude::*};
use super::{
m20230606_000001_create_tracks_table::Tracks, m20230606_000003_create_groups_table::Groups,
};
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20230606_000001_create_tracks_table"
}
}
#[async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(Track2Groups::Table)
.col(
ColumnDef::new(Track2Groups::Id)
.integer()
.not_null()
.primary_key()
.auto_increment(),
)
.col(ColumnDef::new(Track2Groups::TrackId).integer().not_null())
.col(ColumnDef::new(Track2Groups::GroupId).integer().not_null())
.foreign_key(
ForeignKey::create()
.name("fk-track2groups-track_id")
.from(Track2Groups::Table, Track2Groups::TrackId)
.to(Tracks::Table, Tracks::Id),
)
.foreign_key(
ForeignKey::create()
.name("fk-track2groups-group_id")
.from(Track2Groups::Table, Track2Groups::GroupId)
.to(Groups::Table, Groups::Id),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Track2Groups::Table).to_owned())
.await
}
}
#[derive(Iden)]
pub enum Track2Groups {
Table,
Id,
TrackId,
GroupId,
}

View file

@ -1,6 +1,7 @@
mod m20230606_000001_create_tracks_table;
mod m20230606_000002_create_ticks_table;
mod m20230606_000003_create_groups_table;
mod m20230606_000004_create_track2groups_table;
use sea_orm_migration::prelude::*;