From c82c37a36ec28f4fe44b67988968dd89adf92c97 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Mon, 16 Nov 2020 18:25:32 +0530 Subject: [PATCH] MM-28067: Optimize app server startup in tests (#16263) * MM-28067: Optimize app server startup in tests For every test, we would wipe out the database and then start the server again. This would run through all the migrations and create new rows in Systems and Roles table every time. As a result, this was consuming a lot of setup time for every test. We optimize this by preloading the DB with dummy data in the roles and systems table so that the server code just skips over those migrations. This is completely forward compatible and adding new migrations does not need to generate the sql files again. Only in case of schema changes to the roles or systems table, this would need to be done. It is unlikely the Systems table schema will get changed. The Roles table might change in future but it's a comparatively rare event. Given the reduction in CI runtime we are seeing, it's a worthy optimization. We also apply some more optimizations: - Coalesce multiple UpdateConfig calls into a single one. Each UpdateConfig call has to do a json marshal which would take precious CPU cycles. It's much more efficient to do everything in a single call. - Remove unnecessary debug.FreeOSMemory in reload config. This was an artifact from old days and is no longer required. Numbers: Results show a full **2 minutes** shaved off the test runtime. Earlier, tests would take around 16 minutes. Now they take 14 minutes. ```release-note NONE ``` * fix app package --- .circleci/config.yml | 2 +- api4/apitestlib.go | 30 +++++---- app/app_test.go | 2 +- app/config.go | 2 - app/helper_test.go | 13 ++++ app/permissions_migrations.go | 14 ++--- build/dotenv/test.env | 2 +- store/storetest/settings.go | 2 +- testlib/helper.go | 37 +++++++++++ testlib/store.go | 4 ++ testlib/testdata/mysql_migration_warmup.sql | 62 +++++++++++++++++++ .../testdata/postgres_migration_warmup.sql | 49 +++++++++++++++ 12 files changed, 190 insertions(+), 29 deletions(-) create mode 100644 testlib/testdata/mysql_migration_warmup.sql create mode 100644 testlib/testdata/postgres_migration_warmup.sql diff --git a/.circleci/config.yml b/.circleci/config.yml index d2791e3631..3edc8f0c04 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -432,7 +432,7 @@ workflows: - test: name: test-mysql dbdriver: mysql - dbsource: mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4,utf8 + dbsource: mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4,utf8&multiStatements=true requires: - check-app-layers - check-store-layers diff --git a/api4/apitestlib.go b/api4/apitestlib.go index 1aa5d3ada7..868ac5453b 100644 --- a/api4/apitestlib.go +++ b/api4/apitestlib.go @@ -130,30 +130,26 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent // Disable sniffing, otherwise elastic client fails to connect to docker node // More details: https://github.com/olivere/elastic/wiki/Sniffing *cfg.ElasticsearchSettings.Sniff = false - }) - prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress - th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" }) - if err := th.Server.Start(); err != nil { - panic(err) - } - th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = prevListenAddress }) - Init(th.Server, th.Server.AppOptions, th.App.Srv().Router) - InitLocal(th.Server, th.Server.AppOptions, th.App.Srv().LocalRouter) - web.New(th.Server, th.Server.AppOptions, th.App.Srv().Router) - wsapi.Init(th.App.Srv()) - th.App.DoAppMigrations() + *cfg.TeamSettings.EnableOpenServer = true - th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = true }) - - // Disable strict password requirements for test - th.App.UpdateConfig(func(cfg *model.Config) { + // Disable strict password requirements for test *cfg.PasswordSettings.MinimumLength = 5 *cfg.PasswordSettings.Lowercase = false *cfg.PasswordSettings.Uppercase = false *cfg.PasswordSettings.Symbol = false *cfg.PasswordSettings.Number = false + + *cfg.ServiceSettings.ListenAddress = ":0" }) + if err := th.Server.Start(); err != nil { + panic(err) + } + + Init(th.Server, th.Server.AppOptions, th.App.Srv().Router) + InitLocal(th.Server, th.Server.AppOptions, th.App.Srv().LocalRouter) + web.New(th.Server, th.Server.AppOptions, th.App.Srv().Router) + wsapi.Init(th.App.Srv()) if enterprise { th.App.Srv().SetLicense(model.NewTestLicense()) @@ -197,6 +193,7 @@ func SetupEnterprise(tb testing.TB) *TestHelper { dbStore := mainHelper.GetStore() dbStore.DropAllTables() dbStore.MarkSystemRanUnitTests() + mainHelper.PreloadMigrations() searchEngine := mainHelper.GetSearchEngine() th := setupTestHelper(dbStore, searchEngine, true, true, nil) th.InitLogin() @@ -215,6 +212,7 @@ func Setup(tb testing.TB) *TestHelper { dbStore := mainHelper.GetStore() dbStore.DropAllTables() dbStore.MarkSystemRanUnitTests() + mainHelper.PreloadMigrations() searchEngine := mainHelper.GetSearchEngine() th := setupTestHelper(dbStore, searchEngine, false, true, nil) th.InitLogin() diff --git a/app/app_test.go b/app/app_test.go index 5d2ed33e51..4c7e0509d3 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -373,7 +373,7 @@ func TestDoAdvancedPermissionsMigration(t *testing.T) { } func TestDoEmojisPermissionsMigration(t *testing.T) { - th := Setup(t) + th := SetupWithoutPreloadMigrations(t) defer th.TearDown() // Add a license and change the policy config. diff --git a/app/config.go b/app/config.go index a43027b23d..599a32039d 100644 --- a/app/config.go +++ b/app/config.go @@ -14,7 +14,6 @@ import ( "fmt" "net/http" "net/url" - "runtime/debug" "strconv" "time" @@ -60,7 +59,6 @@ func (a *App) UpdateConfig(f func(*model.Config)) { } func (s *Server) ReloadConfig() error { - debug.FreeOSMemory() if err := s.configStore.Load(); err != nil { return err } diff --git a/app/helper_test.go b/app/helper_test.go index 2dd48e1eb6..93027727e0 100644 --- a/app/helper_test.go +++ b/app/helper_test.go @@ -133,6 +133,7 @@ func SetupEnterprise(tb testing.TB) *TestHelper { dbStore := mainHelper.GetStore() dbStore.DropAllTables() dbStore.MarkSystemRanUnitTests() + mainHelper.PreloadMigrations() return setupTestHelper(dbStore, true, true, tb, nil) } @@ -144,6 +145,18 @@ func Setup(tb testing.TB) *TestHelper { dbStore := mainHelper.GetStore() dbStore.DropAllTables() dbStore.MarkSystemRanUnitTests() + mainHelper.PreloadMigrations() + + return setupTestHelper(dbStore, false, true, tb, nil) +} + +func SetupWithoutPreloadMigrations(tb testing.TB) *TestHelper { + if testing.Short() { + tb.SkipNow() + } + dbStore := mainHelper.GetStore() + dbStore.DropAllTables() + dbStore.MarkSystemRanUnitTests() return setupTestHelper(dbStore, false, true, tb, nil) } diff --git a/app/permissions_migrations.go b/app/permissions_migrations.go index a1b91b852e..822471eae9 100644 --- a/app/permissions_migrations.go +++ b/app/permissions_migrations.go @@ -155,16 +155,11 @@ func applyPermissionsMap(role *model.Role, roleMap map[string]map[string]bool, m return result } -func (a *App) doPermissionsMigration(key string, migrationMap permissionsMap) *model.AppError { +func (a *App) doPermissionsMigration(key string, migrationMap permissionsMap, roles []*model.Role) *model.AppError { if _, err := a.Srv().Store.System().GetByName(key); err == nil { return nil } - roles, err := a.GetAllRoles() - if err != nil { - return err - } - roleMap := make(map[string]map[string]bool) for _, role := range roles { roleMap[role.Name] = make(map[string]bool) @@ -543,12 +538,17 @@ func (a *App) DoPermissionsMigrations() error { {Key: model.MIGRATION_KEY_ADD_SYSTEM_ROLES_PERMISSIONS, Migration: a.getSystemRolesPermissionsMigration}, } + roles, err := a.GetAllRoles() + if err != nil { + return err + } + for _, migration := range PermissionsMigrations { migMap, err := migration.Migration() if err != nil { return err } - if err := a.doPermissionsMigration(migration.Key, migMap); err != nil { + if err := a.doPermissionsMigration(migration.Key, migMap, roles); err != nil { return err } } diff --git a/build/dotenv/test.env b/build/dotenv/test.env index e28c24ea04..244c797d95 100644 --- a/build/dotenv/test.env +++ b/build/dotenv/test.env @@ -1,4 +1,4 @@ -TEST_DATABASE_MYSQL_DSN=mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s +TEST_DATABASE_MYSQL_DSN=mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s&multiStatements=true TEST_DATABASE_POSTGRESQL_DSN=postgres://mmuser:mostest@postgres:5432/mattermost_test?sslmode=disable&connect_timeout=10 TEST_DATABASE_MYSQL_ROOT_PASSWD=mostest GOBIN=/mattermost/mattermost-server/bin diff --git a/store/storetest/settings.go b/store/storetest/settings.go index d7cd40b0f8..b257c4204e 100644 --- a/store/storetest/settings.go +++ b/store/storetest/settings.go @@ -21,7 +21,7 @@ import ( ) const ( - defaultMysqlDSN = "mmuser:mostest@tcp(localhost:3306)/mattermost_test?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s" + defaultMysqlDSN = "mmuser:mostest@tcp(localhost:3306)/mattermost_test?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s&multiStatements=true" defaultPostgresqlDSN = "postgres://mmuser:mostest@localhost:5432/mattermost_test?sslmode=disable&connect_timeout=10" defaultMysqlRootPWD = "mostest" ) diff --git a/testlib/helper.go b/testlib/helper.go index def3bb3147..8d8fd0f08b 100644 --- a/testlib/helper.go +++ b/testlib/helper.go @@ -6,6 +6,7 @@ package testlib import ( "flag" "fmt" + "io/ioutil" "log" "os" "testing" @@ -122,6 +123,42 @@ func (h *MainHelper) setupResources() { } } +// PreloadMigrations preloads the migrations and roles into the database +// so that they are not run again when the migrations happen every time +// the server is started. +// This change is forward-compatible with new migrations and only new migrations +// will get executed. +// Only if the schema of either roles or systems table changes, this will break. +// In that case, just update the migrations or comment this out for the time being. +// In the worst case, only an optimization is lost. +// +// Re-generate the files with: +// pg_dump -a -h localhost -U mmuser -d <> --no-comments --inserts -t roles -t systems +// mysqldump -u root -p <> --no-create-info --extended-insert=FALSE Systems Roles +// And keep only the permission related rows in the systems table output. +func (h *MainHelper) PreloadMigrations() { + var buf []byte + var err error + switch *h.Settings.DriverName { + case model.DATABASE_DRIVER_POSTGRES: + buf, err = ioutil.ReadFile("mattermost-server/testlib/testdata/postgres_migration_warmup.sql") + if err != nil { + panic(fmt.Errorf("cannot read file: %v", err)) + } + case model.DATABASE_DRIVER_MYSQL: + buf, err = ioutil.ReadFile("mattermost-server/testlib/testdata/mysql_migration_warmup.sql") + if err != nil { + panic(fmt.Errorf("cannot read file: %v", err)) + } + } + handle := h.SQLSupplier.GetMaster() + _, err = handle.Exec(string(buf)) + if err != nil { + mlog.Error("Error preloading migrations. Check if you have &multiStatements=true in your DSN if you are using MySQL. Or perhaps the schema changed? If yes, then update the warmup files accordingly.") + panic(err) + } +} + func (h *MainHelper) Close() error { if h.SQLSupplier != nil { h.SQLSupplier.Close() diff --git a/testlib/store.go b/testlib/store.go index 9f622d93d9..f80e4947d2 100644 --- a/testlib/store.go +++ b/testlib/store.go @@ -70,12 +70,16 @@ func GetMockStoreForSetupFunctions() *mocks.Store { teamStore := mocks.TeamStore{} + roleStore := mocks.RoleStore{} + roleStore.On("GetAll").Return([]*model.Role{}, nil) + mockStore.On("System").Return(&systemStore) mockStore.On("User").Return(&userStore) mockStore.On("Post").Return(&postStore) mockStore.On("Status").Return(&statusStore) mockStore.On("Channel").Return(&channelStore) mockStore.On("Team").Return(&teamStore) + mockStore.On("Role").Return(&roleStore) mockStore.On("Scheme").Return(&schemeStore) mockStore.On("Close").Return(nil) mockStore.On("DropAllTables").Return(nil) diff --git a/testlib/testdata/mysql_migration_warmup.sql b/testlib/testdata/mysql_migration_warmup.sql new file mode 100644 index 0000000000..9b7ff47e7e --- /dev/null +++ b/testlib/testdata/mysql_migration_warmup.sql @@ -0,0 +1,62 @@ +-- MySQL dump 10.13 Distrib 5.6.49, for Linux (x86_64) +-- +-- Host: localhost Database: db1ehbiiiratghukqhfuf91gzfuh +-- ------------------------------------------------------ +-- Server version 5.6.49 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Dumping data for table `Systems` +-- + +LOCK TABLES `Systems` WRITE; +/*!40000 ALTER TABLE `Systems` DISABLE KEYS */; +INSERT INTO `Systems` VALUES ('emoji_permissions_split', 'true'); +INSERT INTO `Systems` VALUES ('webhook_permissions_split', 'true'); +INSERT INTO `Systems` VALUES ('list_join_public_private_teams', 'true'); +INSERT INTO `Systems` VALUES ('remove_permanent_delete_user', 'true'); +INSERT INTO `Systems` VALUES ('add_bot_permissions', 'true'); +INSERT INTO `Systems` VALUES ('apply_channel_manage_delete_to_channel_user', 'true'); +INSERT INTO `Systems` VALUES ('remove_channel_manage_delete_from_team_user', 'true'); +INSERT INTO `Systems` VALUES ('view_members_new_permission', 'true'); +INSERT INTO `Systems` VALUES ('add_manage_guests_permissions', 'true'); +INSERT INTO `Systems` VALUES ('channel_moderations_permissions', 'true'); +INSERT INTO `Systems` VALUES ('add_use_group_mentions_permission', 'true'); +INSERT INTO `Systems` VALUES ('add_system_console_permissions', 'true'); +INSERT INTO `Systems` VALUES ('add_convert_channel_permissions', 'true'); +INSERT INTO `Systems` VALUES ('manage_shared_channel_permissions', 'true'); + + +/*!40000 ALTER TABLE `Systems` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `Roles` +-- + +LOCK TABLES `Roles` WRITE; +/*!40000 ALTER TABLE `Roles` DISABLE KEYS */; +INSERT INTO `Roles` VALUES ('3ndsqn4sbbyjxpzccrzmzejstw','team_guest','authentication.roles.team_guest.name','authentication.roles.team_guest.description',1605167829008,1605167829300,0,' view_team',1,1),('6jaz4y4nmjnxunkmogjf95fiha','system_user_manager','authentication.roles.system_user_manager.name','authentication.roles.system_user_manager.description',1605167829006,1605167829303,0,' sysconsole_read_user_management_channels manage_channel_roles join_public_teams manage_public_channel_properties sysconsole_read_user_management_groups manage_private_channel_members sysconsole_read_user_management_permissions convert_public_channel_to_private read_public_channel_groups read_jobs sysconsole_read_authentication manage_private_channel_properties manage_public_channel_members list_private_teams read_channel read_public_channel add_user_to_team join_private_teams list_public_teams sysconsole_write_user_management_channels delete_private_channel manage_team remove_user_from_team read_private_channel_groups sysconsole_read_user_management_teams view_team sysconsole_write_user_management_groups convert_private_channel_to_public sysconsole_write_user_management_teams delete_public_channel manage_team_roles',0,1),('6pahsh5hg7rpjfhz4f5c1wsbfw','team_admin','authentication.roles.team_admin.name','authentication.roles.team_admin.description',1605167829005,1605167829305,0,' delete_post read_public_channel_groups use_group_mentions manage_slash_commands read_private_channel_groups remove_reaction manage_others_incoming_webhooks manage_incoming_webhooks manage_outgoing_webhooks add_reaction create_post manage_private_channel_members remove_user_from_team manage_others_slash_commands manage_others_outgoing_webhooks manage_team_roles import_team delete_others_posts manage_public_channel_members use_channel_mentions manage_team manage_channel_roles convert_private_channel_to_public convert_public_channel_to_private',1,1),('c7oo8yeiojfu8xjyuyxn3fhxpc','team_post_all','authentication.roles.team_post_all.name','authentication.roles.team_post_all.description',1605167829009,1605167829308,0,' create_post use_group_mentions use_channel_mentions',0,1),('cmqctq1egt877y9ua9pdsknoiw','team_post_all_public','authentication.roles.team_post_all_public.name','authentication.roles.team_post_all_public.description',1605167829004,1605167829310,0,' use_group_mentions use_channel_mentions create_post_public',0,1),('hh56iy3patffuc3h76soondcga','channel_admin','authentication.roles.channel_admin.name','authentication.roles.channel_admin.description',1605167829007,1605167829312,0,' use_group_mentions manage_public_channel_members use_channel_mentions read_private_channel_groups remove_reaction manage_channel_roles create_post manage_private_channel_members read_public_channel_groups add_reaction',1,1),('hkcrew7wttb5fbuw3ime6g7nzc','system_read_only_admin','authentication.roles.system_read_only_admin.name','authentication.roles.system_read_only_admin.description',1605167829012,1605167829315,0,' sysconsole_read_experimental read_private_channel_groups sysconsole_read_user_management_teams sysconsole_read_user_management_users read_public_channel sysconsole_read_integrations sysconsole_read_about sysconsole_read_user_management_permissions read_jobs sysconsole_read_reporting sysconsole_read_user_management_channels read_public_channel_groups sysconsole_read_environment sysconsole_read_user_management_groups sysconsole_read_site read_other_users_teams read_channel sysconsole_read_plugins sysconsole_read_authentication list_private_teams list_public_teams view_team',0,1),('jg1f1xfh3bb73pua938orwg9ie','system_guest','authentication.roles.global_guest.name','authentication.roles.global_guest.description',1605167829015,1605167829317,0,' create_direct_channel create_group_channel',1,1),('k891n5tpd3n9peue79azejjocy','system_post_all_public','authentication.roles.system_post_all_public.name','authentication.roles.system_post_all_public.description',1605167829011,1605167829319,0,' use_group_mentions use_channel_mentions create_post_public',0,1),('kb6r9i58x7dxdb3srfohd66sse','system_admin','authentication.roles.global_admin.name','authentication.roles.global_admin.description',1605167829012,1605167829322,0,' create_private_channel sysconsole_read_plugins sysconsole_write_authentication delete_others_emojis list_public_teams manage_outgoing_webhooks create_bot sysconsole_write_user_management_users create_post_ephemeral sysconsole_read_site sysconsole_read_about view_team import_team remove_others_reactions get_public_link promote_guest edit_brand assign_system_admin_role sysconsole_write_user_management_groups sysconsole_read_environment read_other_users_teams read_user_access_token sysconsole_write_user_management_teams assign_bot manage_team sysconsole_read_authentication read_bots upload_file convert_public_channel_to_private create_direct_channel create_emojis sysconsole_read_user_management_groups sysconsole_write_reporting invite_user delete_public_channel manage_others_bots edit_others_posts list_private_teams list_users_without_team create_team edit_post sysconsole_write_compliance manage_system_wide_oauth sysconsole_read_compliance read_public_channel_groups sysconsole_write_site sysconsole_read_user_management_users join_private_teams manage_private_channel_properties view_members invite_guest edit_other_users manage_bots manage_incoming_webhooks join_public_channels create_post_public manage_others_slash_commands create_group_channel delete_emojis sysconsole_write_user_management_permissions revoke_user_access_token sysconsole_read_experimental manage_channel_roles add_reaction create_user_access_token manage_public_channel_properties sysconsole_read_user_management_channels remove_reaction sysconsole_read_reporting sysconsole_write_environment sysconsole_read_user_management_permissions manage_team_roles create_post read_jobs sysconsole_write_integrations use_channel_mentions convert_private_channel_to_public read_private_channel_groups sysconsole_write_experimental manage_slash_commands read_channel manage_oauth sysconsole_write_about manage_roles demote_to_guest join_public_teams use_slash_commands manage_jobs sysconsole_write_user_management_channels use_group_mentions add_user_to_team manage_public_channel_members manage_others_outgoing_webhooks read_others_bots delete_others_posts manage_private_channel_members create_public_channel sysconsole_read_user_management_teams remove_user_from_team manage_shared_channels manage_system delete_post sysconsole_read_integrations list_team_channels delete_private_channel sysconsole_write_plugins manage_others_incoming_webhooks read_public_channel',1,1),('km7kijhdtjbajquwu36uqneyoc','system_post_all','authentication.roles.system_post_all.name','authentication.roles.system_post_all.description',1605167829002,1605167829324,0,' use_channel_mentions use_group_mentions create_post',0,1),('qo7e17c1m3rezyjqx5iq9dpmxe','system_manager','authentication.roles.system_manager.name','authentication.roles.system_manager.description',1605167829004,1605167829326,0,' remove_user_from_team manage_private_channel_members sysconsole_read_site edit_brand sysconsole_read_user_management_permissions manage_private_channel_properties delete_public_channel sysconsole_read_user_management_teams read_public_channel sysconsole_write_user_management_channels list_public_teams sysconsole_read_reporting join_private_teams manage_team_roles sysconsole_read_about read_private_channel_groups manage_public_channel_properties list_private_teams view_team sysconsole_write_user_management_permissions convert_private_channel_to_public sysconsole_read_authentication read_channel sysconsole_read_plugins read_public_channel_groups convert_public_channel_to_private sysconsole_write_integrations sysconsole_write_environment manage_public_channel_members manage_team add_user_to_team manage_channel_roles sysconsole_write_site sysconsole_read_user_management_channels sysconsole_read_user_management_groups manage_jobs read_jobs sysconsole_read_environment sysconsole_write_user_management_groups sysconsole_write_user_management_teams delete_private_channel sysconsole_read_integrations join_public_teams',0,1),('rkr97ikkh7fixy86qsoo5rqm4c','system_user_access_token','authentication.roles.system_user_access_token.name','authentication.roles.system_user_access_token.description',1605167829003,1605167829328,0,' revoke_user_access_token create_user_access_token read_user_access_token',0,1),('rxzdk5irm7rcffcfej9e33kqeo','team_user','authentication.roles.team_user.name','authentication.roles.team_user.description',1605167829008,1605167829330,0,' view_team create_public_channel create_private_channel invite_user add_user_to_team list_team_channels join_public_channels read_public_channel',1,1),('x768jnyzw3rkfx7xb66ehcac6o','channel_user','authentication.roles.channel_user.name','authentication.roles.channel_user.description',1605167829014,1605167829332,0,' read_private_channel_groups use_slash_commands add_reaction edit_post use_channel_mentions manage_private_channel_properties create_post manage_public_channel_members delete_private_channel delete_post manage_public_channel_properties read_channel get_public_link upload_file use_group_mentions remove_reaction delete_public_channel read_public_channel_groups manage_private_channel_members',1,1),('ynn8aynsn7n1trtbuq6p4cyzhe','channel_guest','authentication.roles.channel_guest.name','authentication.roles.channel_guest.description',1605167829001,1605167829333,0,' read_channel add_reaction remove_reaction upload_file edit_post create_post use_channel_mentions use_slash_commands',1,1),('zzehkfnp67bg5g1owh6eptdcxc','system_user','authentication.roles.global_user.name','authentication.roles.global_user.description',1605167829010,1605167829334,0,' list_public_teams join_public_teams create_direct_channel create_group_channel view_members create_team create_emojis delete_emojis',1,1); +/*!40000 ALTER TABLE `Roles` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2020-11-12 8:01:35 diff --git a/testlib/testdata/postgres_migration_warmup.sql b/testlib/testdata/postgres_migration_warmup.sql new file mode 100644 index 0000000000..08b0ab693f --- /dev/null +++ b/testlib/testdata/postgres_migration_warmup.sql @@ -0,0 +1,49 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 11.7 (Ubuntu 11.7-2.pgdg19.10+1) +-- Dumped by pg_dump version 11.7 (Ubuntu 11.7-2.pgdg19.10+1) + +-- +-- Data for Name: roles; Type: TABLE DATA; Schema: public; Owner: mmuser +-- +INSERT INTO public.roles VALUES ('6tt4bj3iztgw7yfe8y97zyoo7o', 'system_post_all', 'authentication.roles.system_post_all.name', 'authentication.roles.system_post_all.description', 1605163387743, 1605163387988, 0, ' create_post use_group_mentions use_channel_mentions', false, true); +INSERT INTO public.roles VALUES ('gkegg9mqi3rgbm9u444mnxkmbc', 'team_post_all_public', 'authentication.roles.team_post_all_public.name', 'authentication.roles.team_post_all_public.description', 1605163387738, 1605163387977, 0, ' use_group_mentions create_post_public use_channel_mentions', false, true); +INSERT INTO public.roles VALUES ('peooyqpsq7g5bfnfo45zb1jiro', 'system_guest', 'authentication.roles.global_guest.name', 'authentication.roles.global_guest.description', 1605163387739, 1605163387978, 0, ' create_direct_channel create_group_channel', true, true); +INSERT INTO public.roles VALUES ('wxat9mo53tg79xdzn55kdq148w', 'channel_admin', 'authentication.roles.channel_admin.name', 'authentication.roles.channel_admin.description', 1605163387741, 1605163387981, 0, ' manage_public_channel_members use_group_mentions add_reaction read_public_channel_groups create_post read_private_channel_groups manage_private_channel_members use_channel_mentions remove_reaction manage_channel_roles', true, true); +INSERT INTO public.roles VALUES ('tkioqq1sgtribqgjbzwop1846c', 'system_read_only_admin', 'authentication.roles.system_read_only_admin.name', 'authentication.roles.system_read_only_admin.description', 1605163387745, 1605163387990, 0, ' list_private_teams sysconsole_read_user_management_users sysconsole_read_experimental read_other_users_teams sysconsole_read_environment sysconsole_read_user_management_channels read_public_channel sysconsole_read_user_management_permissions read_jobs read_public_channel_groups sysconsole_read_integrations list_public_teams sysconsole_read_user_management_groups sysconsole_read_about sysconsole_read_reporting sysconsole_read_site read_private_channel_groups read_channel sysconsole_read_authentication view_team sysconsole_read_plugins sysconsole_read_user_management_teams', false, true); +INSERT INTO public.roles VALUES ('mrejpofuoffiiynqcsi98es9ya', 'channel_guest', 'authentication.roles.channel_guest.name', 'authentication.roles.channel_guest.description', 1605163387746, 1605163387991, 0, ' create_post use_channel_mentions use_slash_commands read_channel add_reaction remove_reaction upload_file edit_post', true, true); +INSERT INTO public.roles VALUES ('96whs8mg73dszp7cz4u7sdbd7c', 'team_guest', 'authentication.roles.team_guest.name', 'authentication.roles.team_guest.description', 1605163387741, 1605163387982, 0, ' view_team', true, true); +INSERT INTO public.roles VALUES ('13kpq8iaqffmdf9qkrfqmpby9h', 'team_admin', 'authentication.roles.team_admin.name', 'authentication.roles.team_admin.description', 1605163387742, 1605163387983, 0, ' import_team convert_private_channel_to_public read_private_channel_groups manage_team convert_public_channel_to_private manage_channel_roles use_group_mentions manage_private_channel_members remove_reaction manage_others_outgoing_webhooks delete_others_posts manage_incoming_webhooks remove_user_from_team add_reaction manage_outgoing_webhooks manage_slash_commands manage_public_channel_members delete_post manage_others_slash_commands use_channel_mentions manage_team_roles create_post read_public_channel_groups manage_others_incoming_webhooks', true, true); +INSERT INTO public.roles VALUES ('7ta1wfbacjy3zxid54n3cqjzqw', 'system_post_all_public', 'authentication.roles.system_post_all_public.name', 'authentication.roles.system_post_all_public.description', 1605163387742, 1605163387985, 0, ' use_group_mentions create_post_public use_channel_mentions', false, true); +INSERT INTO public.roles VALUES ('rfc1w7z71pnzurkhpb1jgrbmdh', 'team_user', 'authentication.roles.team_user.name', 'authentication.roles.team_user.description', 1605163387747, 1605163387992, 0, ' list_team_channels join_public_channels read_public_channel view_team create_public_channel create_private_channel invite_user add_user_to_team', true, true); +INSERT INTO public.roles VALUES ('nh5i9ik1u78hdcny9usdoixkuo', 'channel_user', 'authentication.roles.channel_user.name', 'authentication.roles.channel_user.description', 1605163387735, 1605163387974, 0, ' manage_private_channel_members manage_private_channel_properties get_public_link manage_public_channel_properties use_slash_commands remove_reaction create_post add_reaction delete_post use_channel_mentions edit_post delete_private_channel upload_file delete_public_channel read_public_channel_groups manage_public_channel_members read_private_channel_groups use_group_mentions read_channel', true, true); +INSERT INTO public.roles VALUES ('tj3atgnwjfrt7emz8pgqmh5z4c', 'team_post_all', 'authentication.roles.team_post_all.name', 'authentication.roles.team_post_all.description', 1605163387737, 1605163387975, 0, ' create_post use_channel_mentions use_group_mentions', false, true); +INSERT INTO public.roles VALUES ('xf95ytghtjfsfd543dum68uzua', 'system_user_access_token', 'authentication.roles.system_user_access_token.name', 'authentication.roles.system_user_access_token.description', 1605163387743, 1605163387986, 0, ' revoke_user_access_token create_user_access_token read_user_access_token', false, true); +INSERT INTO public.roles VALUES ('hm1bxei8b3d68e4j95tqnndppw', 'system_manager', 'authentication.roles.system_manager.name', 'authentication.roles.system_manager.description', 1605163387740, 1605163387980, 0, ' sysconsole_write_user_management_groups sysconsole_read_user_management_teams read_jobs manage_private_channel_members convert_private_channel_to_public read_public_channel sysconsole_write_user_management_permissions sysconsole_write_environment manage_channel_roles sysconsole_write_user_management_channels manage_public_channel_properties read_private_channel_groups add_user_to_team sysconsole_read_about manage_team_roles view_team edit_brand sysconsole_write_user_management_teams join_private_teams manage_team sysconsole_read_site sysconsole_read_user_management_permissions sysconsole_read_reporting list_private_teams manage_jobs sysconsole_write_site read_public_channel_groups list_public_teams delete_public_channel sysconsole_read_environment sysconsole_read_authentication sysconsole_read_user_management_groups sysconsole_read_plugins delete_private_channel sysconsole_write_integrations sysconsole_read_user_management_channels convert_public_channel_to_private manage_public_channel_members read_channel manage_private_channel_properties remove_user_from_team sysconsole_read_integrations join_public_teams', false, true); +INSERT INTO public.roles VALUES ('f9drbz6cyjdmb8jof6smiqya7h', 'system_user_manager', 'authentication.roles.system_user_manager.name', 'authentication.roles.system_user_manager.description', 1605163387744, 1605163387989, 0, ' add_user_to_team manage_private_channel_properties sysconsole_read_user_management_groups read_public_channel convert_public_channel_to_private read_public_channel_groups read_jobs read_private_channel_groups list_private_teams manage_public_channel_properties join_private_teams sysconsole_read_user_management_permissions manage_public_channel_members read_channel sysconsole_read_user_management_teams delete_private_channel sysconsole_read_user_management_channels list_public_teams manage_private_channel_members join_public_teams manage_team remove_user_from_team sysconsole_write_user_management_channels sysconsole_write_user_management_groups sysconsole_write_user_management_teams convert_private_channel_to_public view_team delete_public_channel manage_channel_roles manage_team_roles sysconsole_read_authentication', false, true); +INSERT INTO public.roles VALUES ('d54xjt4sat8h7dqwu6i35jocuy', 'system_user', 'authentication.roles.global_user.name', 'authentication.roles.global_user.description', 1605163387739, 1605163387993, 0, ' list_public_teams join_public_teams create_direct_channel create_group_channel view_members create_team create_emojis delete_emojis', true, true); +INSERT INTO public.roles VALUES ('ha8u9qxwx3dm8mnbq8sfi7ugdc', 'system_admin', 'authentication.roles.global_admin.name', 'authentication.roles.global_admin.description', 1605163387745, 1605163387995, 0, ' sysconsole_read_site manage_jobs sysconsole_write_user_management_channels read_public_channel_groups sysconsole_read_user_management_permissions sysconsole_read_environment manage_others_outgoing_webhooks manage_outgoing_webhooks sysconsole_write_plugins sysconsole_write_user_management_teams list_private_teams import_team read_other_users_teams create_post_ephemeral read_user_access_token read_public_channel create_team get_public_link create_emojis delete_post manage_public_channel_properties delete_others_posts read_jobs manage_others_incoming_webhooks create_public_channel use_slash_commands sysconsole_read_experimental invite_user sysconsole_write_site manage_others_slash_commands list_public_teams assign_bot read_channel convert_public_channel_to_private sysconsole_write_user_management_permissions read_private_channel_groups manage_channel_roles edit_post create_user_access_token sysconsole_read_user_management_users edit_brand sysconsole_read_about list_users_without_team read_bots manage_private_channel_members create_group_channel delete_others_emojis manage_team sysconsole_write_user_management_users upload_file create_post manage_slash_commands sysconsole_write_about list_team_channels create_private_channel sysconsole_write_environment read_others_bots sysconsole_write_authentication manage_bots delete_private_channel join_public_teams manage_shared_channels create_post_public use_channel_mentions edit_other_users manage_incoming_webhooks join_private_teams sysconsole_write_compliance manage_system manage_others_bots sysconsole_read_user_management_groups view_team sysconsole_read_compliance add_user_to_team sysconsole_read_integrations sysconsole_write_user_management_groups sysconsole_write_experimental manage_team_roles join_public_channels manage_private_channel_properties manage_roles promote_guest invite_guest convert_private_channel_to_public sysconsole_write_reporting assign_system_admin_role revoke_user_access_token remove_user_from_team sysconsole_read_user_management_channels sysconsole_read_plugins remove_reaction add_reaction delete_public_channel view_members edit_others_posts sysconsole_write_integrations sysconsole_read_user_management_teams delete_emojis sysconsole_read_authentication create_direct_channel create_bot sysconsole_read_reporting use_group_mentions demote_to_guest remove_others_reactions manage_oauth manage_system_wide_oauth manage_public_channel_members', true, true); + +-- +-- Data for Name: systems; Type: TABLE DATA; Schema: public; Owner: mmuser +-- +INSERT INTO public.systems VALUES ('emoji_permissions_split', 'true'); +INSERT INTO public.systems VALUES ('webhook_permissions_split', 'true'); +INSERT INTO public.systems VALUES ('list_join_public_private_teams', 'true'); +INSERT INTO public.systems VALUES ('remove_permanent_delete_user', 'true'); +INSERT INTO public.systems VALUES ('add_bot_permissions', 'true'); +INSERT INTO public.systems VALUES ('apply_channel_manage_delete_to_channel_user', 'true'); +INSERT INTO public.systems VALUES ('remove_channel_manage_delete_from_team_user', 'true'); +INSERT INTO public.systems VALUES ('view_members_new_permission', 'true'); +INSERT INTO public.systems VALUES ('add_manage_guests_permissions', 'true'); +INSERT INTO public.systems VALUES ('channel_moderations_permissions', 'true'); +INSERT INTO public.systems VALUES ('add_use_group_mentions_permission', 'true'); +INSERT INTO public.systems VALUES ('add_system_console_permissions', 'true'); +INSERT INTO public.systems VALUES ('add_convert_channel_permissions', 'true'); +INSERT INTO public.systems VALUES ('manage_shared_channel_permissions', 'true'); + +-- +-- PostgreSQL database dump complete +--