call seaorm migrations after typeorm

This commit is contained in:
Namekuji 2023-06-03 00:27:00 -04:00
parent afe4c76392
commit d7f80edbea
No known key found for this signature in database
GPG key ID: B541BD6E646CABC7
4 changed files with 42 additions and 4 deletions

View file

@ -19,6 +19,8 @@ native-utils = { path = "../", optional = true }
indicatif = { version = "0.17.4", features = ["tokio"] } indicatif = { version = "0.17.4", features = ["tokio"] }
tokio = { version = "1.28.2", features = ["full"] } tokio = { version = "1.28.2", features = ["full"] }
futures = "0.3.28" futures = "0.3.28"
serde_yaml = "0.9.21"
serde = { version = "1.0.163", features = ["derive"] }
[dependencies.sea-orm-migration] [dependencies.sea-orm-migration]
version = "0.11.0" version = "0.11.0"

View file

@ -1,11 +1,45 @@
use serde::Deserialize;
use std::env;
use std::fs;
use sea_orm_migration::prelude::*; use sea_orm_migration::prelude::*;
#[cfg(feature = "convert")]
mod vec_to_json; mod vec_to_json;
#[async_std::main] #[async_std::main]
async fn main() { async fn main() {
let cwd = env::current_dir().unwrap();
let yml = fs::File::open(cwd.join("../../.config/default.yml"))
.expect("Unable to read '.config/default.yml'");
let config: Config = serde_yaml::from_reader(yml).expect("Unable to parse");
env::set_var(
"DATABASE_URL",
format!(
"postgres://{}:{}@{}:{}/{}",
config.db.user, config.db.pass, config.db.host, config.db.port, config.db.db
),
);
cli::run_cli(migration::Migrator).await; cli::run_cli(migration::Migrator).await;
#[cfg(feature = "convert")] #[cfg(feature = "convert")]
vec_to_json::convert().await; vec_to_json::convert().await;
} }
#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename = "camelCase")]
pub struct Config {
pub db: DbConfig,
}
#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename = "camelCase")]
pub struct DbConfig {
pub host: String,
pub port: u32,
pub db: String,
pub user: String,
pub pass: String,
}

View file

@ -1,5 +1,3 @@
#![cfg(feature = "convert")]
use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use native_utils::model::entity::newtype::{I32Vec, StringVec}; use native_utils::model::entity::newtype::{I32Vec, StringVec};
use sea_orm_migration::{ use sea_orm_migration::{

View file

@ -6,8 +6,12 @@
"scripts": { "scripts": {
"start": "pnpm node ./built/index.js", "start": "pnpm node ./built/index.js",
"start:test": "NODE_ENV=test pnpm node ./built/index.js", "start:test": "NODE_ENV=test pnpm node ./built/index.js",
"migrate": "typeorm migration:run -d ormconfig.js", "migrate": "pnpm run migrate:typeorm && pnpm run migrate:cargo",
"revertmigration": "typeorm migration:revert -d ormconfig.js", "migrate:typeorm": "typeorm migration:run -d ormconfig.js",
"migrate:cargo": "cargo run --manifest-path native-utils/migration/Cargo.toml -- up",
"revertmigration": "pnpm run revertmigration:cargo && pnpm run revertmigration:typeorm",
"revertmigration:typeorm": "typeorm migration:revert -d ormconfig.js",
"revertmigration:cargo": "cargo run --manifest-path native-utils/migration/Cargo.toml -- down",
"check:connect": "node ./check_connect.js", "check:connect": "node ./check_connect.js",
"build": "pnpm swc src -d built -D", "build": "pnpm swc src -d built -D",
"watch": "pnpm swc src -d built -D -w", "watch": "pnpm swc src -d built -D -w",