mirror of
https://github.com/mattermost/focalboard.git
synced 2025-01-11 18:13:52 +02:00
03f4717e96
* WIP * Added migrations * Updating store method * WIP * WIP * Updated DND * WIP * WIP * WIP * WIP * WIP * wip * WIP * Adding new DB tool * Used migration functions in new migrations * Unique constraint migration * Unique constraint migration * Added SQLITE migrations * Added SQLITE support in few more migrations * Added SQLITE support in few more migrations * WIP * Used old-fashioned way to add unique constraint * Using oldsqlite method * Using oldsqlite method * Fixed all store and app layer tests * fixed integration tests * test and lint fix * Updated migration for MySQL and Postgres on personal server * Types fix * sqlite fix * fix typo * misc cleanup * added new tests * added new tests * de-duping input for postgres * integration tests, rmeoved uneeded migration * Added some migration tests * Added some migration tests * Fixed a test * completed migration tests * completed migration tests * Removed leftover debug statements Co-authored-by: Mattermost Build <build@mattermost.com>
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package migrationstests
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test36AddUniqueConstraintToCategoryBoards(t *testing.T) {
|
|
t.Run("constraint doesn't alreadt exists", func(t *testing.T) {
|
|
th, tearDown := SetupTestHelper(t)
|
|
defer tearDown()
|
|
|
|
th.f.MigrateToStep(36)
|
|
|
|
// verifying if constraint has been added
|
|
|
|
//can't verify in sqlite, so skipping it
|
|
if th.IsSQLite() {
|
|
return
|
|
}
|
|
|
|
var count int
|
|
query := "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS " +
|
|
"WHERE constraint_name = 'unique_user_category_board' " +
|
|
"AND constraint_type = 'UNIQUE' " +
|
|
"AND table_name = 'focalboard_category_boards'"
|
|
th.f.DB().Get(&count, query)
|
|
|
|
require.Equal(t, 1, count)
|
|
})
|
|
|
|
t.Run("constraint already exists", func(t *testing.T) {
|
|
th, tearDown := SetupTestHelper(t)
|
|
defer tearDown()
|
|
|
|
// SQLIte doesn't support adding constraint to existing table
|
|
// and neither do we, so skipping for sqlite
|
|
if th.IsSQLite() {
|
|
return
|
|
}
|
|
|
|
th.f.MigrateToStep(35)
|
|
|
|
if th.IsMySQL() {
|
|
th.f.DB().Exec("alter table focalboard_category_boards add constraint unique_user_category_board UNIQUE(user_id, board_id);")
|
|
} else if th.IsPostgres() {
|
|
th.f.DB().Exec("ALTER TABLE focalboard_category_boards ADD CONSTRAINT unique_user_category_board UNIQUE(user_id, board_id);")
|
|
}
|
|
|
|
th.f.MigrateToStep(36)
|
|
|
|
var schema string
|
|
if th.IsMySQL() {
|
|
schema = "DATABASE()"
|
|
} else if th.IsPostgres() {
|
|
schema = "'public'"
|
|
}
|
|
|
|
var count int
|
|
query := "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS " +
|
|
"WHERE constraint_schema = " + schema + " " +
|
|
"AND constraint_name = 'unique_user_category_board' " +
|
|
"AND constraint_type = 'UNIQUE' " +
|
|
"AND table_name = 'focalboard_category_boards'"
|
|
th.f.DB().Get(&count, query)
|
|
require.Equal(t, 1, count)
|
|
})
|
|
}
|