Skip to content

[sqlserver] ensureVersionTable() errors with custom schema #839

@alex-kuck

Description

@alex-kuck

When using a default DB schema other than dbo, the ensureVersionTable() method errors.

Steps to Reproduce
Steps to reproduce the behavior:

  1. Create a user with default schema other than dbo: CREATE USER foo WITH PASSWORD = 'pw', DEFAULT_SCHEMA = [my_schema];
  2. Open connection to database: dbDriver, err := sqlserver.WithInstance(db, &sqlserver.Config{SchemaName: "my_schema",MigrationsTable: "schema_migrations",})
  3. When trying to open the connection a second time, the error occurs.

Expected Behavior
The method should either check for the version table in the given schema name OR always create the version table in the dbo schema.

Migrate Version
v4.15.2

Loaded Source Drivers
n.a

Loaded Database Drivers
sqlserver

Go Version
go1.19.2 darwin/arm64

Stacktrace

could not load migrations: could not create migration: could not create DB driver from instance: mssql: There is already an object named 'schema_migrations' in the database. in line 0: IF NOT EXISTS
	(SELECT *
		 FROM sysobjects
		WHERE id = object_id(N'[dbo].[schema_migrations]')
			AND OBJECTPROPERTY(id, N'IsUserTable') = 1
	)
	CREATE TABLE schema_migrations ( version BIGINT PRIMARY KEY NOT NULL, dirty BIT NOT NULL );

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