Add migrator module and tracks table creation

This commit is contained in:
D. Scott Boggs 2023-06-06 11:27:37 -04:00
parent 75b57539d9
commit f326c45a41
3 changed files with 71 additions and 0 deletions

View file

@ -1,6 +1,7 @@
#![feature(default_free_fn)]
mod db;
mod error;
mod migrator;
use error::Result;
use sea_orm::Database;

View file

@ -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,
}

12
src/migrator/mod.rs Normal file
View file

@ -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<Box<dyn MigrationTrait>> {
vec![]
}
}