Migrate: SchemaName is ignored for postgres.Config

Created on 15 Feb 2020  路  3Comments  路  Source: golang-migrate/migrate

func migrateDb(db *sql.DB) {
    driver, _ := postgres.WithInstance(db, &postgres.Config{
        MigrationsTable: "migrations",
        SchemaName:      "myschema"})
    m, _ := migrate.NewWithDatabaseInstance(
        "file:///sql/migrations",
        "blablabla", driver)
    if err := m.Up(); err != nil {
        Log("FATAL", err)
    }
}

Expected Behavior
Schema myschema used for the creation of the migrations table

Migrate Version
v3.4

Loaded Database Drivers
postgres, postgresql

duplicate

Most helpful comment

This still doesn't work. If I create a new schema named "my_test_schema" and set:

postgres.Config{
    DatabaseName: "testdb",
    SchemaName: "my_test_schema",
}

The migration table and all the migrations will be created in the public schema.

All 3 comments

Duplicate of https://github.com/golang-migrate/migrate/issues/262
Try updating to v4.7+. If you still have issues, use the other thread.

This still doesn't work. If I create a new schema named "my_test_schema" and set:

postgres.Config{
    DatabaseName: "testdb",
    SchemaName: "my_test_schema",
}

The migration table and all the migrations will be created in the public schema.

As per my comment above, I think the issue is that in the sql files I'm not using the schema name prefixed to the table names and this is why it creates it in the public schema.

I think a "SET SCHEMA " should be issued before running the migrations to make sure any sql that's read is appended on the correct schema.

Was this page helpful?
0 / 5 - 0 ratings