Skip to content

inovait/girigiri

Repository files navigation

girigiri

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.

Prerequisites

Before you begin, ensure you have the following installed on your machine:

  • Node.js (v18.x or higher is recommended)
  • npm or Yarn

Configuration

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 

Installation

Follow these steps to get the project up and running locally:

Clone the repository;

git clone https://github.com/inovait/girigiri.git
cd girigiri

Install dependencies:

npm install
or
yarn install

Usage

Run the sql schema dump with the following command:

    npm run dump:schema

Run with the following command to create the database migration history table:

    npm run docker:init-mig-database

Run 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:reset

Starts the mysql service in a container. If container already exists, does nothing. Defined by DB_MIGRATION parameters

    npm run docker:start

Testing

To use tests run:

    npm run tests

You 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/migrations

Additional info

To check which migrations were successful, please query your database with;

    Select * from migrations

To generate a dump of a temp migrated database run;

    npm run check:migrations

To generate a diff the migrations would create in a log file run;

    npm run check:migrations:diff

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors