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
171 stars 22 forks source link

Auto migration when application startup #20

Closed helphi closed 2 years ago

helphi commented 2 years ago
class User {
  int? age;
  String? name;
}

class Todo {
  int? order;
}

main() {
  var migrationRunner = PostgresMigrationRunner(
    PostgreSQLConnection('127.0.0.1', 5432, 'test'),
    migrations: [
      User, // no need UserMigration()
      Todo, // no need TodoMigration()
    ],
  );
}

When class add, delete or modify some fields, angel can auto alter table when start main function every time, like https://gorm.io/docs/.

dukefirehawk commented 2 years ago

Have you taken a look at the angel3_orm package?

Can refer to the following use cases on how to use: Project template at https://github.com/dukefirehawk/boilerplates/tree/angel3-orm Application example at https://github.com/dart-backend/belatuk-examples/tree/master/dchan

helphi commented 2 years ago

I mean also support runtime reflection, we prefer use reflection rather than build-runner if it's not a flutter project, thanks!

dukefirehawk commented 2 years ago

Currently, dart do not have a good library to support runtime reflection. Although dart:mirrors can do basic reflection but its use is not recommended as it will be deprecated in the future. The current recommended way is using pkg:reflectable which is build_runner based reflection. Without runtime reflection library, this feature would be tough to implement.

See: https://github.com/dart-lang/sdk/issues/44489

Anyway, I'm open to anyone that would like to take a crack at this feature

debuggerx01 commented 2 years ago

I think write alter migrations manually is better for both version control and multiple deploy environments. Also for dart:mirrors will avoid aot compile, that's why I don't like reflection

dukefirehawk commented 2 years ago

Agree. Automatically changing database schema is never a good idea for production. Even for development, it is rarely used. Something like Flyway would be a lot better for keeping track of database migration versions.

outersky commented 2 years ago

I think write alter migrations manually is better for both version control and multiple deploy environments. Also for dart:mirrors will avoid aot compile, that's why I don't like reflection

+1

It is dangerous.