From 3c4bac52564e3348ecade6c55dce9f8685af8c8d Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Tue, 6 Jun 2023 11:52:42 -0400 Subject: [PATCH] Add tick table migration --- .../m20230606_000002_create_ticks_table.rs | 63 +++++++++++++++++++ src/migrator/mod.rs | 1 + 2 files changed, 64 insertions(+) create mode 100644 src/migrator/m20230606_000002_create_ticks_table.rs diff --git a/src/migrator/m20230606_000002_create_ticks_table.rs b/src/migrator/m20230606_000002_create_ticks_table.rs new file mode 100644 index 0000000..0eb7adc --- /dev/null +++ b/src/migrator/m20230606_000002_create_ticks_table.rs @@ -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, +} diff --git a/src/migrator/mod.rs b/src/migrator/mod.rs index 8211763..d21f032 100644 --- a/src/migrator/mod.rs +++ b/src/migrator/mod.rs @@ -1,4 +1,5 @@ mod m20230606_000001_create_tracks_table; +mod m20230606_000002_create_ticks_table; use sea_orm_migration::prelude::*;