A simple applicaton that triggers migrations based on the defined sql files. If a query fails, it safely rollsback the last changes. The successful migrations are inserted into a migrations table.
Before you begin, ensure you have the following installed on your machine:
- Node.js (v18.x or higher is recommended)
- npm or Yarn
Create a .env file: Copy the .env.example file and rename it to local.env. Fill in your environment-specific variables. (for local development)
[DB_VALUES]
DB_HOST=dbHost
DB_PORT=dbPort
DB_USER=dbUser
DB_PASSWORD=dbPassword
DB_NAME=dbName
DB_MIGRATION_HOST=dbMigHost
DB_MIGRATION_PORT=dbMigPort
DB_MIGRATION_USER=dbMigUser
DB_MIGRATION_PASSWORD=dbMigPassword
DB_MIGRATION_NAME=dbMigName
[SQL_DUMP]
NO_COMMENTS=false # with or without comments
NO_TRAIL=false # with or without table options
SCHEMA_OUTPUT_DIR=dir # output directory for schema dump Follow these steps to get the project up and running locally:
Clone the repository;
git clone https://github.com/inovait/girigiri.git
cd girigiriInstall dependencies:
npm install
or
yarn installRun the sql schema dump with the following command:
npm run dump:schemaRun with the following command to create the database migration history table:
npm run docker:init-mig-databaseRun the migration with the following command:
npm run migrate or npm run dev ( for local instance - setup the .local.env accordingly)Note: database parameters defined inside env variables.
To run using docker, use the following command; CAUTION: this resets the containers, do not use in production
npm run docker:resetStarts the mysql service in a container. If container already exists, does nothing. Defined by DB_MIGRATION parameters
npm run docker:startTo use tests run:
npm run testsYou will need to setup a .env.integration file and have a working database instance: The lower part is needed for the tests to grab the appropriate files
SCHEMA_OUTPUT_DIR=src/tests/integration/fixtures
MIGRATIONS_DIR=src/tests/integration/fixtures/migrationsTo check which migrations were successful, please query your database with;
Select * from migrationsTo generate a dump of a temp migrated database run;
npm run check:migrationsTo generate a diff the migrations would create in a log file run;
npm run check:migrations:diff