Added Furlong Grinder scripts
This commit is contained in:
parent
adbd59c5ee
commit
cdf1fdc9c3
6 changed files with 140 additions and 1 deletions
|
@ -1,2 +1,6 @@
|
|||
# Development-only server configuration.
|
||||
port: 3000
|
||||
port: 3000
|
||||
furlong:
|
||||
database: angel
|
||||
username: root
|
||||
password: password
|
19
lib/migrations/group.dart
Normal file
19
lib/migrations/group.dart
Normal file
|
@ -0,0 +1,19 @@
|
|||
import 'dart:async';
|
||||
import 'package:furlong/furlong.dart';
|
||||
|
||||
class GroupMigration extends Migration {
|
||||
String get name => "Groups table";
|
||||
|
||||
@override
|
||||
Future create(Migrator migrator) async {
|
||||
migrator.create("groups", (table) {
|
||||
table.id();
|
||||
table.varChar("name");
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future destroy(Migrator migrator) async {
|
||||
migrator.drop(["groups"]);
|
||||
}
|
||||
}
|
68
lib/migrations/migrations.dart
Normal file
68
lib/migrations/migrations.dart
Normal file
|
@ -0,0 +1,68 @@
|
|||
library angel.migrations;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:angel_configuration/angel_configuration.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:furlong/furlong.dart';
|
||||
import 'package:sqljocky/sqljocky.dart';
|
||||
export 'group.dart';
|
||||
export 'todo.dart';
|
||||
|
||||
Future<ConnectionPool> createPool() async {
|
||||
var app = new Angel();
|
||||
await app.configure(loadConfigurationFile());
|
||||
Map config = app.properties["furlong"];
|
||||
|
||||
if (config == null)
|
||||
throw new Exception(
|
||||
"Please provide Furlong configuration with your configuration file.");
|
||||
|
||||
String type = config["type"] ?? "mysql";
|
||||
|
||||
if (type == "mysql") {
|
||||
return new ConnectionPool(
|
||||
host: config["host"] ?? "localhost",
|
||||
port: config["port"] ?? 3306,
|
||||
user: config["username"],
|
||||
password: config["password"],
|
||||
db: config["database"],
|
||||
useSSL: config["ssl"] == true);
|
||||
} else
|
||||
throw new Exception("Unsupported database driver '$type'.");
|
||||
}
|
||||
|
||||
migrateDown(List<Migration> migrations) async {
|
||||
print("Undoing all migrations...");
|
||||
var pool = await createPool();
|
||||
var furlong = new Furlong(pool, migrations: migrations);
|
||||
await furlong.down();
|
||||
print("Done.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
migrateReset(List<Migration> migrations) async {
|
||||
var pool = await createPool();
|
||||
var furlong = new Furlong(pool, migrations: migrations);
|
||||
await furlong.reset();
|
||||
print("Done.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
migrateRevert(List<Migration> migrations) async {
|
||||
print("Reverting last batch...");
|
||||
var pool = await createPool();
|
||||
var furlong = new Furlong(pool, migrations: migrations);
|
||||
await furlong.revert();
|
||||
print("Done.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
migrateUp(List<Migration> migrations) async {
|
||||
print("Running all outstanding migrations...");
|
||||
var pool = await createPool();
|
||||
var furlong = new Furlong(pool, migrations: migrations);
|
||||
await furlong.up();
|
||||
print("Done.");
|
||||
exit(0);
|
||||
}
|
21
lib/migrations/todo.dart
Normal file
21
lib/migrations/todo.dart
Normal file
|
@ -0,0 +1,21 @@
|
|||
import 'dart:async';
|
||||
import 'package:furlong/furlong.dart';
|
||||
|
||||
class TodoMigration extends Migration {
|
||||
String get name => "Todos table";
|
||||
|
||||
@override
|
||||
Future create(Migrator migrator) async {
|
||||
migrator.create("todos", (table) {
|
||||
table.id();
|
||||
table.varChar("group_id").nullable = true;
|
||||
table.varChar("title").nullable = true;
|
||||
table.varChar("text");
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future destroy(Migrator migrator) async {
|
||||
migrator.drop(["todos"]);
|
||||
}
|
||||
}
|
|
@ -11,6 +11,8 @@ dependencies:
|
|||
angel_mongo: ^1.0.0-dev
|
||||
angel_mustache: ^1.0.0-dev
|
||||
angel_static: ^1.0.0
|
||||
furlong:
|
||||
path: /Users/tobe/Source/Dart/furlong
|
||||
json_god: ^2.0.0-beta
|
||||
validate: ^1.5.2
|
||||
dev_dependencies:
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:angel/migrations/migrations.dart';
|
||||
import 'package:furlong/furlong.dart';
|
||||
import 'package:grinder/grinder.dart';
|
||||
|
||||
final List<Migration> migrations = [
|
||||
// Your migrations here!
|
||||
new GroupMigration(),
|
||||
new TodoMigration()
|
||||
];
|
||||
|
||||
main(args) => grind(args);
|
||||
|
||||
@Task()
|
||||
|
@ -13,3 +23,18 @@ build() {
|
|||
|
||||
@Task()
|
||||
clean() => defaultClean();
|
||||
|
||||
@Task("Generates classes from your Furlong migrations.")
|
||||
generate() async {}
|
||||
|
||||
@Task("Reverts the database state to before any Furlong migrations were run.")
|
||||
down() => migrateDown(migrations);
|
||||
|
||||
@Task("Undoes and re-runs all Furlong migrations.")
|
||||
reset() => migrateReset(migrations);
|
||||
|
||||
@Task("Undoes the last batch of Furlong migrations run.")
|
||||
revert() => migrateRevert(migrations);
|
||||
|
||||
@Task("Runs any outstanding Furlong migrations.")
|
||||
up() => migrateUp(migrations);
|
||||
|
|
Loading…
Reference in a new issue