Comments (9)
Hi @erikbra
Need your thoughts on this matter. I would suggest making some refactoring in the structure like below:
Register the service in DI.
var builder = WebApplication.CreateBuilder(args);
builder.AddGrateMigration(grateConfiguration => {
// general configuration of grate like transaction, schema, etc
grateConfiguration.UseTransaction();
grateConfiguration.UseGrateSchema("grate");
// this extension method will be located in grate.sqlserver package.
// same for UseSqlServer, UsePostgreSql, UseMySql, UseOracle, UseSqlite
grateConfiguration.UseSqlServer(cfg => {
cfg.WithDatabaseName("your database here");
cfg.WithConnectionString(builder.Configuration.GetConnectionString("DefaultConnection"));
cfg.WithAdminConnectionString(builder.Configuration.GetConnectionString("AdminConnection"));
});
});
With this configuration, grate will register the hosted service in aspnetcore app and run the migration accordingly or we can trigger the migration programmatically when needed.
var services = builder.Services;
var grateMigrator = services.GetRequiredService<IGrateMigrator>();
await grateMigrator.Migrate("your_new_database_here");
I would like to get your view on that, if everything looks good, I will implement this feature in grate.
Thanh Tran.
Thanks.
from grate.
Hi, @georgehemmings and @hoangthanh28, I see your input here. I maintained RoundhousE for the last couple of years, and that was split into multiple packages like this. I made the decision not to do this for grate, as I thought it was very complex, and I didn't feel that it was necessary. But I'm willing to be convinced otherwise :)
I'm just curious to know a little bit about your workflow. The setup you mention above, with running grate on application startup resembles how Entity Framework does its migrations (at least previously), and this is one of my arguments against EF. It's not very convenient to run database migrations on application startup, as in most environments, you will run multiple instances of each application, and then, which one should run the migration and not, and you probably want to start the new version of your application before taking down your old one (think, if you are running in Kubernetes, e.g, it always starts a new pod before killing the old one). This will lead to problems for the old/existing version of the application, which expects the old schema, if there are changes.
I'm not unwilling per se to add this split of grate into multiple packages, I just want to know that the usage scenario is a common one, and understanding others' workflow is a good input here. Are you able to tell me a bit more about your setup/workflow on application deployment?
from grate.
Hi Erik (@erikbra )
That's good point otherwise, let me explain my workflow then.
My application is a multi-tenancy architecture, with the highest database isolation (each tenant has their database), which means that whenever a new tenant onboard, the database must be created and migrated with the appropriate version, suppose the version should be exact with the current version of service.
Currently, I need to setup 2 dedicated pipelines:
- init container in k8s (runs when new deployment) - works like a charm.
- runtime database migration, I need to create a new azp and trigger via webhook - which causes some out-of-process problems like network latency, intermittent, and losing traceability. With this proposal, I am trying to clear this burden. So when onboarding a new tenant, I just trigger the grate to migrate the appropriate version on the new database.
from grate.
Thank you for your explanation, @hoangthanh28. So, just to reiterate, you don't run grate automatically at application startup as part of deployment, you want to trigger it programatically without a new version of your application code, because you trigger it for a new database/schema/configuration (new tenant)?
That makes sense, I haven't thought of that.
I was initially very sceptical to maintaining libraries, as the binary compatibilities were quite a hassle, especially when the whole .net core/.net standard/.net framework transition took place, but now the number of TFMs for dotnet has been significantly reduced, so I'm more willing to do it now.
@georgehemmings and @hoangthanh28 , what .net versions would you need support for? Nothing lower than .net6?
from grate.
Hi Erik.
I run both at startup and runtime. For startup, I use the init container in k8s deployment manifest, for runtime, I would like to get rid of out-of-process ( like mentioned above) by implementing this proposal.
Please assign this ticket to me, I'm happy to implement this feature.
from grate.
Quick update @erikbra.
The implementation has been pushed to my github, I will spend time on unit tests and documents.
Please have a look first, I'm happy to walk you through and discuss if any doubts.
from grate.
We have a .NET Framework 4.7.2 WinForms application specifically for provisioning new databases and upgrading existing ones. Our clients self-host their databases.
It runs a few other scripts before and after RH migrate, such as password hash migration etc. The technician running the app just sets the connection details and presses "go".
The app could be ported to .NET 8.
I hope that gives you a better understanding of our need for programmatic migration.
from grate.
This should be fixed by #417 (thanks again, @hoangthanh28 ). I'm working my best to get out a 1.6 release now, it's long overdue, but I wanted to take the extra time to think this through some times. The surface we expose to users is much greater when providing an API than just the command line, and users will expect a stable API in the nuget packages as well.
But, we're getting there, hang in tight :)
from grate.
FYI, @georgehemmings - this is released and live on Nuget:
https://github.com/erikbra/grate/releases/tag/1.6.0
https://www.nuget.org/packages/grate.sqlserver#readme-body-tab (and friends - further link in the readme for this)
from grate.
Related Issues (20)
- Best practice for deploying SQL Agent Jobs HOT 1
- CREATE INDEX CONCURRENTLY cannot be executed within a pipeline (on Postgresql) HOT 8
- Run Grate from code HOT 5
- RoundhousE Feature | SearchAllSubdirectoriesInsteadOfTraverse HOT 5
- Azure SQL migrations with Managed Identity not working after 1.3.0 HOT 3
- MySQLConnector Hangs when connecting to MySQL 5.7 for DB Open() HOT 2
- Inconsistent script type for RunFirstAfterUpdate folder in documentation HOT 2
- Scripts using postgresql dollar-quoted strings fail in version 1.5.1 HOT 11
- Use Npgsql Code for Parsing PostgreSQL SQL Statements HOT 17
- Unable to connect to MySQL 8.0.30 using grate 1.5.3 HOT 5
- Silent flag doesn't work on version 1.5.3 on Linux HOT 6
- A noop run creates new entries in `Version` table HOT 1
- Migrating from Roundhouse, MySQL text_of_script column size too small HOT 2
- Documentation to support non-DotNet users HOT 2
- Unhandled exception trying to login to Azure SQL database HOT 3
- Improve error messages on SQL errors
- Getting Incorrect string value: '\xE2\x9C\xA8", ...' for column 'text_of_script' HOT 3
- SET QUOTED_IDENTIFIER OFF leads to Unhandled exception error HOT 2
- Running migrations on SQL Server fail - database is attempted to create though exists already HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grate.