From c9c12a0ec7abd668982681a8b785f99feb284022 Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Tue, 6 Jun 2023 12:38:31 -0400 Subject: [PATCH] Add track2groups table creation migration --- ...230606_000004_create_track2groups_table.rs | 61 +++++++++++++++++++ src/migrator/mod.rs | 1 + 2 files changed, 62 insertions(+) create mode 100644 src/migrator/m20230606_000004_create_track2groups_table.rs diff --git a/src/migrator/m20230606_000004_create_track2groups_table.rs b/src/migrator/m20230606_000004_create_track2groups_table.rs new file mode 100644 index 0000000..dd1a3b8 --- /dev/null +++ b/src/migrator/m20230606_000004_create_track2groups_table.rs @@ -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, +} diff --git a/src/migrator/mod.rs b/src/migrator/mod.rs index 993e70f..242ef4f 100644 --- a/src/migrator/mod.rs +++ b/src/migrator/mod.rs @@ -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::*;