refactor(migrations): add commands to make file to run migrations for api v2 (#5169)

Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
Narayan Bhat
2024-07-03 15:35:14 +05:30
committed by GitHub
parent f3fb59ce74
commit ff23e2f7d3
9 changed files with 55 additions and 25 deletions

View File

@ -57,10 +57,10 @@ jobs:
shell: bash
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
run: diesel migration run --locked-schema
run: make migrate locked-schema=yes
- name: Verify `diesel migration redo`
shell: bash
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
run: diesel migration redo -a --locked-schema
run: make redo_migrate locked-schema=yes

View File

@ -107,7 +107,7 @@ jobs:
shell: bash
env:
DATABASE_URL: postgres://db_user:db_pass@localhost:5432/hyperswitch_db
run: diesel migration run
run: make migrate locked-schema=yes
- name: Install newman from fork
run: npm ci

View File

@ -252,7 +252,7 @@ fi
# run migrations
print_info "Running migrations"
MIGRATION_CMD="diesel migration --database-url postgres://${DB_USER}:${DB_PASS}@localhost:5432/${DB_NAME} run"
MIGRATION_CMD="make migrate database-url=postgres://${DB_USER}:${DB_PASS}@localhost:5432/${DB_NAME}"
if [[ -d "migrations" ]]; then
$MIGRATION_CMD

View File

@ -113,3 +113,37 @@ precommit : fmt clippy test
hack:
cargo hack check --workspace --each-feature --all-targets
# Run database migrations using `diesel_cli`.
# Assumes `diesel_cli` is already installed.
#
# Usage :
# make migrate [database-url=<PSQL connection string>] [locked-schema=<yes|no>]
# This proceeds as follows:
# Creates a temporary migrations directory, cleans it up if it already exists
# Copies all migrations to the temporary migrations directory and runs migrations
# Cleans up migrations, removing tmp directory if empty, ignoring otherwise
migrate:
mkdir -p $(ROOT_DIR)/tmp/migrations
find $(ROOT_DIR)/tmp/migrations/ -mindepth 1 -delete
cp -r $(ROOT_DIR)/migrations/. $(ROOT_DIR)/v2_migrations/. $(ROOT_DIR)/tmp/migrations/
diesel migration run --migration-dir=$(ROOT_DIR)/tmp/migrations \
$(if $(strip $(database-url)),--database-url="$(database-url)",) \
$(if $(strip $(call eq,$(locked-schema),yes)),--locked-schema,)
rm -r $(ROOT_DIR)/tmp/migrations
rmdir $(ROOT_DIR)/tmp 2>/dev/null || true
redo_migrate:
mkdir -p $(ROOT_DIR)/tmp/migrations
find $(ROOT_DIR)/tmp/migrations/ -mindepth 1 -delete
cp -r $(ROOT_DIR)/migrations/. $(ROOT_DIR)/v2_migrations/. $(ROOT_DIR)/tmp/migrations/
diesel migration redo --all --migration-dir=$(ROOT_DIR)/tmp/migrations \
$(if $(strip $(database-url)),--database-url="$(database-url)",) \
$(if $(strip $(call eq,$(locked-schema),yes)),--locked-schema,)
rm -r $(ROOT_DIR)/tmp/migrations
rmdir $(ROOT_DIR)/tmp 2>/dev/null || true

View File

@ -47,18 +47,15 @@ services:
migration_runner:
image: rust:latest
command: "bash -c 'cargo install diesel_cli --no-default-features --features postgres && diesel migration --database-url postgres://$${DATABASE_USER}:$${DATABASE_PASSWORD}@$${DATABASE_HOST}:$${DATABASE_PORT}/$${DATABASE_NAME} run'"
command: "bash -c 'cargo install diesel_cli --no-default-features --features postgres && make migrate'"
working_dir: /app
networks:
- router_net
volumes:
- ./:/app
environment:
- DATABASE_USER=db_user
- DATABASE_PASSWORD=db_pass
- DATABASE_HOST=pg
- DATABASE_PORT=5432
- DATABASE_NAME=hyperswitch_db
# format -> postgresql://DB_USER:DB_PASSWORD@HOST:PORT/DATABASE_NAME
- DATABASE_URL=postgresql://db_user:db_pass@pg:5432/hyperswitch_db
### Application services
hyperswitch-server:
@ -321,7 +318,7 @@ services:
ports:
- "9000:9000"
environment:
apiBaseUrl: http://localhost:8080
apiBaseUrl: http://localhost:8080
sdkBaseUrl: http://localhost:9050/HyperLoader.js
hyperswitch-web-sdk:

View File

@ -42,18 +42,15 @@ services:
migration_runner:
image: rust:latest
command: "bash -c 'cargo install diesel_cli --no-default-features --features postgres && diesel migration --database-url postgres://$${DATABASE_USER}:$${DATABASE_PASSWORD}@$${DATABASE_HOST}:$${DATABASE_PORT}/$${DATABASE_NAME} run'"
command: "bash -c 'cargo install diesel_cli --no-default-features --features postgres && make migrate'"
working_dir: /app
networks:
- router_net
volumes:
- ./:/app
environment:
- DATABASE_USER=db_user
- DATABASE_PASSWORD=db_pass
- DATABASE_HOST=pg
- DATABASE_PORT=5432
- DATABASE_NAME=hyperswitch_db
# format -> postgresql://DB_USER:DB_PASSWORD@HOST:PORT/DATABASE_NAME
- DATABASE_URL=postgresql://db_user:db_pass@pg:5432/hyperswitch_db
### Application services
hyperswitch-server:

View File

@ -71,6 +71,7 @@ Check the Table Of Contents to jump to the relevant section.
### Running additional services
The default behaviour for docker compose only runs the following services:
1. postgres
2. redis (standalone)
3. hyperswitch server
@ -102,10 +103,11 @@ involved, check out the [architecture document][architecture].
- To run the data services (Clickhouse, Kafka and Opensearch) you can specify the `olap` profile
```shell
docker compose --profile olap up -d
```
You can read more about using the data services [here][data-docs]
```shell
docker compose --profile olap up -d
```
You can read more about using the data services [here][data-docs]
- You can also specify multiple profile names by specifying the `--profile` flag
multiple times.
@ -226,10 +228,10 @@ for your distribution and follow along.
cargo install diesel_cli --no-default-features --features postgres
```
5. Make sure your system has the `pkg-config` package and OpenSSL installed:
5. Make sure your system has the `pkg-config` package, OpenSSL and make installed:
```shell
sudo apt install pkg-config libssl-dev
sudo apt install pkg-config libssl-dev make
```
Once you're done with setting up the dependencies, proceed with
@ -476,10 +478,10 @@ Once you're done with setting up the dependencies, proceed with
cd hyperswitch
```
3. Run database migrations using `diesel_cli`:
3. Run database migrations:
```shell
diesel migration --database-url postgres://$DB_USER:$DB_PASS@localhost:5432/$DB_NAME run
make migrate database-url=postgres://$DB_USER:$DB_PASS@localhost:5432/$DB_NAME
```
Once you're done with setting up the database, proceed with