Skip to content

Commit

Permalink
fix: default docker uri
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed Jul 27, 2024
1 parent 98f9fa4 commit fe575dd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion example/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ container:
provider: "docker" # The container provider, can be "docker" or "k8s".
entry: "127.0.0.1" # The public entry of containers.
docker:
uri: "unix://var/run/docker.sock" # DO NOT EDIT if you are using docker-compose.
uri: "unix:///var/run/docker.sock" # DO NOT EDIT if you are using docker-compose.
k8s:
namespace: "cloudsdale" # The namespace of k8s cluster.
path: "./k8s-config.yml" # The k8s config file's path, such as "./k8s-config.yml".
Expand All @@ -73,6 +73,7 @@ db:
password: "cloudsdale"
port: 5432
sslmode: "disable"
schema: "public"
mysql:
dbname: "cloudsdale"
host: "db"
Expand Down
1 change: 1 addition & 0 deletions src/config/db/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Config {
pub dbname: String,
pub schema: String,
pub host: String,
pub port: u16,
pub username: String,
Expand Down
31 changes: 21 additions & 10 deletions src/database/migration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use sea_orm::{ConnectionTrait, DbConn, EntityTrait, Schema};
use tracing::error;

macro_rules! create_tables {
($db:expr, $($entity:expr),*) => {
$(
create_table($db, $entity).await;
)*
};
}

async fn create_table<E>(db: &DbConn, entity: E)
where
E: EntityTrait,
Expand All @@ -16,14 +24,17 @@ where
}

pub async fn migrate(db: &DbConn) {
create_table(db, crate::model::user::Entity).await;
create_table(db, crate::model::team::Entity).await;
create_table(db, crate::model::user_team::Entity).await;
create_table(db, crate::model::category::Entity).await;
create_table(db, crate::model::challenge::Entity).await;
create_table(db, crate::model::submission::Entity).await;
create_table(db, crate::model::game::Entity).await;
create_table(db, crate::model::pod::Entity).await;
create_table(db, crate::model::game_challenge::Entity).await;
create_table(db, crate::model::game_team::Entity).await;
create_tables!(
db,
crate::model::user::Entity,
crate::model::team::Entity,
crate::model::user_team::Entity,
crate::model::category::Entity,
crate::model::challenge::Entity,
crate::model::submission::Entity,
crate::model::game::Entity,
crate::model::pod::Entity,
crate::model::game_challenge::Entity,
crate::model::game_team::Entity
);
}
3 changes: 2 additions & 1 deletion src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ pub async fn init() {
crate::config::get_app_config().db.mysql.dbname,
),
"postgres" => format!(
"postgres://{}:{}@{}:{}/{}",
"postgres://{}:{}@{}:{}/{}?currentSchema={}",
crate::config::get_app_config().db.postgres.username,
crate::config::get_app_config().db.postgres.password,
crate::config::get_app_config().db.postgres.host,
crate::config::get_app_config().db.postgres.port,
crate::config::get_app_config().db.postgres.dbname,
crate::config::get_app_config().db.postgres.schema,
),
_ => {
error!("Unsupported database provider");
Expand Down

0 comments on commit fe575dd

Please sign in to comment.