Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pg_constraint oid duplication #8166

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion edb/buildmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# The merge conflict there is a nice reminder that you probably need
# to write a patch in edb/pgsql/patches.py, and then you should preserve
# the old value.
EDGEDB_CATALOG_VERSION = 2024_12_17_00_00
EDGEDB_CATALOG_VERSION = 2024_01_02_00_00
EDGEDB_MAJOR_VERSION = 7


Expand Down
18 changes: 14 additions & 4 deletions edb/pgsql/metaschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6389,12 +6389,14 @@ def make_wrapper_view(name: str) -> trampoline.VersionedView:
name=('edgedbsql', 'uuid_to_oid'),
args=(
('id', 'uuid'),
# extra is two extra bits to throw into the oid, for now
('extra', 'int4', '0'),
),
returns=('oid',),
volatility='immutable',
text="""
SELECT (
('x' || substring(id::text, 2, 7))::bit(28)::bigint
('x' || substring(id::text, 2, 7))::bit(28)::bigint*4 + extra
+ 40000)::oid;
"""
)
Expand Down Expand Up @@ -7194,7 +7196,9 @@ def make_wrapper_view(name: str) -> trampoline.VersionedView:

-- foreign keys for object tables
SELECT
edgedbsql_VER.uuid_to_oid(sl.id) as oid,
-- uuid_to_oid needs "extra" arg to disambiguate from the link table
-- keys below
edgedbsql_VER.uuid_to_oid(sl.id, 0) as oid,
vt.table_name || '_fk_' || sl.name AS conname,
edgedbsql_VER.uuid_to_oid(vt.module_id) AS connamespace,
'f'::"char" AS contype,
Expand Down Expand Up @@ -7240,7 +7244,9 @@ def make_wrapper_view(name: str) -> trampoline.VersionedView:
-- - single link with link properties (source & target),
-- these constraints do not actually exist, so we emulate it entierly
SELECT
edgedbsql_VER.uuid_to_oid(sp.id) AS oid,
-- uuid_to_oid needs "extra" arg to disambiguate from other
-- constraints using this pointer
edgedbsql_VER.uuid_to_oid(sp.id, spec.attnum) AS oid,
vt.table_name || '_fk_' || spec.name AS conname,
edgedbsql_VER.uuid_to_oid(vt.module_id) AS connamespace,
'f'::"char" AS contype,
Expand Down Expand Up @@ -7856,6 +7862,10 @@ def construct_pg_view(
returns=('text',),
volatility='stable',
text=r"""
-- Wrap in a subquery SELECT so that we get a clear failure
-- if something is broken and this returns multiple rows.
-- (By default it would silently return the first.)
SELECT (
SELECT CASE
WHEN contype = 'p' THEN
'PRIMARY KEY(' || (
Expand All @@ -7868,7 +7878,6 @@ def construct_pg_view(
SELECT attname
FROM edgedbsql_VER.pg_attribute
WHERE attrelid = conrelid AND attnum = ANY(conkey)
LIMIT 1
) || '")' || ' REFERENCES "'
|| pn.nspname || '"."' || pc.relname || '"(id)'
ELSE ''
Expand All @@ -7878,6 +7887,7 @@ def construct_pg_view(
LEFT JOIN edgedbsql_VER.pg_namespace pn
ON pc.relnamespace = pn.oid
WHERE con.oid = conid
)
"""
),
trampoline.VersionedFunction(
Expand Down
Loading