mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 03:13:56 +08:00
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:
4
.github/workflows/migration-check.yaml
vendored
4
.github/workflows/migration-check.yaml
vendored
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
34
Makefile
34
Makefile
@ -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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
@ -105,6 +106,7 @@ involved, check out the [architecture document][architecture].
|
||||
```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
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user