Add tick table migration

This commit is contained in:
D. Scott Boggs 2023-06-06 11:52:42 -04:00
parent f326c45a41
commit 3c4bac5256
2 changed files with 64 additions and 0 deletions

View file

@ -0,0 +1,63 @@
use super::m20230606_000001_create_tracks_table::Tracks;
use sea_orm_migration::{async_trait::async_trait, prelude::*};
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20230606_000002_create_ticks_table"
}
}
#[async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(Ticks::Table)
.col(
ColumnDef::new(Ticks::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Ticks::TrackId).integer())
.col(ColumnDef::new(Ticks::Year).integer())
.col(ColumnDef::new(Ticks::Month).integer())
.col(ColumnDef::new(Ticks::Day).integer())
.col(ColumnDef::new(Ticks::Hour).integer())
.col(ColumnDef::new(Ticks::Minute).integer())
.col(ColumnDef::new(Ticks::Second).integer())
.col(ColumnDef::new(Ticks::HasTimeInfo).integer().default(0))
.foreign_key(
ForeignKey::create()
.name("fk-ticks-track_id")
.from(Ticks::Table, Ticks::TrackId)
.to(Tracks::Table, Tracks::Id),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Ticks::Table).to_owned())
.await
}
}
#[derive(Iden)]
pub enum Ticks {
Table,
Id,
TrackId,
Year,
Month,
Day,
Hour,
Minute,
Second,
HasTimeInfo,
}

View file

@ -1,4 +1,5 @@
mod m20230606_000001_create_tracks_table;
mod m20230606_000002_create_ticks_table;
use sea_orm_migration::prelude::*;