oguimbal / pg-mem

An in memory postgres DB instance for your unit tests
MIT License
1.95k stars 94 forks source link

schema exported with pg_dump parameters from FAQ fails to load #315

Closed mmmmmrob closed 1 year ago

mmmmmrob commented 1 year ago

Describe the bug

pg_dump exports the schema with schema objects prefixed with public. – which causes the pg-mem parser to error.

Unexpected word token: "public". I did not expect any more input. Here is the state of my parse table:

        kw_view → %word ● 
        kw_recursive → %word ● 
        kw_global → %word ● 
        kw_local → %word ● 
        kw_unlogged → %word ● 
        kw_index → %word ● 
        kw_sequence → %word ● 
        kw_temporary → %word ● 
        kw_temp → %word ● 
        kw_function → %word ● 
        kw_extension → %word ● 
        kw_type → %word ● 
        kw_materialized → %word ● 
        kw_schema → %word ●

To Reproduce

pg_dump --schema-only --no-owner --no-acl --disable-triggers --no-comments --no-publications --no-security-labels --no-subscriptions --no-tablespaces 'postgresql://me:password@localhost:5432/dbname' > schema.sql
    const db = newDb()
    const sql = fs.readFileSync('schema.sql', 'utf-8')
    db.public.none(sql)
CREATE TYPE public."State" AS ENUM (
    'PENDING',
    'DECLINED',
    'IN_PROGRESS',
    'COMPLETED'
);

pg-mem version

"version": "2.6.12"

(nb: the version in your package.json version is often not precise enough... please run "cat ./node_modules/pg-mem/package.json | grep version" to tell which minor version is actually installed)

mmmmmrob commented 1 year ago

This fails when using db.public.none(sql) but works when using db.public.query(sql) so I'm assuming it's my error.