Skip to content

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

@mydogisbox

Description

@mydogisbox
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions