fixed #456 - postgresql migrations

This commit is contained in:
Eugene Pankov 2022-11-04 20:20:27 +01:00
parent 891760f092
commit bfa2d262f3
No known key found for this signature in database
GPG key ID: 5896FCBBDD1CF4F4
7 changed files with 30 additions and 22 deletions

View file

@ -1,25 +1,27 @@
projects := "warpgate warpgate-admin warpgate-common warpgate-db-entities warpgate-db-migrations warpgate-database-protocols warpgate-protocol-ssh warpgate-protocol-mysql warpgate-protocol-http warpgate-core warpgate-sso" projects := "warpgate warpgate-admin warpgate-common warpgate-db-entities warpgate-db-migrations warpgate-database-protocols warpgate-protocol-ssh warpgate-protocol-mysql warpgate-protocol-http warpgate-core warpgate-sso"
features := "sqlite,postgres,mysql"
run *ARGS: run *ARGS:
RUST_BACKTRACE=1 RUST_LOG=warpgate cargo run -- --config config.yaml {{ARGS}} RUST_BACKTRACE=1 RUST_LOG=warpgate cargo run --features {{features}} -- --config config.yaml {{ARGS}}
fmt: fmt:
for p in {{projects}}; do cargo fmt -p $p -v; done for p in {{projects}}; do cargo fmt --features {{features}} -p $p -v; done
fix *ARGS: fix *ARGS:
for p in {{projects}}; do cargo fix -p $p {{ARGS}}; done for p in {{projects}}; do cargo fix --features {{features}} -p $p {{ARGS}}; done
clippy *ARGS: clippy *ARGS:
for p in {{projects}}; do cargo cranky -p $p {{ARGS}}; done for p in {{projects}}; do cargo cranky --features {{features}} -p $p {{ARGS}}; done
test: test:
for p in {{projects}}; do cargo test -p $p; done for p in {{projects}}; do cargo test --features {{features}} -p $p; done
yarn *ARGS: yarn *ARGS:
cd warpgate-web && yarn {{ARGS}} cd warpgate-web && yarn {{ARGS}}
migrate *ARGS: migrate *ARGS:
cargo run -p warpgate-db-migrations -- {{ARGS}} cargo run --features {{features}} -p warpgate-db-migrations -- {{ARGS}}
lint: lint:
cd warpgate-web && yarn run lint cd warpgate-web && yarn run lint
@ -36,4 +38,4 @@ openapi:
cleanup: (fix "--allow-dirty") (clippy "--fix" "--allow-dirty") fmt svelte-check lint cleanup: (fix "--allow-dirty") (clippy "--fix" "--allow-dirty") fmt svelte-check lint
udeps: udeps:
cargo udeps --all-targets cargo udeps --features {{features}} --all-targets

View file

@ -8,7 +8,7 @@ use uuid::Uuid;
#[oai(rename = "TargetRoleAssignment")] #[oai(rename = "TargetRoleAssignment")]
pub struct Model { pub struct Model {
#[sea_orm(primary_key, auto_increment = true)] #[sea_orm(primary_key, auto_increment = true)]
pub id: u32, pub id: i32,
pub target_id: Uuid, pub target_id: Uuid,
pub role_id: Uuid, pub role_id: Uuid,
} }

View file

@ -8,7 +8,7 @@ use uuid::Uuid;
#[oai(rename = "UserRoleAssignment")] #[oai(rename = "UserRoleAssignment")]
pub struct Model { pub struct Model {
#[sea_orm(primary_key, auto_increment = true)] #[sea_orm(primary_key, auto_increment = true)]
pub id: u32, pub id: i32,
pub user_id: Uuid, pub user_id: Uuid,
pub role_id: Uuid, pub role_id: Uuid,
} }

View file

@ -79,7 +79,7 @@ mod target_role_assignment {
#[sea_orm(table_name = "target_roles")] #[sea_orm(table_name = "target_roles")]
pub struct Model { pub struct Model {
#[sea_orm(primary_key, auto_increment = true)] #[sea_orm(primary_key, auto_increment = true)]
pub id: u32, pub id: i32,
pub target_id: Uuid, pub target_id: Uuid,
pub role_id: Uuid, pub role_id: Uuid,
} }

View file

@ -39,7 +39,7 @@ mod user_role_assignment {
#[sea_orm(table_name = "user_roles")] #[sea_orm(table_name = "user_roles")]
pub struct Model { pub struct Model {
#[sea_orm(primary_key, auto_increment = true)] #[sea_orm(primary_key, auto_increment = true)]
pub id: u32, pub id: i32,
pub user_id: Uuid, pub user_id: Uuid,
pub role_id: Uuid, pub role_id: Uuid,
} }

View file

@ -56,7 +56,7 @@ pub(crate) async fn command(cli: &crate::Cli) -> Result<()> {
std::process::exit(1); std::process::exit(1);
} }
if let Commands::Setup = cli.command { if let Commands::Setup { .. } = cli.command {
assert_interactive_terminal(); assert_interactive_terminal();
} }
@ -114,14 +114,16 @@ pub(crate) async fn command(cli: &crate::Cli) -> Result<()> {
create_dir_all(&db_path)?; create_dir_all(&db_path)?;
secure_directory(&db_path)?; secure_directory(&db_path)?;
store.database_url = Secret::new( store.database_url = Secret::new(match &cli.command {
if let Commands::UnattendedSetup { Commands::UnattendedSetup {
database_url: Some(url), database_url: Some(url),
.. ..
} = &cli.command }
{ | Commands::Setup {
url.to_owned() database_url: Some(url),
} else { ..
} => url.to_owned(),
_ => {
let mut db_path = db_path.to_string_lossy().to_string(); let mut db_path = db_path.to_string_lossy().to_string();
if let Some(x) = db_path.strip_suffix("./") { if let Some(x) = db_path.strip_suffix("./") {
@ -129,8 +131,8 @@ pub(crate) async fn command(cli: &crate::Cli) -> Result<()> {
} }
format!("sqlite:{db_path}") format!("sqlite:{db_path}")
}, }
); });
if let Commands::UnattendedSetup { http_port, .. } = &cli.command { if let Commands::UnattendedSetup { http_port, .. } = &cli.command {
store.http.enable = true; store.http.enable = true;

View file

@ -32,7 +32,11 @@ pub struct Cli {
#[derive(clap::Subcommand)] #[derive(clap::Subcommand)]
pub(crate) enum Commands { pub(crate) enum Commands {
/// Run first-time setup and generate a config file /// Run first-time setup and generate a config file
Setup, Setup {
/// Database URL
#[clap(long)]
database_url: Option<String>,
},
/// Run first-time setup non-interactively /// Run first-time setup non-interactively
UnattendedSetup { UnattendedSetup {
/// Database URL /// Database URL
@ -92,7 +96,7 @@ async fn _main() -> Result<()> {
Commands::TestTarget { target_name } => { Commands::TestTarget { target_name } => {
crate::commands::test_target::command(&cli, target_name).await crate::commands::test_target::command(&cli, target_name).await
} }
Commands::Setup | Commands::UnattendedSetup { .. } => { Commands::Setup { .. } | Commands::UnattendedSetup { .. } => {
crate::commands::setup::command(&cli).await crate::commands::setup::command(&cli).await
} }
Commands::ClientKeys => crate::commands::client_keys::command(&cli).await, Commands::ClientKeys => crate::commands::client_keys::command(&cli).await,