# Migrations Runner Tool for managing and executing database migrations for the Humand ecosystem. ## Description This tool allows running migrations in the databases used by Humand services. It facilitates the creation, management, and tracking of changes to the database schema in a controlled and versioned manner. ## Features - Automatic execution of migrations - Tracking of migration status - Support for migration rollback - Management of migrations for multiple databases ## Configuration 1. Copy the `.env.example` file to `.env` and configure the necessary variables: ``` DB_HOST=localhost DB_PORT=5432 DB_USER=humand_user DB_PASSWORD=humand_password DB_NAME=humand_dev ``` ## Commands ⚠️ **Warning**: Be careful running migrations locally, because you can contain migrations from another branch in your build. You always should run `pnpm clean` before running migrations. - **Build the project**: `pnpm nx build migrations-runner` - **Run linting**: `pnpm nx lint migrations-runner` - **Create migration**: `pnpm create-migration-on-main my-migration-sample` - **Run migrations**: `pnpm local-migrate-on-main` - **Undo migrations**: `pnpm undo-migrations-on-main` ### Creating a New Migration 1. Create a new migration using the command: `pnpm create-migration-on-main your-migration-name` 2. This will generate a file with the format `{timestamp}-{name}.ts` in the appropriate directory 3. Edit the generated file to implement the `up` and `down` functions that will apply and revert your database changes Example migration structure: ```typescript export const up = async (queryInterface, Sequelize) => { // Your database changes here }; export const down = async (queryInterface) => { // Code to revert your changes }; ```