migrable 0.0.2 migrable: ^0.0.2 copied to clipboard
An interface to easy database migration for Flutter. The method is based on Laravel's way of doing this.
migrable #
An interface to easy database migration for Flutter. The method is based on Laravel's way of doing this.
This has builded to work with sqflite only. If you are not acquainted with the workig mode you must read about sqflite and read abouy sqflite migrations too.
We disapprove the idea of writing all migration scripts on the application entrypoint (like is suggested by the sqflite documentation). This is a not responsible and hard to maintain code.
So, we write a solution to separate all scripts into single files. Now, application entrypoint just maps the migration files and call the scripts execution.
We suggest the usage of enge for easy migrations create. You can find more information and instructions in the documentation section.
Usage #
Setting up connection #
To know how to execute your migration scripts you must offer to us your SQLite database path by the DATABASE_PATH
propertie on your .env
. If you are not using .env
you must to include that in your application, see more about that here.
Creating migrations #
Using enge
If you are using enge all you need is run this command:
> enge make:migration {MIGRATION_NAME}
You can read more about this in the enge documentation section.
Without enge
If you are not using enge you must create a Dart class in a reserved to migrations folder (like database/migrations
) and make it looks like that:
import 'package:migrable/migration.dart';
import 'package:sqflite/sqflite.dart';
class YourMigrationName implements Migration {
@override
void up(Batch batch) {
batch.execute('YOUR MIGRATION SCRIPT');
}
}
Migrating #
To call the execution of your migrations scripts include a section like that:
import 'package:migrable/migrable.dart';
import 'package:migrable/migration.dart';
List<Migration> migrations = [
// Instances of your migration classes.
];
Migrable.execute(migrations);