diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-08-18 16:06:54 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-18 16:06:54 -0400 |
| commit | 3ad5a6ab1ef53330f18014b710534d0ed0cd55b0 (patch) | |
| tree | 5b5d1ed42e59314e65a4ddb8bff2dd7c059fedd9 /internal/storage/mssql.go | |
| parent | Add a couple helper scripts (diff) | |
| download | cli-3ad5a6ab1ef53330f18014b710534d0ed0cd55b0.zip | |
Fix using a schema with a custom migration table name (#7)
* Fix using a schema with a custom migration table name
* Fix test
Diffstat (limited to 'internal/storage/mssql.go')
| -rw-r--r-- | internal/storage/mssql.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/internal/storage/mssql.go b/internal/storage/mssql.go index a7fbead..4a084ca 100644 --- a/internal/storage/mssql.go +++ b/internal/storage/mssql.go @@ -31,17 +31,27 @@ func (m MSSQLAdapter) TableExists( tableName string, ) (bool, error) { var exists bool + + schemaName := "dbo" + parts := strings.Split(tableName, ".") + if len(parts) == 2 { + schemaName = parts[0] + tableName = parts[1] + } else { + tableName = parts[0] + } + err := executor.QueryRow(` SELECT CASE WHEN EXISTS ( SELECT * FROM INFORMATION_SCHEMA.TABLES - WHERE TABLE_SCHEMA = 'dbo' - AND TABLE_NAME = @p1 + WHERE TABLE_SCHEMA = @p1 + AND TABLE_NAME = @p2 ) THEN 1 ELSE 0 END - `, tableName).Scan(&exists) + `, schemaName, tableName).Scan(&exists) if err != nil { return false, fmt.Errorf( - "unable to check if dbo.%s exists: %w", + "unable to check if %s exists: %w", tableName, err, ) |