EntityFrameworkCore.TemporalTables icon indicating copy to clipboard operation
EntityFrameworkCore.TemporalTables copied to clipboard

Include temporal tables in migration script

Open bcallaghan-et opened this issue 6 years ago • 3 comments

Right now, the migration code and the migration SQL scripts look the same as if temporal tables were not being used. The ITemporalTableSqlBuilder interface has to be used in order to preview the exact SQL script or to execute that script manually. It would be useful if the EF migration files included the temporal columns and flags so that the changes can be previewed or modified.

bcallaghan-et avatar Mar 19 '20 23:03 bcallaghan-et

I can't seem to find a solution how to plug a custom SQL script in the migrations themselves. The only solution I find is creating a custom migrations operations (https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/operations) where you create an extension method over MigrationBuilder and have it generate your custom SQL code but then you have to manually call the extension method in your migration. I haven't tested if you call Script-Migration whether the custom SQL will show up but even if it does, one can always forget to call the extension method and we are back to basics.

If you or someone else have an idea or appropriate solution, I would be happy to take a look at it.

findulov avatar Mar 21 '20 23:03 findulov

I have attempted to include temporal-metadata into the migrations myself, and it is much more complicated than I initially expected. My approach was similar to the one you took by extending the SqlServerMigrationsGenerator for #4. My prototype also extended the CreateTableOperation to try and include the SysStartTime and SysEndTime properties in the initial table rather than tacking them on at the end. While such extensions would be nice, I've come to the conclusion that full support for temporal tables is best left for the official SQL Server provider. That feature is being tracked by dotnet/efcore#4693.

bcallaghan-et avatar Mar 26 '20 17:03 bcallaghan-et

Due to this it's not possible to generate SQL scripts using dotnet ef migrations script

Armarr avatar Mar 31 '20 14:03 Armarr