-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create/ensure compatible db structures at runtime #6221
Comments
Possibly related to #6214 |
@MatthewMWR The compatibility checking in EF6 was based on having metadata for your model in the database, typically in the MigrationsHistory table. But it seems like you are asking to be able to check compatibility without having control over how the database is created/maintained--i.e. with just a database schema to work with. If this is the case, then I don't think it is something we are going to implement. It would essentially be a reverse-engineer of the database to a model and then a diff of that model against the current model. We have discussed doing this in the past, but while it would work in simple cases it is hard to make it robust enough to be really useful. On the other hand, if you are OK with creating a database with model metadata in it, then I believe Migrations has all the infrastructure to do the compatibility check although I would have to ask for help for how to wire it all up to work at runtime. |
Thanks for the context. I see now that my fictitious method name implied a much broader two way set of logic than what I had in mind. The two way compatibility matrix logic you described would be nifty, but what I want is considerably less ambitious. AllI really want is a version of EnsureCreated() that will still try to create the tables if the db already exists. The code to create the tables from current model already exists, but currently there is no way to call it outside of EnsureCreated() which bails if the db already exists. |
@MatthewMWR You need to use var creator = context.GetService<IRelationalDatabaseCreator>(); This gives you lower-level access over the database operations. |
@MatthewMWR I created a simple tool for the same, I need to rewrite using IRelationalDatabaseCreator, but this tool is working well against SQL Server with simple data structure. https://github.com/neurospeech/ef-core-live-migration , I would be happy to have some contribution to improve it. I have also created a mock library to mock Sql LocalDB per instance at https://github.com/neurospeech/ef-core-localdb-mock |
Feature request: Create/ensure compatible db structures at runtime
In EF6 there were APIs along the lines of Database.EnsureCompatible() (don't remember the exact names). These we useful for scenarios not covered by EFCore implementation of Migrations or EnsureCreated() . For example:
Please consider for future development either adding an EnsureCompatible() like API, or extending Migrations infrastructure with runtime flexibility such that migrations can be created and used at runtime rather than via Visual Studio and design time artifacts.
Thanks.
The text was updated successfully, but these errors were encountered: