dart-backend / angel

A polished, production-ready backend framework in Dart for the VM, AOT, and Flutter.
https://github.com/dukefirehawk/angel
BSD 3-Clause "New" or "Revised" License
173 stars 21 forks source link

Db migrations run, generate the 'migrations' table but not the new tables, is it working? #70

Closed atreeon closed 2 years ago

atreeon commented 2 years ago

A migrations table is created but no rows are added in it nor are my new tables added. Any ideas?

Command I'm running (or up / refresh)

dart run bin/createDb2.dart reset

createDb2.dart

import 'package:angel3_migration/angel3_migration.dart';
import 'package:angel3_migration_runner/angel3_migration_runner.dart';
import 'package:angel3_migration_runner/postgres.dart';
import 'package:angel3_orm/angel3_orm.dart';

import 'book.dart';
import 'getConnection.dart';

void main(List<String> args) async {
  await runMigrations(migrationRunner, args);
}

var migrationRunner = PostgresMigrationRunner(
  getConnection(eDbType.supabaseTest),
  migrations: [
    BookMigration(),
  ],
);

book.dart

import 'package:angel3_migration/angel3_migration.dart';
import 'package:angel3_orm/angel3_orm.dart';
import 'package:angel3_serialize/angel3_serialize.dart';
import 'package:optional/optional.dart';

part 'book.g.dart';

@orm
@serializable
abstract class _Book extends Model {
  String? get author;

  @SerializableField(defaultValue: '[Untitled]')
  String? get title;

  String? get description;

  int? get pageCount;
}

Generated Migration code

class BookMigration extends Migration {
  @override
  void up(Schema schema) {
    schema.create('books', (table) {
      table.serial('id').primaryKey();
      table.timeStamp('created_at');
      table.timeStamp('updated_at');
      table.varChar('author', length: 255);
      table.varChar('title', length: 255).defaultsTo('[Untitled]');
      table.varChar('description', length: 255);
      table.integer('page_count');
    });
  }

  @override
  void down(Schema schema) {
    schema.drop('books');
  }
}
atreeon commented 2 years ago

btw, I've tried Supabase, Serverpod, Conduit and this seems to be the closest thing to a dart postgres ORM that seems to work. Well done for supporting and creating. I think Angel3 ORM is my only option if I want to use postgres with serverside dart. (Serverpod and Conduit both had too many dependencies and Supabase isn't strongly typed)

dukefirehawk commented 2 years ago

This should be working. Will take a look.

dukefirehawk commented 2 years ago

This is a regression bug caused by migration runner incorrectly generated SQL code for defaultsTo('[Untitled]') as default [Untitiled] instead of default '[Untitiled]'. The fix is on bug-fix/orm-generator branch. Will publish a new version once the default for temporal fields are sorted out.

dukefirehawk commented 2 years ago

Resolved in the latest release angel3_orm 6.1.0