[MM-64437] Hotfix on attribute view creation error (#31225)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c9006b55e1
Коммит
1cf2f08108
@@ -269,6 +269,8 @@ channels/db/migrations/mysql/000135_sidebarchannels_categoryid.down.sql
|
|||||||
channels/db/migrations/mysql/000135_sidebarchannels_categoryid.up.sql
|
channels/db/migrations/mysql/000135_sidebarchannels_categoryid.up.sql
|
||||||
channels/db/migrations/mysql/000136_create_attribute_view.down.sql
|
channels/db/migrations/mysql/000136_create_attribute_view.down.sql
|
||||||
channels/db/migrations/mysql/000136_create_attribute_view.up.sql
|
channels/db/migrations/mysql/000136_create_attribute_view.up.sql
|
||||||
|
channels/db/migrations/mysql/000137_update_attribute_view.down.sql
|
||||||
|
channels/db/migrations/mysql/000137_update_attribute_view.up.sql
|
||||||
channels/db/migrations/postgres/000001_create_teams.down.sql
|
channels/db/migrations/postgres/000001_create_teams.down.sql
|
||||||
channels/db/migrations/postgres/000001_create_teams.up.sql
|
channels/db/migrations/postgres/000001_create_teams.up.sql
|
||||||
channels/db/migrations/postgres/000002_create_team_members.down.sql
|
channels/db/migrations/postgres/000002_create_team_members.down.sql
|
||||||
@@ -539,3 +541,5 @@ channels/db/migrations/postgres/000135_sidebarchannels_categoryid.down.sql
|
|||||||
channels/db/migrations/postgres/000135_sidebarchannels_categoryid.up.sql
|
channels/db/migrations/postgres/000135_sidebarchannels_categoryid.up.sql
|
||||||
channels/db/migrations/postgres/000136_create_attribute_view.down.sql
|
channels/db/migrations/postgres/000136_create_attribute_view.down.sql
|
||||||
channels/db/migrations/postgres/000136_create_attribute_view.up.sql
|
channels/db/migrations/postgres/000136_create_attribute_view.up.sql
|
||||||
|
channels/db/migrations/postgres/000137_update_attribute_view.down.sql
|
||||||
|
channels/db/migrations/postgres/000137_update_attribute_view.up.sql
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
-- This is no-op migration for MySQL.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
-- This is no-op migration for MySQL.
|
||||||
@@ -1,37 +1,2 @@
|
|||||||
CREATE OR REPLACE PROCEDURE create_attribute_view()
|
-- This migration is converted to be no-op due to an error in the original migration.
|
||||||
LANGUAGE plpgsql
|
-- The new migration for this change is 000137_update_attribute_view.up.sql.
|
||||||
AS $$
|
|
||||||
BEGIN
|
|
||||||
EXECUTE '
|
|
||||||
CREATE MATERIALIZED VIEW IF NOT EXISTS AttributeView AS
|
|
||||||
SELECT
|
|
||||||
pv.GroupID,
|
|
||||||
pv.TargetID,
|
|
||||||
pv.TargetType,
|
|
||||||
jsonb_object_agg(
|
|
||||||
pf.Name,
|
|
||||||
CASE
|
|
||||||
WHEN pf.Type = ''select'' THEN (
|
|
||||||
SELECT to_jsonb(options.name)
|
|
||||||
FROM jsonb_to_recordset(pf.Attrs->''options'') AS options(id text, name text)
|
|
||||||
WHERE options.id = pv.Value #>> ''{}''
|
|
||||||
LIMIT 1
|
|
||||||
)
|
|
||||||
WHEN pf.Type = ''multiselect'' THEN (
|
|
||||||
SELECT jsonb_agg(option_names.name)
|
|
||||||
FROM jsonb_array_elements_text(pv.Value) AS option_id
|
|
||||||
JOIN jsonb_to_recordset(pf.Attrs->''options'') AS option_names(id text, name text)
|
|
||||||
ON option_id = option_names.id
|
|
||||||
)
|
|
||||||
ELSE pv.Value
|
|
||||||
END
|
|
||||||
) AS Attributes FROM PropertyValues pv
|
|
||||||
LEFT JOIN PropertyFields pf ON pf.ID = pv.FieldID
|
|
||||||
WHERE pv.DeleteAt = 0 OR pv.DeleteAt IS NULL
|
|
||||||
GROUP BY pv.GroupID, pv.TargetID, pv.TargetType
|
|
||||||
';
|
|
||||||
END;
|
|
||||||
$$;
|
|
||||||
|
|
||||||
call create_attribute_view();
|
|
||||||
DROP PROCEDURE create_attribute_view();
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
DROP MATERIALIZED VIEW IF EXISTS AttributeView;
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
DROP MATERIALIZED VIEW IF EXISTS AttributeView;
|
||||||
|
|
||||||
|
CREATE OR REPLACE PROCEDURE create_attribute_view()
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
EXECUTE '
|
||||||
|
CREATE MATERIALIZED VIEW IF NOT EXISTS AttributeView AS
|
||||||
|
SELECT
|
||||||
|
pv.GroupID,
|
||||||
|
pv.TargetID,
|
||||||
|
pv.TargetType,
|
||||||
|
jsonb_object_agg(
|
||||||
|
pf.Name,
|
||||||
|
CASE
|
||||||
|
WHEN pf.Type = ''select'' THEN (
|
||||||
|
SELECT to_jsonb(options.name)
|
||||||
|
FROM jsonb_to_recordset(pf.Attrs->''options'') AS options(id text, name text)
|
||||||
|
WHERE options.id = pv.Value #>> ''{}''
|
||||||
|
LIMIT 1
|
||||||
|
)
|
||||||
|
WHEN pf.Type = ''multiselect'' AND jsonb_typeof(pv.Value) = ''array'' THEN (
|
||||||
|
SELECT jsonb_agg(option_names.name)
|
||||||
|
FROM jsonb_array_elements_text(pv.Value) AS option_id
|
||||||
|
JOIN jsonb_to_recordset(pf.Attrs->''options'') AS option_names(id text, name text)
|
||||||
|
ON option_id = option_names.id
|
||||||
|
)
|
||||||
|
ELSE pv.Value
|
||||||
|
END
|
||||||
|
) AS Attributes FROM PropertyValues pv
|
||||||
|
LEFT JOIN PropertyFields pf ON pf.ID = pv.FieldID
|
||||||
|
WHERE (pv.DeleteAt = 0 OR pv.DeleteAt IS NULL) AND (pf.DeleteAt = 0 OR pf.DeleteAt IS NULL)
|
||||||
|
GROUP BY pv.GroupID, pv.TargetID, pv.TargetType
|
||||||
|
';
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
call create_attribute_view();
|
||||||
|
DROP PROCEDURE create_attribute_view();
|
||||||
Ссылка в новой задаче
Block a user