Header menu logo Migrondi

Migrondi takes the directory where it was invoked as the root of the project, it will also try to read a full migrondi.json file right there. If the file is not found or it is not valid it will default to the following configuration:

{
  "connection": "Data Source=./migrondi.db",
  "migrations": "./migrations",
  "tableName": "__migrondi_migrations",
  "driver": "sqlite"
}

*NOTE*: Partial configuration is not supported yet, you either provide a full configuration file or use the environment variables to override the default configuration.

Getting started

migrondi offers the init command

$ migrondi init
[21:59:24 INF] Initializing a new migrondi project at: C:
[21:59:24 INF] migrondi.json and migrations directory created successfully.

This will create the migrondi.json file and the migrations directory for you.

The next logical step would be to create a migration file, you can do that with the new command

$ migrondi new create-users-table
[22:00:58 INF] Creating a new migration with name: create-users-table.
[22:00:58 INF] Migration create-users-table_1695873658869.sql created successfully.

All of the migrondi migrations have the following naming convention:

The name is the one you specify as the argument for the new command and should not be changed once it has been applied to the database.

The timestamp is a unix miliseconds timestamp that is used to order the migrations.

The latest date is always at the top while the oldest is at the bottom.

This should have created a new file in the migrations directory with the following content:

-- MIGRONDI:NAME=create-users-table_1695873658869.sql
-- MIGRONDI:TIMESTAMP=1695873658869
-- ---------- MIGRONDI:UP ----------
-- Add your SQL migration code below. You can delete this line but do not delete the comments above.


-- ---------- MIGRONDI:DOWN ----------
-- Add your SQL rollback code below. You can delete this line but do not delete the comment above.

The first 2 lines are used by migrondi to keep track of the migration file, please do not delete them. The markers MIGRONDI:UP and MIGRONDI:DOWN are used to separate the migration code from the rollback code, and you should not delete those as well. With those elements present in the migration file in that order you can start writing some SQL code to create your table.

Example:

-- MIGRONDI:NAME=create-users-table_1695873658869.sql
-- MIGRONDI:TIMESTAMP=1695873658869
-- ---------- MIGRONDI:UP ----------
create table users (
    id integer primary key,
    name text not null,
    email text not null,
    password text not null,
    created_at datetime not null,
    updated_at datetime not null
);

-- ---------- MIGRONDI:DOWN ----------
drop table users;

Before we apply this to our database let's check what's the status of our current migrations

$ migrondi list
                                 All Migrations
┌─────────┬──────────────────────────────────┬──────────────────────────────────┐
│ Status  │ Name                             │ Date Created                     │
├─────────┼──────────────────────────────────┼──────────────────────────────────┤
│ Pending │ create-users-table_1695873658869 │ 27/09/2023 10:00:58 p. m. -06:00 │
└─────────┴──────────────────────────────────┴──────────────────────────────────┘

Note that this should render fine in your console

Great! now that we have a migration file we can apply it to the database with the up command

$ migrondi up
[22:10:01 INF] Running '1' migrations.
[22:10:01 INF] Applied migration 'create-users-table_1695873658869' successfully.

This will run all the migrations that have not been applied to the database yet.

$ migrondi list
                                 All Migrations
┌─────────┬──────────────────────────────────┬──────────────────────────────────┐
│ Status  │ Name                             │ Date Created                     │
├─────────┼──────────────────────────────────┼──────────────────────────────────┤
│ Applied │ create-users-table_1695873658869 │ 27/09/2023 10:00:58 p. m. -06:00 │
└─────────┴──────────────────────────────────┴──────────────────────────────────┘

To revert the last migration you can use the down command

$ migrondi down
[22:11:01 INF] Running '1' migrations.
[22:11:01 INF] Reverted migration 'create-users-table_1695873658869' successfully.

This will revert all of the migrations from the last applied to the first one into the database.

If we ran our list command again we would see that the migration has been reverted.

That's the General Gist of how to use migrondi.

Command Reference

Type something to start searching.