Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-04-06 15:08:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-04-06 15:08:07 +0300
commitb161512b300e70c1e786dd299867dad284e11019 (patch)
treed0537a6f97b8a117a1a7763c50dca18735b64aca /db
parenteb4b72630a9f479f33858fc9011e18666da3bbba (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20230228183644_add_partitioning_info_to_postgres_foreign_keys.rb90
-rw-r--r--db/schema_migrations/202302281836441
-rw-r--r--db/structure.sql12
3 files changed, 101 insertions, 2 deletions
diff --git a/db/migrate/20230228183644_add_partitioning_info_to_postgres_foreign_keys.rb b/db/migrate/20230228183644_add_partitioning_info_to_postgres_foreign_keys.rb
new file mode 100644
index 00000000000..5fe2a497077
--- /dev/null
+++ b/db/migrate/20230228183644_add_partitioning_info_to_postgres_foreign_keys.rb
@@ -0,0 +1,90 @@
+# frozen_string_literal: true
+
+class AddPartitioningInfoToPostgresForeignKeys < Gitlab::Database::Migration[2.1]
+ def up
+ execute <<~SQL
+ DROP VIEW IF EXISTS postgres_foreign_keys;
+ CREATE VIEW postgres_foreign_keys AS
+ SELECT pg_constraint.oid AS oid,
+ pg_constraint.conname AS name,
+ constrained_namespace.nspname::text || '.'::text ||
+ constrained_table.relname::text AS constrained_table_identifier,
+ referenced_namespace.nspname::text || '.'::text ||
+ referenced_table.relname::text AS referenced_table_identifier,
+ constrained_table.relname::text AS constrained_table_name,
+ referenced_table.relname::text AS referenced_table_name,
+ constrained_cols.constrained_columns,
+ referenced_cols.referenced_columns,
+ pg_constraint.confdeltype AS on_delete_action,
+ pg_constraint.confupdtype as on_update_action,
+ pg_constraint.coninhcount > 0 as is_inherited,
+ pg_constraint.convalidated as is_valid,
+ partitioned_parent_oids.parent_oid as parent_oid
+ FROM pg_constraint
+ INNER JOIN pg_class constrained_table ON constrained_table.oid = pg_constraint.conrelid
+ INNER JOIN pg_class referenced_table ON referenced_table.oid = pg_constraint.confrelid
+ INNER JOIN pg_namespace constrained_namespace ON constrained_table.relnamespace = constrained_namespace.oid
+ INNER JOIN pg_namespace referenced_namespace ON referenced_table.relnamespace = referenced_namespace.oid
+ CROSS JOIN LATERAL (
+ SELECT array_agg(pg_attribute.attname ORDER BY conkey.idx) -- must order here so that attributes are in correct order in array
+ FROM unnest(pg_constraint.conkey) WITH ORDINALITY conkey(attnum, idx)
+ INNER JOIN pg_attribute
+ ON pg_attribute.attnum = conkey.attnum AND pg_attribute.attrelid = constrained_table.oid
+ ) constrained_cols(constrained_columns)
+ CROSS JOIN LATERAL (
+ SELECT array_agg(pg_attribute.attname ORDER BY confkey.idx)
+ FROM unnest(pg_constraint.confkey) WITH ORDINALITY confkey(attnum, idx)
+ INNER JOIN pg_attribute
+ ON pg_attribute.attnum = confkey.attnum AND pg_attribute.attrelid = referenced_table.oid
+ ) referenced_cols(referenced_columns)
+ LEFT JOIN LATERAL (
+ SELECT refobjid as parent_oid
+ FROM pg_depend
+ WHERE objid = pg_constraint.oid
+ AND pg_depend.deptype = 'P'
+ AND refobjid IN (SELECT oid FROM pg_constraint WHERE contype = 'f')
+ LIMIT 1
+ ) partitioned_parent_oids(parent_oid) ON true
+ WHERE contype = 'f';
+ SQL
+
+ Gitlab::Database::PostgresForeignKey.reset_column_information
+ end
+
+ def down
+ execute <<~SQL
+ DROP VIEW IF EXISTS postgres_foreign_keys;
+ CREATE VIEW postgres_foreign_keys AS
+ SELECT
+ pg_constraint.oid AS oid,
+ pg_constraint.conname AS name,
+ constrained_namespace.nspname::text || '.'::text || constrained_table.relname::text AS constrained_table_identifier,
+ referenced_namespace.nspname::text || '.'::text || referenced_table.relname::text AS referenced_table_identifier,
+ constrained_table.relname::text AS constrained_table_name,
+ referenced_table.relname::text AS referenced_table_name,
+ constrained_cols.constrained_columns,
+ referenced_cols.referenced_columns,
+ pg_constraint.confdeltype AS on_delete_action,
+ pg_constraint.confupdtype as on_update_action,
+ pg_constraint.coninhcount > 0 as is_inherited
+ FROM pg_constraint
+ INNER JOIN pg_class constrained_table ON constrained_table.oid = pg_constraint.conrelid
+ INNER JOIN pg_class referenced_table ON referenced_table.oid = pg_constraint.confrelid
+ INNER JOIN pg_namespace constrained_namespace ON constrained_table.relnamespace = constrained_namespace.oid
+ INNER JOIN pg_namespace referenced_namespace ON referenced_table.relnamespace = referenced_namespace.oid
+ CROSS JOIN LATERAL (
+ SELECT array_agg(pg_attribute.attname ORDER BY conkey.idx) -- must order here so that attributes are in correct order in array
+ FROM unnest(pg_constraint.conkey) WITH ORDINALITY conkey(attnum, idx)
+ INNER JOIN pg_attribute ON pg_attribute.attnum = conkey.attnum AND pg_attribute.attrelid = constrained_table.oid
+ ) constrained_cols(constrained_columns)
+ CROSS JOIN LATERAL (
+ SELECT array_agg(pg_attribute.attname ORDER BY confkey.idx)
+ FROM unnest(pg_constraint.confkey) WITH ORDINALITY confkey(attnum, idx)
+ INNER JOIN pg_attribute ON pg_attribute.attnum = confkey.attnum AND pg_attribute.attrelid = referenced_table.oid
+ ) referenced_cols(referenced_columns)
+ WHERE contype = 'f';
+ SQL
+
+ Gitlab::Database::PostgresForeignKey.reset_column_information
+ end
+end
diff --git a/db/schema_migrations/20230228183644 b/db/schema_migrations/20230228183644
new file mode 100644
index 00000000000..5c6b755de76
--- /dev/null
+++ b/db/schema_migrations/20230228183644
@@ -0,0 +1 @@
+19a23286a0efab51ecad88ce224f1a9991796acce47c845530fdf1e65af9b3ad \ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index 6c71c7d17ce..bb42846943c 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -20243,8 +20243,10 @@ CREATE VIEW postgres_foreign_keys AS
referenced_cols.referenced_columns,
pg_constraint.confdeltype AS on_delete_action,
pg_constraint.confupdtype AS on_update_action,
- (pg_constraint.coninhcount > 0) AS is_inherited
- FROM ((((((pg_constraint
+ (pg_constraint.coninhcount > 0) AS is_inherited,
+ pg_constraint.convalidated AS is_valid,
+ partitioned_parent_oids.parent_oid
+ FROM (((((((pg_constraint
JOIN pg_class constrained_table ON ((constrained_table.oid = pg_constraint.conrelid)))
JOIN pg_class referenced_table ON ((referenced_table.oid = pg_constraint.confrelid)))
JOIN pg_namespace constrained_namespace ON ((constrained_table.relnamespace = constrained_namespace.oid)))
@@ -20255,6 +20257,12 @@ CREATE VIEW postgres_foreign_keys AS
CROSS JOIN LATERAL ( SELECT array_agg(pg_attribute.attname ORDER BY confkey.idx) AS array_agg
FROM (unnest(pg_constraint.confkey) WITH ORDINALITY confkey(attnum, idx)
JOIN pg_attribute ON (((pg_attribute.attnum = confkey.attnum) AND (pg_attribute.attrelid = referenced_table.oid))))) referenced_cols(referenced_columns))
+ LEFT JOIN LATERAL ( SELECT pg_depend.refobjid AS parent_oid
+ FROM pg_depend
+ WHERE ((pg_depend.objid = pg_constraint.oid) AND (pg_depend.deptype = 'P'::"char") AND (pg_depend.refobjid IN ( SELECT pg_constraint_1.oid
+ FROM pg_constraint pg_constraint_1
+ WHERE (pg_constraint_1.contype = 'f'::"char"))))
+ LIMIT 1) partitioned_parent_oids(parent_oid) ON (true))
WHERE (pg_constraint.contype = 'f'::"char");
CREATE VIEW postgres_index_bloat_estimates AS