pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Running plan fails when schema A wants to refefence something in schema B

Open Thxsoft64 opened this issue 9 months ago • 1 comments

The failue is:

Error: failed to apply desired state: failed to apply schema SQL to temporary schema pgschema_tmp_20260206_185024_01130b54: ERROR: relation "public.geotab_database" does not exist (SQLSTATE 42P01)

This is the reference that fails:

ALTER TABLE database ADD CONSTRAINT zone_tool_database_geotab_database_id_fk FOREIGN KEY (geotab_database_id) REFERENCES public.geotab_database (id) ON DELETE CASCADE;

Dump shows geotab_database is defined as:

--
-- pgschema database dump
--

-- Dumped from database version PostgreSQL 17.7
-- Dumped by pgschema version 1.6.2

CREATE EXTENSION IF NOT EXISTS "citext" SCHEMA public;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA public;
CREATE EXTENSION IF NOT EXISTS pg_trgm SCHEMA public;

CREATE TABLE IF NOT EXISTS geotab_database (
    name citext NOT NULL,
    active boolean DEFAULT true NOT NULL,
    id uuid DEFAULT public.uuid_generate_v1mc(),
    api_password text,
    CONSTRAINT geotab_database_pk PRIMARY KEY (id)
);
CREATE INDEX IF NOT EXISTS geotab_database_active_idx ON geotab_database (active);
CREATE INDEX IF NOT EXISTS geotab_database_name_idx ON geotab_database (name);
CREATE INDEX IF NOT EXISTS geotab_database_name_idx1 ON geotab_database USING gin (lower(name::text) gin_trgm_ops);

Thxsoft64 avatar Feb 06 '26 08:02 Thxsoft64

Similar to #122, please use an external plan database

"Your schema has cross-schema foreign key references - The embedded approach only loads one schema at a time, breaking foreign key constraints that reference tables in other schemas"

see https://www.pgschema.com/cli/plan-db#when-to-use-external-database

tianzhou avatar Feb 06 '26 09:02 tianzhou