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

Less horrible way to run migrations with dynamic connection string? #49

Open
mydogisbox opened this issue Jul 29, 2019 · 1 comment
Open

Comments

@mydogisbox
Copy link

let loadUserModel () =
    let assemblyFolder = Path.GetDirectoryName(Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)
    let resolutionFolder = Path.Combine(assemblyFolder, "../../../TempDBImpl")
    UserModel.Load(resolutionFolder, ".")

let migrate connectionString =
    let backend : IBackend = unbox (Rezoom.SQL.Compiler.Postgres.PostgresBackend())
    let connection = Configuration.ConnectionStringSettings("Test", connectionString)
    connection.ProviderName <- "Npgsql"
    let result = <@ (%backend.MigrationBackend) connection @>
    let migrationBackend = result.Evaluate()
    let model = loadUserModel()
    MigrationExtensions.Run ((model.Migrations.ToArray()), MigrationConfig.Default, fun () -> migrationBackend)

Note that this requires pulling in a library just to execute the expressions ( result.Evaluate() ).

It would be great if SQLModel<".">.Migrate() had an overload to take a connection string instead of just the name of a connectionName from a config.

@mydogisbox
Copy link
Author

From looking at the code, it looks like it would be pretty easy to add a MigrateUsingConnectionString. If that's acceptable I might find some time to create a PR for it.

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

No branches or pull requests

1 participant