From f326c45a418db7e2319ec5280ea0da5a496658ea Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Tue, 6 Jun 2023 11:27:37 -0400 Subject: [PATCH] Add migrator module and tracks table creation --- src/main.rs | 1 + .../m20230606_000001_create_tracks_table.rs | 58 +++++++++++++++++++ src/migrator/mod.rs | 12 ++++ 3 files changed, 71 insertions(+) create mode 100644 src/migrator/m20230606_000001_create_tracks_table.rs create mode 100644 src/migrator/mod.rs diff --git a/src/main.rs b/src/main.rs index 75e808e..2391e85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![feature(default_free_fn)] mod db; mod error; +mod migrator; use error::Result; use sea_orm::Database; diff --git a/src/migrator/m20230606_000001_create_tracks_table.rs b/src/migrator/m20230606_000001_create_tracks_table.rs new file mode 100644 index 0000000..a8a35c7 --- /dev/null +++ b/src/migrator/m20230606_000001_create_tracks_table.rs @@ -0,0 +1,58 @@ +use sea_orm_migration::{async_trait::async_trait, prelude::*}; + +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(Tracks::Table) + .col( + ColumnDef::new(Tracks::Id) + .integer() + .not_null() + .auto_increment() + .primary_key(), + ) + .col(ColumnDef::new(Tracks::Name).string().not_null()) + .col(ColumnDef::new(Tracks::Description).string().not_null()) + .col(ColumnDef::new(Tracks::Icon).string().not_null()) + .col(ColumnDef::new(Tracks::Enabled).integer().not_null()) + .col( + ColumnDef::new(Tracks::MultipleEntriesPerDay) + .integer() + .default(0), + ) + .col(ColumnDef::new(Tracks::Color).integer().default(0)) + .col(ColumnDef::new(Tracks::Order).integer().default(-1)) + .to_owned(), + ) + .await + } + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(Tracks::Table).to_owned()) + .await + } +} + +#[derive(Iden)] +pub enum Tracks { + Table, + Id, + Name, + Description, + Icon, + Enabled, + MultipleEntriesPerDay, + Color, + Order, +} diff --git a/src/migrator/mod.rs b/src/migrator/mod.rs new file mode 100644 index 0000000..8211763 --- /dev/null +++ b/src/migrator/mod.rs @@ -0,0 +1,12 @@ +mod m20230606_000001_create_tracks_table; + +use sea_orm_migration::prelude::*; + +pub struct Migrator; + +#[async_trait::async_trait] +impl MigratorTrait for Migrator { + fn migrations() -> Vec> { + vec![] + } +}