Skip to content
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

Add migrations for database setup #258

Open
linkdotnet opened this issue Aug 2, 2023 · 11 comments
Open

Add migrations for database setup #258

linkdotnet opened this issue Aug 2, 2023 · 11 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@linkdotnet
Copy link
Owner

Currently, the migration for the database has to be done manually. It would be nice if a BackgroundService does the initial database setup (instead of Database.EnsureCreated) and migration.

For starters, this could be an "SQL" only thing and incrementally also supported for RavenDB, if anyone uses this.

@linkdotnet linkdotnet added enhancement New feature or request help wanted Extra attention is needed labels Aug 2, 2023
@manishtiwari25
Copy link
Contributor

We can just add migrations and create a script (or something) to run the migrations, instead of adding it in a background job.

@linkdotnet
Copy link
Owner Author

We can just add migrations and create a script (or something) to run the migrations, instead of adding it in a background job.

You mean something in the direction of DbUp? So basically a bunch of SQL scripts that get executed via a CLI tool and or script.

I thought of that, but we might have to maintain scripts for MySQL/SqlServer/Postgres and so on... adding a new provider would mean, they have to backport those scripts to said provider.

The obvious choice would be EF.Migrations (at least for the SQL Part).

@Kamyab7
Copy link
Contributor

Kamyab7 commented Dec 17, 2023

I'm thinking of something like Json Taylor did in this repo
https://github.com/jasontaylordev/CleanArchitecture
if you take a look here
https://github.com/jasontaylordev/CleanArchitecture/blob/main/src/Infrastructure/Data/ApplicationDbContextInitialiser.cs
there is a class that can migrate the database automatically using EF.

@linkdotnet
Copy link
Owner Author

Yes exactly - that was my initial thought. Not sure whether or not that is really applicable here, as there aren't that many moving parts in the database (well, yesterday I merged a PR with a new field on BlogPosts with ReadingTimeInMinutes).

The advantage is that we would have one provider managing migrations (at least for the SQL part). Also we can write update-scripts in C#. If they really have to be executed on startup is a different topic and more or less a detail.

@Kamyab7
Copy link
Contributor

Kamyab7 commented Dec 17, 2023

We can make some searches to find best practices for reaching this goal also I'm thinking of some kind of strategy design pattern for handling the NoSQL part as well.

@linkdotnet
Copy link
Owner Author

Yeah - I'm also not very sure how much usage the NoSQL providers have and if the way forward would be dropping those. That would make the code way easier!

@Kamyab7
Copy link
Contributor

Kamyab7 commented Dec 17, 2023

Yeah - I'm also not very sure how much usage the NoSQL providers have and if the way forward would be dropping those. That would make the code way easier!

Good, I will create a pull request as soon as possible to tackle this issue.

@linkdotnet
Copy link
Owner Author

Much appreciated - yeah currently I am not sure if I can come to a conclusion. I would argue EF.Migrations might be a good way of kickstarting. Then at least one part would be covered.
Not the most urgent thing right now, but still nice to have.

@Kamyab7
Copy link
Contributor

Kamyab7 commented Jan 23, 2024

Hey Steven, I was a bit busy and now I'm trying to solve this issue.

I've been dealing with an issue recently and could use your insights. When attempting to add a new migration, I encountered a series of error messages. It seems like the culprit might be the editor config rules.

For instance, the generated migration file doesn't obey file scoped namespace

My initial thought was to have the .editorconfig ignore the migrations directories, but I'm not entirely sure if that's the most suitable solution. Have you come across any alternative approaches to address this issue? Your expertise would be greatly appreciated.

@linkdotnet
Copy link
Owner Author

Hey Kamyab, cool to hear back from you. Hope you are doing well!

To be honest I do think having a separate .editorconfig is suitable for that. It is basically 3rd party code so it doesn't have to follow the same rules as "our" code (and it may or may not change that at any point in time).
We already have different rules for .cs files that are under the tests directory. So that wouldn't be a novum here.

So yeah I would really go here with your intuition!

@Kamyab7
Copy link
Contributor

Kamyab7 commented Jan 23, 2024

Hey Kamyab, cool to hear back from you. Hope you are doing well!

To be honest I do think having a separate .editorconfig is suitable for that. It is basically 3rd party code so it doesn't have to follow the same rules as "our" code (and it may or may not change that at any point in time). We already have different rules for .cs files that are under the tests directory. So that wouldn't be a novum here.

So yeah I would really go here with your intuition!

Thanks Steven, It worked.
After several tests to make sure everything looks fine, I will create a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants