refactor: moved migrations to own crate

This commit is contained in:
Jef Roosens 2024-07-15 21:48:26 +02:00
parent 777d57512e
commit 4225ce3471
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
13 changed files with 799 additions and 15 deletions

View file

@ -15,7 +15,6 @@ futures = "0.3.28"
http-body-util = "0.1.1"
libarchive = { path = "../libarchive" }
regex = "1.10.5"
sea-orm-migration = "0.12.1"
sea-query = { version = "0.30.7", features = ["backend-postgres", "backend-sqlite"] }
serde = { version = "1.0.178", features = ["derive"] }
sha256 = "1.1.4"
@ -26,6 +25,7 @@ tower-http = { version = "0.5.2", features = ["fs", "trace", "auth"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
uuid = { version = "1.4.0", features = ["v4"] }
migration = { path = "../migration" }
[dependencies.sea-orm]
version = "0.12.1"

View file

@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(unique)]
pub name: String,
pub description: Option<String>,
}

View file

@ -1,6 +1,5 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
use chrono::NaiveDateTime;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
@ -20,13 +19,12 @@ pub struct Model {
pub c_size: i64,
pub description: Option<String>,
pub url: Option<String>,
pub build_date: NaiveDateTime,
pub build_date: DateTime,
pub packager: Option<String>,
pub pgp_sig: Option<String>,
pub pgp_sig_size: Option<i64>,
pub sha256_sum: String,
pub compression: String,
#[serde(skip_serializing)]
pub state: PackageState,
}

View file

@ -9,6 +9,7 @@ pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub distro_id: i32,
#[sea_orm(unique)]
pub name: String,
pub description: Option<String>,
}

View file

@ -1,11 +1,9 @@
pub mod entities;
mod migrator;
pub mod query;
use crate::config::DbConfig;
pub use entities::{prelude::*, *};
pub use migrator::Migrator;
use sea_orm::{ConnectionTrait, Database, DbConn, DeriveActiveEnum, EnumIter};
use serde::{Deserialize, Serialize};

View file

@ -12,7 +12,7 @@ pub use error::{Result, ServerError};
use std::{io, path::PathBuf};
use clap::Parser;
use sea_orm_migration::MigratorTrait;
use migration::MigratorTrait;
use tokio::runtime;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
@ -52,7 +52,7 @@ fn setup(rt: &runtime::Handle, config_file: PathBuf) -> crate::Result<Global> {
tracing::info!("Connecting to database");
let db = rt.block_on(crate::db::connect(&config.db))?;
rt.block_on(crate::db::Migrator::up(&db, None))?;
rt.block_on(migration::Migrator::up(&db, None))?;
let repo = match &config.fs {
FsConfig::Local { data_dir } => {