Entity framework core code first migration postgresql database privileges management - postgresql

I need to set up an automated way to manage table privileges and ownership during migration execution.
Currently, the workflow is that a developer runs database migrations using his personal account during the new version release. The issue here is that he is automatically set as the owner of newly created tables, and the owner and privileges for table access have to be changed manually afterwards. I'm looking for a way to automate this, but could not find a solution. My assumption is that this is not supported by ef core as permission/ownership handling differs on underlying database used, but I don't see a reason for specific ef providers not to have this functionality. I'm probably missing something obvious and any help would be appreciated.
We are using .NET 5 with EF Core 5.0 with Postgresql.

Related

Entity Framework Database Generation Power Pack?

I use Model-first with EF, and I want to have an automated gap DDL script when I change my model. With "Entity Framework Database Generation Power Pack" We had it in past, but I read that was not supported in VS2012.
Any changes about that?
For Who dont't understand this need, I would like to remmember that in production enviroments, development team dosen't have access to DB. We must create and send to production Support team, DDL deployment scripts that preserve data and all DB without any recreation.
You should have a look at Database.SetInitializer, which mainly determines what happens if there is no database present when the application is started for the first time, and migrations which can be used to update the datebase when a new application version (which requires an updated database) has been deployed. If the built-in support for migrations data aren't enough, you also have the ability to add raw SQL data to handle migrating to a new version.

Manual synchronization between Context and Database using EF Codefirst

I'm using EF 5.0 (CodeFirst) with VS 2012. I changed my model (entity) and manually changed my database. I try to run the application and the following error appears:
The model backing the 'XXXContext' context has changed since the
database was created. Consider using Code First Migrations to update
the database (http://go.microsoft.com/fwlink/?LinkId=238269).
My only change was the name of the entity property (column in the database).
Its automate or ignore the synchronization? For the same has been done manually, only the application that does not recognize it. Or run something that validates manual synchronization.
Where is the recorded synchronization information for the application to know that there was a change?
Thanks
You have the option of using Database Initializers or Migrations. In your application startup you can enable initializers with the following:
System.Data.Entity.Database.SetInitializer<YourDbContextType>(new DropCreateDatabaseIfModelChanges());
You can also subclass and create your own logic if needed. See http://www.codeguru.com/csharp/article.php/c19999/Understanding-Database-Initializers-in-Entity-Framework-Code-First.htm for more info.
You can also enable migrations and let them automatically update your database. Running Enable-Migrations in the Package Manager Console does this. Look here for more information http://msdn.microsoft.com/en-us/data/jj591621.aspx

Migrate a given (old) database to current model

I am struggling with entity framework's migration quite a bit. Below is how I plan on using migrations, but I find no information on how to accomplish this:
My users are creating databases (Sql Compact Server) on their premises with different versions of my software. Each version introduces a slightly changed EF model. As soon as a user updates to a newer version of the software and opens a database with a previous version of the model, I would like to have some sort of "auto migration" bring the given database up-to-date to the current model.
Is there any way to do this?
Use the MigrateDatabaseToLatestVersion database initializer. See this link for more info.

Migrating from Entity Framework Code First from Development to Production

I have been working on a side project for the last few weeks, and built the system with EntityFramework Code first. This was very handy during development, as any changes i needed to make to the code were reflected in the DB nice and easily. But now that i want to launch the site, but continue development, i dont want to have to drop and recreate the DB every time i make a tweak to a model...
Is there a way to get EF to generate change scripts for the model change so i can deploy them myself to the production server? And how do i use the database somewhere else (Windows Service in the background of the site) without having to drop and recreate the table, and use the same model as I have already? Kind of like a "Code first, but now i have a production DB, dont break it..."
Personally i use the builtin data tools in VS2010 to do a database schema synchronization for updating production.
Another cheaper tool if you dont have VS Premium is SQLDelta which ive used in the past and is really good.
Both tools connect to the two database versions and allow you to synchronise the table schemas first. Both also have an export to SQL script functionality.
Comming up for EF is Migrations which allows you to solve just this problem within your solution however its still in beta. Migrations lets you describe upgrade and downgrade events for your database in code.
No RTM version of EF has this feature. Once you go to production you must handle it yourselves. The common way is to turn off database initializer in production and use some tool like VS Premium or RedGate Database compare to compare your production and dev database and create change SQL script.
You can also try to use EF Migrations which is exactly the tool you are asking for. The problem is it is still beta (but it should be part of EF 4.3 once completed) so it doesn't have to work in all cases and functionality / API can change in RTM.

Incremental Database development in Entity framework code first

How can I do incremental developments with entity framework code first database. Because if I change something i model classes it will regenerate the database which cased to loss my data already in the database. I'm using DropCreateDatabaseIfModelChanges . Is there any thing other than that to execute alter quires rather than recreating.
EF Code First Migrations would help you here, it's in alpha/CTP currently: Entity Framework Code First Migrations: Alpha, also check out the ADO.NET team blog:
The most consistent request we have heard from you since releasing EF
4.1 has been for a migrations solution for Code First that will
incrementally evolve the database schema as you model changes over
time. Today we are announcing the release of our first Community
Technical Preview (CTP) of our Code First Migrations work.
As I recall, the Microsoft docs tell you to be sure not to use DropCreateDatabaseIfModelChanges in production environments. The point of that option is to help you come up with code-based data population for your test runs. I haven't seen any tools to help with incremental changes when using code-first. Where I work, we use a database-first setup, and we create a change script for each new release that includes alter and insert statements.
incremental database development is not currently available in the current version of the codefirst framework however it is included in the roadmap for the next release which will ship with MVC 4
as of right now you would need to remove metadata tracking from the database conventions and update the database manually via scripting or using the sql tooling until this new convention is added to the framework