pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

types created from extensions cause an error in planning

Open whoward opened this issue 1 year ago • 8 comments

Given the following database definition:

create extension hstore;

create table some_table(
  id serial primary key,
  some_value hstore
);

pgschema dump outputs:

--
-- pgschema database dump
--

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


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

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

However when you attempt to plan on this dumped schema you get the following error:

Error: failed to apply desired state to embedded PostgreSQL: failed to apply schema SQL: ERROR: type "hstore" does not exist (SQLSTATE 42704)

the dump file would probably have to include CREATE EXTENSION statements.

whoward avatar Oct 23 '25 14:10 whoward

pgschema operates on schema level.

CREATE EXTENSION is a database level statement and is not supported https://www.pgschema.com/syntax/unsupported#database-level-commands

User needs to manage the lifecycle of extensions outside of pgschema

tianzhou avatar Oct 23 '25 17:10 tianzhou

i agree that pgschema shouldn't manage extensions, but in order to plan using an internal embedded database the extension will have to be installed on that embedded database as it can provide dependencies like types or even tables or views.

whoward avatar Oct 23 '25 18:10 whoward

The embedded pg doesn't support extension. I need to think of different plan.

https://github.com/fergusstrange/embedded-postgres/issues/21 https://github.com/zonkyio/embedded-postgres-binaries/issues/6

tianzhou avatar Oct 24 '25 10:10 tianzhou

sorry for being such a challenge lol...i do really like the tool but it's been challenging to get to a point where we can use it against our obviously very complex database

whoward avatar Oct 24 '25 16:10 whoward

if it helps i would not be opposed to allowing pgschema to own a database on my postgres server to load the target schema into. i imagine that is probably heavier than you'd prefer but it would solve the extension issue at least.

whoward avatar Oct 27 '25 14:10 whoward

@whoward if you mean something similar to Prisma shadow DB https://www.prisma.io/docs/orm/prisma-migrate/understanding-prisma-migrate/shadow-database

Yes, that's an option we can resort to. I am still researching

tianzhou avatar Oct 27 '25 14:10 tianzhou

Please use external plan db: https://www.pgschema.com/cli/plan-db. Available in 1.4.1

tianzhou avatar Nov 01 '25 10:11 tianzhou

very nice! i checked and this works well. Thanks!

whoward avatar Nov 04 '25 16:11 whoward