Skip to content

Interdependent types do not get dumped in the correct order in some cases #195

@whoward

Description

@whoward

Given the following database definition:

create type some_type as enum ('value1', 'value2');

create type some_other_type as (name text, type some_type);

create table some_table(id serial primary key, data some_other_type);

We can see that the definition of some_other_type depends on the definition of some_type

When pgschema dump is run we get the following output:

--
-- pgschema database dump
--

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


--
-- Name: some_other_type; Type: TYPE; Schema: -; Owner: -
--

CREATE TYPE some_other_type AS (name text, type some_type);

--
-- Name: some_type; Type: TYPE; Schema: -; Owner: -
--

CREATE TYPE some_type AS ENUM (
    'value1',
    'value2'
);

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

CREATE TABLE IF NOT EXISTS some_table (
    id SERIAL,
    data some_other_type,
    CONSTRAINT some_table_pkey PRIMARY KEY (id)
);

This dump file is incorrect because it defines some_other_type before some_type which will cause an error when we attempt to load the dump. To be specific we see pgschema plan produce the following error:

Error: failed to apply desired state: failed to apply schema SQL to temporary schema pgschema_tmp_20251209_125803_ed6a4663: ERROR: type "some_type" does not exist (SQLSTATE 42704)

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