From b8ffd5c0b5b12bb1e2c77cce74952a06961b193e Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Tue, 6 Jun 2023 12:14:58 -0400 Subject: [PATCH] Add groups table creation migration --- .../m20230606_000003_create_groups_table.rs | 46 +++++++++++++++++++ src/migrator/mod.rs | 1 + 2 files changed, 47 insertions(+) create mode 100644 src/migrator/m20230606_000003_create_groups_table.rs diff --git a/src/migrator/m20230606_000003_create_groups_table.rs b/src/migrator/m20230606_000003_create_groups_table.rs new file mode 100644 index 0000000..9d79579 --- /dev/null +++ b/src/migrator/m20230606_000003_create_groups_table.rs @@ -0,0 +1,46 @@ +use sea_orm_migration::{async_trait::async_trait, prelude::*}; + +pub struct Migration; + +impl MigrationName for Migration { + fn name(&self) -> &str { + "m20230606_000003_create_groups_table" + } +} + +#[async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .create_table( + Table::create() + .table(Groups::Table) + .col( + ColumnDef::new(Groups::Id) + .integer() + .not_null() + .auto_increment() + .primary_key(), + ) + .col(ColumnDef::new(Groups::Name).string().not_null()) + .col(ColumnDef::new(Groups::Description).string().not_null()) + .col(ColumnDef::new(Groups::Order).integer().default(-1)) + .to_owned(), + ) + .await + } + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(Groups::Table).to_owned()) + .await + } +} + +#[derive(Iden)] +pub enum Groups { + Table, + Id, + Name, + Description, + Order, +} diff --git a/src/migrator/mod.rs b/src/migrator/mod.rs index d21f032..993e70f 100644 --- a/src/migrator/mod.rs +++ b/src/migrator/mod.rs @@ -1,5 +1,6 @@ mod m20230606_000001_create_tracks_table; mod m20230606_000002_create_ticks_table; +mod m20230606_000003_create_groups_table; use sea_orm_migration::prelude::*;