From d60462a23a6bb027fd7db3d0bc09a7f4dfa8ff90 Mon Sep 17 00:00:00 2001 From: thosakwe Date: Tue, 20 Sep 2016 01:04:51 -0400 Subject: [PATCH] Going to replace MongoDB with Furlong --- config/default.yaml | 11 ++++++++- config/development.yaml | 6 +---- lib/src/migrations/migrations.dart | 4 ++++ lib/src/migrations/schemas/user.dart | 24 +++++++++++++++++++ .../migrations/util.dart} | 4 +--- pubspec.yaml | 3 +-- tool/grind.dart | 3 ++- 7 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 lib/src/migrations/migrations.dart create mode 100644 lib/src/migrations/schemas/user.dart rename lib/{migrations/migrations.dart => src/migrations/util.dart} (96%) diff --git a/config/default.yaml b/config/default.yaml index 592be3d7..fac269e3 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -1,3 +1,12 @@ # Default server configuration. host: 127.0.0.1 -mongo_db: mongodb://localhost:27017/angel \ No newline at end of file +mongo_db: mongodb://localhost:27017/angel +db: + migrate: + database: angel + username: root + password: password + web: + database: angel + username: username + password: password \ No newline at end of file diff --git a/config/development.yaml b/config/development.yaml index a4b3d020..bcfffb61 100644 --- a/config/development.yaml +++ b/config/development.yaml @@ -1,6 +1,2 @@ # Development-only server configuration. -port: 3000 -furlong: - database: angel - username: root - password: password \ No newline at end of file +port: 3000 \ No newline at end of file diff --git a/lib/src/migrations/migrations.dart b/lib/src/migrations/migrations.dart new file mode 100644 index 00000000..09ec0b61 --- /dev/null +++ b/lib/src/migrations/migrations.dart @@ -0,0 +1,4 @@ +library angel.migrations; + +export 'util.dart'; +export 'schemas/user.dart'; \ No newline at end of file diff --git a/lib/src/migrations/schemas/user.dart b/lib/src/migrations/schemas/user.dart new file mode 100644 index 00000000..96f7ecc3 --- /dev/null +++ b/lib/src/migrations/schemas/user.dart @@ -0,0 +1,24 @@ +import 'dart:async'; +import 'package:furlong/furlong.dart'; + +class UsersMigration extends Migration { + @override + String get name => "Users table"; + + @override + Future create(Migrator migrator) async { + migrator.create("users", (table) { + table.id(); + table.string("username"); + table.string("email"); + table.string("password"); + table.dateTime("created_at"); + table.dateTime("updated_at").nullable = true; + }); + } + + @override + Future destroy(Migrator migrator) async { + migrator.drop(["users"]); + } +} \ No newline at end of file diff --git a/lib/migrations/migrations.dart b/lib/src/migrations/util.dart similarity index 96% rename from lib/migrations/migrations.dart rename to lib/src/migrations/util.dart index bd82b9ac..5a0bccd4 100644 --- a/lib/migrations/migrations.dart +++ b/lib/src/migrations/util.dart @@ -1,5 +1,3 @@ -library angel.migrations; - import 'dart:async'; import 'dart:io'; import 'package:angel_configuration/angel_configuration.dart'; @@ -10,7 +8,7 @@ import 'package:sqljocky/sqljocky.dart'; Future createPool() async { var app = new Angel(); await app.configure(loadConfigurationFile()); - Map config = app.properties["furlong"]; + Map config = app.properties["db"]["migrate"]; if (config == null) throw new Exception( diff --git a/pubspec.yaml b/pubspec.yaml index 947c5e8f..b5e65914 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,8 +12,7 @@ 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 + furlong: ^1.0.0-dev json_god: ^2.0.0-beta validate: ^1.5.2 dev_dependencies: diff --git a/tool/grind.dart b/tool/grind.dart index fba5f057..a82b7619 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -1,9 +1,10 @@ -import 'package:angel/migrations/migrations.dart'; +import 'package:angel/src/migrations/migrations.dart'; import 'package:furlong/furlong.dart'; import 'package:grinder/grinder.dart'; final List migrations = [ // Your migrations here! + new UsersMigration() ]; main(args) => grind(args);