Hi all,
I´m new to the EF community, I have being watching the project evolution since their starts, and now I´m thrilled about the opportunity to collaborate since the project became open source.
Currently EF Migrations support is restricted to this two scenarios:
- Extending or changing existing migration operations behavior, inheriting from a concrete generator (like SqlServerMigrationSqlGenerator)
- Creating a Migrator from scratch, when you inherit from MigrationSqlGenerator, but only for existing MigrationOperation types.
However, both scenarios fall short, when you want to create new operation types (inheriting fromMigrationOperation), and add then to the migration internal operation list to allow the custom generator to process it.
For example, a user wants to add a new operation for creating views. By extendingDBMigrator he can create a method for adding a new CreateViewOperation:
publicabstractclass CustomDbMigration : DbMigration { protectedvoid CreateView(string viewName, string table, string[] columns) { var m = new CreateViewOperation(viewName, string table, string[] columns); //Currently this isn't possible AddOperation(m); } }
And then he want to proccess this new operation type in his custom generator:
publicclass CustomMigrationSqlGenerator : SqlServerMigrationSqlGenerator { //Currently this method is never calledprotectedvirtualvoid Generate(CreateViewOperation operation) { string createViewSql = "CREATE VIEW "+ operation.ViewName" + "AS SELECT " + operation.ColumnsAsString() + "FROM "+ operation.Table "; Statement(createViewSql); } }
I would like to propose creating the internals needed to support the creation of custom operations, so that EF migrations users could add operations as needed.
I´m thinking about making the following changes:
- Make the AddOperation method in DBMigration protected, to allow adding new operation instances easily. This way you can process them when you add your ownMigrationSqlGenerator.
- Change the SqlServerMigrationSqlGenerator and allow to discoverGenerate methods in inherited classes. This would make easy to extend existing generators and only add new operations to it.
I would like to hear your thoughts about extension support on EF Migrations, and I´m opened to any implementation proposal that you may have.