Database MigratorDatabase Migrator
The Database Migrator project is a Bash-based tool designed to facilitate seamless database schema changes and security mechanisms. It utilizes Flyway, a database migration tool, in conjunction with Bash scripting and Docker. By leveraging the power of Docker, the migrator can be easily deployed and executed within a Kubernetes environment, enabling continuous database updates across various environments. This project streamlines the process of managing and applying database schema changes, ensuring data consistency and maintaining security measures. It provides a reliable and efficient solution for maintaining up-to-date databases in a scalable and automated manner.The Database Migrator project is a Bash-based tool designed to facilitate seamless database schema changes and security mechanisms. It utilizes Flyway, a database migration tool, in conjunction with Bash scripting and Docker. By leveraging the power of Docker, the migrator can be easily deployed and executed within a Kubernetes environment, enabling continuous database updates across various environments. This project streamlines the process of managing and applying database schema changes, ensuring data consistency and maintaining security measures. It provides a reliable and efficient solution for maintaining up-to-date databases in a scalable and automated manner.
This repository contains the Flyway migrations used to define Asasy databases.
The migrations are organised into folders according to the database they belong to.
Note: There is a special
init-dbfolder which contains migrations that are used on every new database.
Each database folder contains a flyway.conf configuration file to configure the mgirations.
The are some general guidelines that are followed in the design of the databases & migrations:
- Permission to create tables is restricted to the DB migrator service account.
- The default
PUBLICrole is restricted. - Table-level
SELECT,INSERT,UPDATE, andDELETEpermissions are granted to non-login roles.
| Role | Type | Connect to database | Create tables | Member of |
|---|---|---|---|---|
| postgres | user (Postgres) | Yes, all | Yes | {superuser} |
| db-migrator | user | Yes, all | Yes | {} |
| loki_user | role | No | No | {} |
| loki_service | user | Yes, {loki} |
No | {loki_user} |
In order to run the migrations, you must supply the necessary credentials to connect to the database.
- Make sure your database is running:
sudo service postgresql start- Navigate to the directory of the database migrations you would like to run:
cd ./loki- Run the migration script (supplying a
.envfile if necessary):
./migrate.shUse docker-compose to bring up the migrator and a test db:
docker-compose up -f docker-compose.dev.ymlWe use SQLFluff linter to lint and fix our database migrations. The lint.sh script will traverse all folders except init-db and will apply lint rules/fixes on any .sql files. To run locally:
$ pip install -r lint-requirements.txt
# install sqlfluff
$ CONCURRENCY=2 bash lint.sh
# will use 2 threads to lint files
$ CONCURRENCY=4 bash lint.sh -f
# will use 4 threads to fix errorsThe default dialect used is postgres.