Adds the main Property System Architecture components (#29644)

* Adds the main Property System Architecture components

This change adds the necessary migrations for the Property Groups,
Fields and Values tables to be created, the store layer and a Property
Service that can be used from the app layer.

* Update property field type to use user instead of person

* Update PropertyFields to allow for unique nondeleted fields and remove redundant indexes

* Update PropertyValues to allow for unique nondeleted fields and remove redundant indexes

* Use StringMap instead of the map[string]any on property fields

* Add i18n strings

* Revert "Use StringMap instead of the map[string]any on property fields"

This reverts commit e2735ab0f8589d2524d636419ca0cb144575c4d6.

* Cast JSON binary data to string and add todo note for StringMap use

* Add mocks to the retrylayer tests

* Cast JSON binary data to string in property value store

* Check for binary parameter instead of casting to string for JSON data

* Check property field type is one of the allowed ones

* Avoid reusing err variable to be explicit about the returned value

* Merge Property System Migrations into one file

* Adds NOT NULL to timestamps at the DB level

* Update stores to use tableSelectQuery instead of a slice var

* Update PropertyField model translations to be more explicit and avoid repetition

* Update PropertyValue model translations to be more explicit and avoid repetition

* Use ExecBuilder instead of ToSql&Exec

* Update property field errors to add context

* Ensure PerPage is greater than zero

* Update store errors to give more context

* Use ExecBuilder in the property stores where possible

* Add an on conflict suffix to the group register to avoid race conditions

* Remove badly used translation string

* Remove unused get in register group method

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Miguel de la Cruz
2025-01-13 12:41:44 +01:00
коммит произвёл GitHub
родитель d2b334e605
Коммит ecdce71fc4
35 изменённых файлов: 3793 добавлений и 0 удалений

Просмотреть файл

@@ -253,6 +253,8 @@ channels/db/migrations/mysql/000127_add_mfa_used_ts_to_users.down.sql
channels/db/migrations/mysql/000127_add_mfa_used_ts_to_users.up.sql
channels/db/migrations/mysql/000128_create_scheduled_posts.down.sql
channels/db/migrations/mysql/000128_create_scheduled_posts.up.sql
channels/db/migrations/mysql/000129_add_property_system_architecture.down.sql
channels/db/migrations/mysql/000129_add_property_system_architecture.up.sql
channels/db/migrations/postgres/000001_create_teams.down.sql
channels/db/migrations/postgres/000001_create_teams.up.sql
channels/db/migrations/postgres/000002_create_team_members.down.sql
@@ -507,3 +509,5 @@ channels/db/migrations/postgres/000127_add_mfa_used_ts_to_users.down.sql
channels/db/migrations/postgres/000127_add_mfa_used_ts_to_users.up.sql
channels/db/migrations/postgres/000128_create_scheduled_posts.down.sql
channels/db/migrations/postgres/000128_create_scheduled_posts.up.sql
channels/db/migrations/postgres/000129_add_property_system_architecture.down.sql
channels/db/migrations/postgres/000129_add_property_system_architecture.up.sql

Просмотреть файл

@@ -0,0 +1,3 @@
DROP TABLE IF EXISTS PropertyGroups;
DROP TABLE IF EXISTS PropertyFields;
DROP TABLE IF EXISTS PropertyValues;

Просмотреть файл

@@ -0,0 +1,47 @@
CREATE TABLE IF NOT EXISTS PropertyGroups (
ID varchar(26) PRIMARY KEY,
Name varchar(64) NOT NULL,
UNIQUE(Name)
);
CREATE TABLE IF NOT EXISTS PropertyFields (
ID varchar(26) PRIMARY KEY,
GroupID varchar(26) NOT NULL,
Name varchar(255) NOT NULL,
Type enum('text', 'select', 'multiselect', 'date', 'user', 'multiuser'),
Attrs json,
TargetID varchar(255),
TargetType varchar(255),
CreateAt bigint(20),
UpdateAt bigint(20),
DeleteAt bigint(20),
UNIQUE(GroupID, TargetID, Name, DeleteAt)
);
CREATE TABLE IF NOT EXISTS PropertyValues (
ID varchar(26) PRIMARY KEY,
TargetID varchar(255) NOT NULL,
TargetType varchar(255) NOT NULL,
GroupID varchar(26) NOT NULL,
FieldID varchar(26) NOT NULL,
Value json,
CreateAt bigint(20),
UpdateAt bigint(20),
DeleteAt bigint(20),
UNIQUE(GroupID, TargetID, FieldID, DeleteAt)
);
SET @preparedStatement = (SELECT IF(
(
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
WHERE table_name = 'PropertyValues'
AND table_schema = DATABASE()
AND index_name = 'idx_propertyvalues_targetid_groupid'
) > 0,
'SELECT 1',
'CREATE INDEX idx_propertyvalues_targetid_groupid ON PropertyValues (TargetID, GroupID);'
));
PREPARE createIndexIfNotExists FROM @preparedStatement;
EXECUTE createIndexIfNotExists;
DEALLOCATE PREPARE createIndexIfNotExists;

Просмотреть файл

@@ -0,0 +1,3 @@
DROP TABLE IF EXISTS PropertyGroups;
DROP TABLE IF EXISTS PropertyFields;
DROP TABLE IF EXISTS PropertyValues;

Просмотреть файл

@@ -0,0 +1,55 @@
CREATE TABLE IF NOT EXISTS PropertyGroups (
ID varchar(26) PRIMARY KEY,
Name varchar(64) NOT NULL,
UNIQUE(Name)
);
DO
$$
BEGIN
IF NOT EXISTS (SELECT * FROM pg_type typ
INNER JOIN pg_namespace nsp ON nsp.oid = typ.typnamespace
WHERE nsp.nspname = current_schema()
AND typ.typname = 'property_field_type') THEN
CREATE TYPE property_field_type AS ENUM (
'text',
'select',
'multiselect',
'date',
'user',
'multiuser'
);
END IF;
END;
$$
LANGUAGE plpgsql;
CREATE TABLE IF NOT EXISTS PropertyFields (
ID varchar(26) PRIMARY KEY,
GroupID varchar(26) NOT NULL,
Name varchar(255) NOT NULL,
Type property_field_type,
Attrs jsonb,
TargetID varchar(255),
TargetType varchar(255),
CreateAt bigint NOT NULL,
UpdateAt bigint NOT NULL,
DeleteAt bigint NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_propertyfields_unique ON PropertyFields (GroupID, TargetID, Name) WHERE DeleteAt = 0;
CREATE TABLE IF NOT EXISTS PropertyValues (
ID varchar(26) PRIMARY KEY,
TargetID varchar(255) NOT NULL,
TargetType varchar(255) NOT NULL,
GroupID varchar(26) NOT NULL,
FieldID varchar(26) NOT NULL,
Value jsonb NOT NULL,
CreateAt bigint NOT NULL,
UpdateAt bigint NOT NULL,
DeleteAt bigint NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_propertyvalues_unique ON PropertyValues (GroupID, TargetID, FieldID) WHERE DeleteAt = 0;
CREATE INDEX IF NOT EXISTS idx_propertyvalues_targetid_groupid ON PropertyValues (TargetID, GroupID);