migrate_34_test.go
TLDR
The file migrate_34_test.go
contains test functions for the migration step 34 in the SQL store. The tests ensure that a specific column named delete_at
is dropped from the table focalboard_category_boards
for MySQL and PostgreSQL databases.
Methods
-
Test34DropDeleteAtColumnMySQLPostgres
: This method executes two sub-tests.- In the first sub-test, it verifies that the
delete_at
column does not exist in thefocalboard_category_boards
table for MySQL and PostgreSQL databases after migrating to step 34. - In the second sub-test, it checks that the
delete_at
column is not dropped again if it was already deleted during a previous migration.
- In the first sub-test, it verifies that the
package migrationstests
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test34DropDeleteAtColumnMySQLPostgres(t *testing.T) {
t.Run("column exists", func(t *testing.T) {
th, tearDown := SetupTestHelper(t)
defer tearDown()
th.f.MigrateToStep(34)
// migration 34 only works for MySQL and PostgreSQL
if th.IsMySQL() {
var count int
query := "SELECT COUNT(column_name) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'focalboard_category_boards' AND column_name = 'delete_at'"
th.f.DB().Get(&count, query)
require.Equal(t, 0, count)
} else if th.IsPostgres() {
var count int
query := "select count(*) from information_schema.columns where table_name = 'focalboard_category_boards' and column_name = 'delete_at'"
th.f.DB().Get(&count, query)
require.Equal(t, 0, count)
}
})
t.Run("column already deleted", func(t *testing.T) {
th, tearDown := SetupTestHelper(t)
defer tearDown()
// For migration 34, we don't drop column
// on SQLite, so no need to test for it.
if th.IsSQLite() {
return
}
th.f.MigrateToStep(33).
ExecFile("./fixtures/test34_drop_delete_at_column.sql")
th.f.MigrateToStep(34)
if th.IsMySQL() {
var count int
query := "SELECT COUNT(column_name) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'focalboard_category_boards' AND column_name = 'delete_at'"
th.f.DB().Get(&count, query)
require.Equal(t, 0, count)
} else if th.IsPostgres() {
var count int
query := "select count(*) from information_schema.columns where table_name = 'focalboard_category_boards' and column_name = 'delete_at'"
th.f.DB().Get(&count, query)
require.Equal(t, 0, count)
}
})
}