Auto migration when application startup
Closed this issue · 6 comments
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/.
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
I mean also support runtime reflection, we prefer use reflection rather than build-runner if it's not a flutter project, thanks!
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: dart-lang/sdk#44489
Anyway, I'm open to anyone that would like to take a crack at this feature
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
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.
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.