Skip to content

cross schema foreign key constraints introduce errors in planning #122

@whoward

Description

@whoward

Given the following database definition:

create schema some_schema;

create table public.some_table(id serial primary key);

create table some_schema.some_other_table(
  id serial primary key,
  some_table_id integer not null references public.some_table(id)
);

pgschema dump --schema some_schema produces the following output:

--
-- pgschema database dump
--

-- Dumped from database version PostgreSQL 17.0
-- Dumped by pgschema version 1.4.0


--
-- Name: some_other_table; Type: TABLE; Schema: -; Owner: -
--

CREATE TABLE IF NOT EXISTS some_other_table (
    id SERIAL,
    some_table_id integer NOT NULL,
    CONSTRAINT some_other_table_pkey PRIMARY KEY (id),
    CONSTRAINT some_other_table_some_table_id_fkey FOREIGN KEY (some_table_id) REFERENCES public.some_table (id)
);

and when you attempt to pgschema plan with this dump file you get the following error:

Error: failed to apply desired state to embedded PostgreSQL: failed to apply schema SQL: ERROR: relation "public.some_table" does not exist (SQLSTATE 42P01)

This makes sense because as of aa80712 we are trying to load dumps into an embedded postgres database, but only one schema at a time which obviously breaks cross-schema references. I'm not sure if there might be an easier way but solving this might require doing dumps and plans across multiple schemas at the same time. Any thoughts?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions