database persistence in progress

This commit is contained in:
2026-02-05 23:22:00 +01:00
parent a398911527
commit f7e55536ab
17 changed files with 3600 additions and 22 deletions

12
migration/src/lib.rs Normal file
View File

@@ -0,0 +1,12 @@
pub use sea_orm_migration::prelude::*;
mod m20220101_000001_create_table;
pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(m20220101_000001_create_table::Migration)]
}
}

View File

@@ -0,0 +1,36 @@
use sea_orm_migration::{prelude::*, schema::*};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
manager.create_table(
Table::create()
.table(Alarm::Table)
.if_not_exists()
.col(pk_auto(Alarm::Id))
.col(date_time(Alarm::Time))
.col(boolean(Alarm::Enabled))
.col(string(Alarm::Title))
.to_owned(),
).await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
manager.drop_table(Table::drop().table(Alarm::Table).to_owned()).await
}
}
#[derive(DeriveIden)]
enum Alarm {
Table,
Id,
Time,
Enabled,
Title
}

6
migration/src/main.rs Normal file
View File

@@ -0,0 +1,6 @@
use sea_orm_migration::prelude::*;
#[tokio::main]
async fn main() {
cli::run_cli(migration::Migrator).await;
}