diff --git a/.env b/.env index e21e6b3..49d54a8 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ APP_PROFILE=dev RUST_BACKTRACE=1 RUST_LOG=info -DATABASE_URL=postgres://postgres_user:postgres_pass@localhost:5432/postgres_db +DATABASE_URL=postgres://username:password@localhost:5432/database_name diff --git a/README.md b/README.md index 893ddf1..887535b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# RUSTfulapi +# rustfulapi Reusable template for building REST Web Services in Rust. Uses [Axum](https://github.com/tokio-rs/axum) HTTP web framework and [SeaORM](https://github.com/SeaQL/sea-orm) ORM and [PostgreSQL](https://www.postgresql.org/). [![License](https://img.shields.io/github/license/robatipoor/rustfulapi) @@ -83,6 +83,10 @@ export APP_PROFILE=prod # switch to production profile ``` cp ./scripts/git-hooks/* ./.git/hooks/ ``` +### Migrate database +``` +cargo run --bin migration -- up -u $DATABASE_URL +``` ### Update ERD (Entity-Relationship Diagram) use [planter](https://github.com/achiku/planter) ```bash planter postgres://username:password@localhost:5432/database_name\?sslmode=disable -o docs/schema.puml diff --git a/docker/dev/.env b/docker/dev/.env index 466440d..9141baf 100644 --- a/docker/dev/.env +++ b/docker/dev/.env @@ -1,14 +1,14 @@ APP_PROFILE=dev RUST_BACKTRACE=1 RUST_LOG=info -DATABASE_URL=postgres://postgres_user:postgres_pass@localhost:5432/postgres_db +DATABASE_URL=postgres://username:password@localhost:5432/database_name APP_SERVER__PORT=8080 APP_SERVER__ADDR=0.0.0.0 -APP_DB__USERNAME=postgres_user -APP_DB__PASSWORD=postgres_pass +APP_DB__USERNAME=username +APP_DB__PASSWORD=password APP_DB__PORT=5432 APP_DB__HOST=postgres-db -APP_DB__DATABASE_NAME=postgres_db +APP_DB__DATABASE_NAME=database_name APP_REDIS__USERNAME=redis_user APP_REDIS__PASSWORD= APP_REDIS__PORT=6379 diff --git a/docker/prod/.env b/docker/prod/.env index abe0c8f..a57adb4 100644 --- a/docker/prod/.env +++ b/docker/prod/.env @@ -1,14 +1,14 @@ APP_PROFILE=prod RUST_BACKTRACE=1 RUST_LOG=info -DATABASE_URL=postgres://postgres_user:postgres_pass@localhost:5432/postgres_db +DATABASE_URL=postgres://username:password@localhost:5432/database_name APP_SERVER__PORT=8080 APP_SERVER__ADDR=0.0.0.0 -APP_DB__USERNAME=postgres_user -APP_DB__PASSWORD=postgres_pass +APP_DB__USERNAME=username +APP_DB__PASSWORD=password APP_DB__PORT=5432 APP_DB__HOST=postgres-db -APP_DB__DATABASE_NAME=postgres_db +APP_DB__DATABASE_NAME=database_name APP_REDIS__USERNAME=redis_user APP_REDIS__PASSWORD= APP_REDIS__PORT=6379 diff --git a/docs/schema.png b/docs/schema.png index e9182bc..e29cbdb 100644 Binary files a/docs/schema.png and b/docs/schema.png differ diff --git a/src/client/database.rs b/src/client/database.rs index db0344f..b95f830 100644 --- a/src/client/database.rs +++ b/src/client/database.rs @@ -42,7 +42,7 @@ async fn create_database(db: &DatabaseConnection, database_name: &str) -> AppRes } pub async fn setup_new_database(config: &mut AppConfig) -> AppResult { - info!("Setup new postgres database for the test."); + info!("Setup new database for the test."); let db = DatabaseClient::build_from_config(config).await?; config.db.database_name = util::random::generate_random_string_with_prefix("test_db").to_lowercase(); diff --git a/src/handler/openapi.rs b/src/handler/openapi.rs index ca7e832..8be44af 100644 --- a/src/handler/openapi.rs +++ b/src/handler/openapi.rs @@ -11,7 +11,7 @@ use crate::util::claim::UserClaims; #[openapi( info( version = "v0.1.0", - title = "RUSTful APIs", + title = "RUSTful API", ), paths( // server api