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

Post-migration actions and post-migration database views refreshing #112

Merged
merged 12 commits into from
Jan 14, 2025

Conversation

mchlkntrv
Copy link
Contributor

Added post-migration actions and post-migration database views refresh with an option to accept the script ID up to which actions will be executed after migration. Added default script for refreshing views into resources.

Use:

const long scriptId = 20251912010;

builder.Services.AddKorm(builder.Configuration)
        .AddKormMigrations(options =>
        {
            var assembly = Assembly.GetEntryAssembly();
            options.AddAssemblyScriptsProvider(assembly, "CompanyStruct.SqlScripts");

            options.AddRefreshViewsAction();

            options.AddAfterMigrationAction(async (database, id) =>
            {
                if (id <= scriptId)
                {
                    database.ExecuteNonQuery("INSERT ...");
                }
                await Task.CompletedTask;
            });
        })
        .Migrate();

Action will be executed only if the ID of the latest script of the migration is less than or equal to the user-defined ID. If the ID is not defined, the action will execute regardless.

@Burgyn
Copy link
Member

Burgyn commented Dec 31, 2024

Pridaj prosím o tom informáciu do dokumentácie readme.md.

@Burgyn
Copy link
Member

Burgyn commented Dec 31, 2024

Chýbajú mi tu unit testy. Je to knižnica, ktorú používa veľa projektov tak je potrebné aby zmeny boli pokryté unitestami.

Je tam trieda MigrationsRunnerShould s testami pre migrácie. Tak tam prosím pridaj zopár scenárov pre tieto after migration akcie. Aj pre tie views.

Aspoň sa zoznámiš s unit testami.
DIk.

src/Migrations/MigrationOptions.cs Outdated Show resolved Hide resolved
var resourceName = $"{assembly.GetName().Name}.{DefaultResourceNamespace}.{scriptName}";
AddAfterMigrationAction(async (database, _) =>
{
Stream resourceStream = assembly.GetManifestResourceStream(resourceName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nejdem to teraz overovať, ale mám pocit, že GetManifestResourceStream vracia nullabe stream, čiže by si mala použiť Stream?. Ak je to tak tak prosím ešte over či je to null a ak áno tak vyhoď InvalidOperationException.

A rovnako použi prosím using Stream? .... Pretože aj Stream je disposable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pri jednom aj druhom usingu podľa mňa môžeš použiť await using miesto using. Ale istý som si není, neskúšal som to. Prosím skús.

src/Resources/RefreshViews.sql Show resolved Hide resolved
@mchlkntrv mchlkntrv requested a review from Burgyn January 8, 2025 13:20
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@Burgyn Burgyn merged commit fd6d222 into Kros-sk:master Jan 14, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants