aboutsummaryrefslogtreecommitdiffstats
path: root/internal/repositories/migration_db_repo_mssql_test.go
blob: a46cc69e8cc50e90b8f96087c95ce8f2e77ec413 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//go:build mssql

package repositories_test

import (
	"testing"

	"git.eugenetriguba.com/bolt/cli/internal/bolttest"
	"git.eugenetriguba.com/bolt/cli/internal/repositories"
	"git.eugenetriguba.com/checkmate/assert"
)

func TestNewMigrationDBRepo_CreatesTableInSchema_MSSQL(t *testing.T) {
	testdb := bolttest.NewTestDB(t)
	schemaName := "custom_schema"
	tableName := schemaName + ".bolt_migrations"

	t.Cleanup(func() {
		_, err := testdb.Exec("IF OBJECT_ID('" + tableName + "', 'U') IS NOT NULL DROP TABLE " + tableName)
		assert.Nil(t, err)
		_, err = testdb.Exec("IF SCHEMA_ID('" + schemaName + "') IS NOT NULL DROP SCHEMA " + schemaName)
		assert.Nil(t, err)
	})

	_, err := testdb.Exec("IF SCHEMA_ID('" + schemaName + "') IS NOT NULL DROP SCHEMA " + schemaName)
	assert.Nil(t, err)

	_, err = testdb.Exec("CREATE SCHEMA " + schemaName)
	assert.Nil(t, err)

	exists, err := testdb.TableExists(tableName)
	assert.Nil(t, err)
	assert.False(t, exists)

	_, err = repositories.NewMigrationDBRepo(tableName, testdb)
	assert.Nil(t, err)

	exists, err = testdb.TableExists(tableName)
	assert.Nil(t, err)
	assert.True(t, exists)
}