Simple database Migration manager

01/29/2020 23:01 pintinho12#1
Hello!

Today I've got a few free minutes at my work and coded something that I noticed that I need long time ago! There's room for improvements of course but this will be good for those who often updates their game database and also need to keep track of the changes. The script is simple and I'll be updating here as I upgrade my code on my source.


How to use:
  • Create a 'migrations' folder on your executable path
  • Put all your SQL Scripts in files inside of it
  • Files must have yyyyMMddHHmmss as the first 14 characters
  • Files must have from 16 to 128 characters
  • Before loading your mysql data just create a new instance of the MigrationManager and call .Migrate() method
  • Done!

Then, anything that you code on your test database, save the final code on a SQL file, name it 20200129183000 WhateverYouWant.sql and put in your production migrations folder! If the code hasn't been executed, your server will execute and you can keep track of the updates.

Ey! I'm sending your first migration sql file so you can test it! Good luck.

PS: don't forget to change the namespace!
01/30/2020 00:24 Spirited#2
I see a lot of work went into this, so first thing's first, good job. But doesn't EF Core also allow you to track database migrations via command line?
01/30/2020 00:38 turk55#3
Quote:
Originally Posted by Spirited View Post
I see a lot of work went into this, so first thing's first, good job. But doesn't EF Core also allow you to track database migrations via command line?
dotnet ef migrations add [MigrationName]
01/30/2020 02:56 pintinho12#4
I know that I have a lot of things that I want to implement, but, I use Fluent NHibernate in my project and I don't want to depend on it to do everything. With files I have freedom to write SQL code as I wish.
But this will be updated as I find better pratices too. But for this I mostly just want to depend on MySQL standard library.
01/30/2020 04:34 Super Aids#5
What's up with the variable names?
01/30/2020 04:47 Relic#6
Quote:
Originally Posted by Super Aids View Post
What's up with the variable names?
Looks like he's using an outdated naming convention, back when IDEs weren't as powerful especially with intellisense.

[Only registered and activated users can see links. Click Here To Register...]

It's all personal preference in the end though.
01/30/2020 09:05 KraHen#7
I also don't see why the standard .NET migrations are not sufficient for this, but hey. :D Also, what's the reason behind fluent nhibernate? I'm a bit out of the loop with ORM stuff but IIRC it was really slow compared to the competition (I think it was Dapper maybe?)
01/30/2020 18:31 pintinho12#8
Quote:
Originally Posted by KraHen View Post
I also don't see why the standard .NET migrations are not sufficient for this, but hey. :D Also, what's the reason behind fluent nhibernate? I'm a bit out of the loop with ORM stuff but IIRC it was really slow compared to the competition (I think it was Dapper maybe?)
If I start changing my server ORM now I will need to rewrite the entire server. Fluent NHibernate isn't slow at all, I never had performance issues with it, but since most servers out there doesn't use any ORM.
There's FluentMigrator but I don't want to use it. Also SchemaUpdate once droped all my tables and I got mad at it xD but of course it was my fault.