mattermost/server/channels/store/sqlstore/schema_dump_test.go
Elias Nahum 1022cd44c0
Some checks failed
API / build (push) Has been cancelled
Server CI / Compute Go Version (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / test (push) Has been cancelled
Web App CI / build (push) Has been cancelled
Server CI / Check mocks (push) Has been cancelled
Server CI / Check go mod tidy (push) Has been cancelled
Server CI / check-style (push) Has been cancelled
Server CI / Check serialization methods for hot structs (push) Has been cancelled
Server CI / Vet API (push) Has been cancelled
Server CI / Check migration files (push) Has been cancelled
Server CI / Generate email templates (push) Has been cancelled
Server CI / Check store layers (push) Has been cancelled
Server CI / Check mmctl docs (push) Has been cancelled
Server CI / Postgres with binary parameters (push) Has been cancelled
Server CI / Postgres (push) Has been cancelled
Server CI / Postgres (FIPS) (push) Has been cancelled
Server CI / Generate Test Coverage (push) Has been cancelled
Server CI / Run mmctl tests (push) Has been cancelled
Server CI / Run mmctl tests (FIPS) (push) Has been cancelled
Server CI / Build mattermost server app (push) Has been cancelled
MM-65756 Database Migrations, Indexes and Methods for Auto-Translation (#34047)
* AutoTranslate config settings

* comment out Agents provider

* Add auto translate timeout config validation

* i18n messages for autotranslation config validation

* fix test

* validate url for libreTranslate

* Feedback review

* Admin Console UI for Auto-Translation

* fix admin console conditional section display

* i18n

* removed unintentional change

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* update admin.general.localization.autoTranslateProviderDescription newline

* fix lint

* Fix types

* UX feedback review

* fix typo in i18n

* Fix AutoTranslation feature flag

* feedback review

* Fix test default values

* feedback review

* re-add isHidden property to feature discovery

* Database Migrations, Indexes and Methods for Auto-Translation

* i18n

* fix retrylayer and storetest

* Fix search query

* fix lint

* remove the request.CTX and modify Translation model

* fix lint and external url

* Add settings to playwright

* Add empty as a valid value for the Provider

* Update jsonb queries

* Fix queries and add model methods

* fix go lint

* go lint fix 2

* fix db migrations

* feedback review + store cache

* increase migration number

* cleanup autotranslation store cache

* use NULL as objectType for posts

* fix bad merge

* fix tests

* add missing i18n

* Switch prop bags column to boolean

* fix lint

* fix tests

* Remove database search

* use Builder methods

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: BenCookie95 <benkcooke@gmail.com>
2025-11-22 09:32:01 +08:00

117 lines
5.1 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package sqlstore
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
)
func TestGetSchemaDefinition(t *testing.T) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
t.Run("PostgreSQL", func(t *testing.T) {
if ss.(*SqlStore).DriverName() != model.DatabaseDriverPostgres {
t.Skip("Skipping test as database is not PostgreSQL")
}
schemaInfo, err := ss.GetSchemaDefinition()
require.NoError(t, err)
require.NotNil(t, schemaInfo)
// Verify database encoding is captured
assert.Equal(t, "UTF8", schemaInfo.DatabaseEncoding, "Database encoding should be captured")
// Verify schema structure
assert.NotEmpty(t, schemaInfo.Tables)
// Verify that columns are not duplicated
for _, table := range schemaInfo.Tables {
columnNames := make(map[string]bool)
for _, column := range table.Columns {
// Assert that this column name hasn't been seen before
assert.False(t, columnNames[column.Name], "Column %s in table %s is duplicated", column.Name, table.Name)
columnNames[column.Name] = true
}
}
// Verify that common tables are present
tableNames := make([]string, 0, len(schemaInfo.Tables))
for _, table := range schemaInfo.Tables {
tableNames = append(tableNames, table.Name)
}
// Verify some core tables
expectedTables := []string{"users", "channels", "teams", "posts"}
assert.Subset(t, tableNames, expectedTables)
// Verify table structure
for _, table := range schemaInfo.Tables {
if table.Name == "users" {
// Check user table has key columns
columnNames := make([]string, 0, len(table.Columns))
for _, column := range table.Columns {
columnNames = append(columnNames, column.Name)
}
expectedColumns := []string{"id", "username", "email"}
assert.Subset(t, columnNames, expectedColumns)
break
}
}
// Verify indexes are present for tables
for _, table := range schemaInfo.Tables {
if table.Name == "channels" {
// Check that indexes are present
assert.NotEmpty(t, table.Indexes, "channels table should have indexes")
assert.Equal(t, 12, len(table.Indexes), "channels table should have 12 indexes")
// Expected index definitions
expectedIndexDefs := map[string]string{
"idx_channels_delete_at": "CREATE INDEX idx_channels_delete_at ON public.channels USING btree (deleteat)",
"idx_channels_create_at": "CREATE INDEX idx_channels_create_at ON public.channels USING btree (createat)",
"channels_pkey": "CREATE UNIQUE INDEX channels_pkey ON public.channels USING btree (id)",
"channels_name_teamid_key": "CREATE UNIQUE INDEX channels_name_teamid_key ON public.channels USING btree (name, teamid)",
"idx_channels_displayname_lower": "CREATE INDEX idx_channels_displayname_lower ON public.channels USING btree (lower((displayname)::text))",
"idx_channels_name_lower": "CREATE INDEX idx_channels_name_lower ON public.channels USING btree (lower((name)::text))",
"idx_channels_update_at": "CREATE INDEX idx_channels_update_at ON public.channels USING btree (updateat)",
"idx_channel_search_txt": "CREATE INDEX idx_channel_search_txt ON public.channels USING gin (to_tsvector('english'::regconfig, (((((name)::text || ' '::text) || (displayname)::text) || ' '::text) || (purpose)::text)))",
"idx_channels_scheme_id": "CREATE INDEX idx_channels_scheme_id ON public.channels USING btree (schemeid)",
"idx_channels_team_id_display_name": "CREATE INDEX idx_channels_team_id_display_name ON public.channels USING btree (teamid, displayname)",
"idx_channels_team_id_type": "CREATE INDEX idx_channels_team_id_type ON public.channels USING btree (teamid, type)",
"idx_channels_autotranslation_enabled": "CREATE INDEX idx_channels_autotranslation_enabled ON public.channels USING btree (id) WHERE (autotranslation = true)",
}
// Verify all expected indexes are present with correct definitions
foundIndexes := make(map[string]bool)
for _, index := range table.Indexes {
foundIndexes[index.Name] = true
// Verify definition is not empty
assert.NotEmpty(t, index.Definition, "Index %s should have a definition", index.Name)
// Check if this is an expected index and verify definition
expectedDef, ok := expectedIndexDefs[index.Name]
require.Truef(t, ok, "Unexpected definition found: %s", index.Name)
assert.Equal(t, expectedDef, index.Definition, "Index %s has incorrect definition", index.Name)
}
// Verify all expected indexes were found
for expectedName := range expectedIndexDefs {
assert.True(t, foundIndexes[expectedName], "Expected index %s not found", expectedName)
}
break
}
}
})
})
}