CREATE TYPE doesn't work with multiple tables in psqldef #854
-
Environment
IssueI'm experiencing an issue where Single table (works)CREATE TYPE order_status AS ENUM ('pending', 'shipped');
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
status order_status NOT NULL
);This applies successfully. Multiple tables (fails)CREATE TYPE order_status AS ENUM ('pending', 'shipped');
CREATE TABLE customers (
id SERIAL PRIMARY KEY
);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
status order_status NOT NULL
);This fails with ObservationWhen I run with $ cat schema.sql
CREATE TYPE order_status AS ENUM ('pending', 'shipped');
CREATE TABLE customers (
id SERIAL PRIMARY KEY
);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
status order_status NOT NULL
);
$ psqldef --dry-run xxx < schema.sql
BEGIN;
CREATE TABLE customers (
id SERIAL PRIMARY KEY
);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
status order_status NOT NULL
);
CREATE TYPE order_status AS ENUM ('pending', 'shipped');
COMMIT;This ordering difference might be causing the issue. Current WorkaroundI'm using -- before.sql
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'order_status') THEN
CREATE TYPE order_status AS ENUM ('pending', 'shipped');
END IF;
END $$;psqldef --before-apply="$(cat before.sql)" database < schema.sqlThis works, but I'm wondering if there's a better approach or if this is expected behavior? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
It seems to be a bug introduced by #805 And fixed in #865 |
Beta Was this translation helpful? Give feedback.
It seems to be a bug introduced by #805
And fixed in #865