This commit is contained in:
Tobe O 2017-11-18 15:12:30 -05:00
parent 97989a6250
commit aa72814886
10 changed files with 229 additions and 1 deletions

View file

@ -25,9 +25,10 @@ dev_dependencies:
build_runner: ^0.5.0 build_runner: ^0.5.0
``` ```
`package:angel_orm_generator` exports two classes that you can include `package:angel_orm_generator` exports three classes that you can include
in a `package:build` flow: in a `package:build` flow:
* `PostgresOrmGenerator` - Fueled by `package:source_gen`; include this within a `LibraryBuilder`. * `PostgresOrmGenerator` - Fueled by `package:source_gen`; include this within a `LibraryBuilder`.
* `MigrationGenerator` - Builds a [`package:angel_migration`](https://github.com/angel-dart/migration) migration for your models automatically.
* `SqlMigrationBuilder` - This is its own `Builder`; it generates a SQL schema, as well as a SQL script to drop a generated table. * `SqlMigrationBuilder` - This is its own `Builder`; it generates a SQL schema, as well as a SQL script to drop a generated table.
You should pass an `List<String>` containing your project's models. You should pass an `List<String>` containing your project's models.

View file

@ -0,0 +1,26 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// Generator: MigrationGenerator
// **************************************************************************
import 'package:angel_migration/angel_migration.dart';
class AuthorMigration extends Migration {
@override
up(Schema schema) {
schema.create('authors', (table) {
table.serial('id')..primaryKey();
table.varchar('name', length: 255)
..defaultsTo('Tobe Osakwe')
..unique();
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
schema.drop('authors');
}
}

View file

@ -0,0 +1,25 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// Generator: MigrationGenerator
// **************************************************************************
import 'package:angel_migration/angel_migration.dart';
class BookMigration extends Migration {
@override
up(Schema schema) {
schema.create('books', (table) {
table.serial('id')..primaryKey();
table.varchar('name');
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.integer('author_id').references('authors', 'id').onDeleteCascade();
});
}
@override
down(Schema schema) {
schema.drop('books');
}
}

View file

@ -0,0 +1,27 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// Generator: MigrationGenerator
// **************************************************************************
import 'package:angel_migration/angel_migration.dart';
class CarMigration extends Migration {
@override
up(Schema schema) {
schema.create('cars', (table) {
table.serial('id')..primaryKey();
table.varchar('make');
table.varchar('description');
table.boolean('family_friendly');
table.timeStamp('recalled_at');
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
schema.drop('cars');
}
}

View file

@ -0,0 +1,25 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// Generator: MigrationGenerator
// **************************************************************************
import 'package:angel_migration/angel_migration.dart';
class FootMigration extends Migration {
@override
up(Schema schema) {
schema.create('foots', (table) {
table.serial('id')..primaryKey();
table.integer('leg_id');
table.integer('n_toes');
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
schema.drop('foots');
}
}

View file

@ -0,0 +1,25 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// Generator: MigrationGenerator
// **************************************************************************
import 'package:angel_migration/angel_migration.dart';
class FruitMigration extends Migration {
@override
up(Schema schema) {
schema.create('fruits', (table) {
table.serial('id')..primaryKey();
table.integer('tree_id');
table.varchar('common_name');
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
schema.drop('fruits');
}
}

View file

@ -0,0 +1,24 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// Generator: MigrationGenerator
// **************************************************************************
import 'package:angel_migration/angel_migration.dart';
class LegMigration extends Migration {
@override
up(Schema schema) {
schema.create('legs', (table) {
table.serial('id')..primaryKey();
table.varchar('name');
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
schema.drop('legs');
}
}

View file

@ -0,0 +1,24 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// Generator: MigrationGenerator
// **************************************************************************
import 'package:angel_migration/angel_migration.dart';
class RoleMigration extends Migration {
@override
up(Schema schema) {
schema.create('roles', (table) {
table.serial('id')..primaryKey();
table.varchar('name');
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
schema.drop('roles');
}
}

View file

@ -0,0 +1,24 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// Generator: MigrationGenerator
// **************************************************************************
import 'package:angel_migration/angel_migration.dart';
class TreeMigration extends Migration {
@override
up(Schema schema) {
schema.create('trees', (table) {
table.serial('id')..primaryKey();
table.integer('rings')..unique();
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
schema.drop('trees');
}
}

View file

@ -0,0 +1,27 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// Generator: MigrationGenerator
// **************************************************************************
import 'package:angel_migration/angel_migration.dart';
class UserMigration extends Migration {
@override
up(Schema schema) {
schema.create('users', (table) {
table.serial('id')..primaryKey();
table.varchar('username');
table.varchar('password');
table.varchar('email');
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.integer('role_id').references('roles', 'id');
});
}
@override
down(Schema schema) {
schema.drop('users');
}
}