erikbra / grate

grate - the SQL scripts migration runner
MIT License
165 stars 36 forks source link

Running Grate on RoundhousE database - all scripts are new #550

Open Edgaras91 opened 1 week ago

Edgaras91 commented 1 week ago

Describe the bug Using grate.sqlserver, HasRun() check is fetching scripts from RoundhousE.GrateScriptsRun which is wrong when trying to run my scripts (xxxx.NewAddressColumns.sql). My scripts already ran and are in RoundhousE.ScriptsRun table.

To Reproduce Have an existing RoundhousE tables such as "RoundhousE.ScriptsRun". Specify the "RoundhousE" schema in start-up.

Expected behavior The existing RoundhousE script to not run again.

Desktop (please complete the following information):

Context This in AnsiSqlDatabase class, this is the cache: private async Task<IDictionary<string, string>> GetScriptsRunCache() => _scriptsRunCache ??= await GetAllScriptsRun(); _scriptsRunCache is shared across all migration scripts (Grate scripts and user scripts) which is wrong. user scripts should either "refresh" the cache using the correct table "ScriptsRun" or separate instance of the AnsiSqlDatabase class, or another property to store this (or something else)

Edgaras91 commented 1 week ago

After checking the codebase more, I think the easiest fix for this, is to make the AnsiSqlDatabase._scriptsRunCache more complex than IDictionary<string, string>? to cater for multiple tables (Schema.GrateScriptsRun and Schema.ScriptsRun since that's what we have now (we didn't have 2 sets of tables with roundhousE).

should be in this kind of format "Schema.GrateScriptsRun", IDictionary<string, string>? and then check ScriptsRunTable property if we have a key for that.

So Dictionary<string, Dictionary<string, string>>

This should allow to cache multiple tables.