Mysql & SQLite Migration

Finch provides a simple way to manage your database migrations. You can use the migrate (for mysql) or migrate_sqlite (for sqlite) command to manage your database migrations. This command provides the following options:

  • --init or -i: Initializes the migration table and executes all pending migrations.
  • --create or -c: Creates a new migration file template.
  • --name or -n: Name of migration file while creating.
  • --rollback or -r: Rolls back the most recent migrations.
  • --list or -l: Lists all migration files and their status.

This commands are available after you run the app (or while running the app in console mode). you can use the migrate command in your app.dart file. for example:

dart run example/lib/app.dart migrate --init

Add new migration file

You can add a new migration file by using the --create or -c option. for example:

Finch> migrate --create --name "add_users_table"

Migration file template

Migration file template is a simple sql file that contains two sections:

-- [DATE & TIME]
-- [MySQL | SQLite] Migration File 
-- Name: [NAME OF MIGRATION] 
-- ## NEW VERSION:

   [HERE GOES THE NEW VERSION SQL CODE]

-- ## ROLL BACK:
  
   [HERE GOES THE ROLLBACK SQL CODE]