oguimbal / pg-mem

An in memory postgres DB instance for your unit tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Query from node-pg-migrate that won't parse - REFERENCES

timlesallen opened this issue Β· comments

Describe the bug

One of my node-pg-migrate migrations do not parse the SQL correctly.

  πŸ’” Your query failed to parse.
    This is most likely due to a SQL syntax error. However, you might also have hit a bug, or an unimplemented feature of pg-mem.
    If this is the case, please file an issue at https://github.com/oguimbal/pg-mem along with a query that reproduces this syntax error.

    πŸ‘‰ Failed query:

        CREATE TABLE "partner_referral_agreement" (
      "partner_referral_agreement_id" text PRIMARY KEY NOT NULL,
      "partner_id" text NOT NULL REFERENCES "partner",
      "promo_code" text NOT NULL,
      "created_at" timestamptz NOT NULL,
      "created_by" text NOT NULL,
      "valid_from" timestamptz NOT NULL,
      "valid_to" timestamptz,
      "cancelled_at" timestamptz,
      "cancelled_by" text,
      "payable_amount" numeric(6, 2) NOT NULL
    );
    COMMENT ON COLUMN "partner_referral_agreement"."created_by" IS $pga$The person who input the agreement.$pga$;
    COMMENT ON COLUMN "partner_referral_agreement"."cancelled_by" IS $pga$The person who cancelled the agreement.$pga$;
    COMMENT ON COLUMN "partner_referral_agreement"."payable_amount" IS $pga$positive for payable TO partner, negative for payable TO Amber$pga$;;

    πŸ’€ Syntax error at line 3 col 50:

    1  COMMENT ON COLUMN "partner_referral_agreement"."created_by" IS $pga$The person who input the agreement.$pga$;
    2  COMMENT ON COLUMN "partner_referral_agreement"."cancelled_by" IS $pga$The person who cancelled the agreement.$pga$;
    3  COMMENT ON COLUMN "partner_referral_agreement"."payable_amount" IS $pga$positive for payable TO partner, negative for payable TO Amber$pga$;;
                                                        ^
    Unexpected comma token: ",". Instead, I was expecting to see one of the following:

        - A "dot" token
        - A "lparen" token

      at parseSql (node_modules/pg-mem/src/parser/parse-cache.ts:55:15)
      at DbSchema.parse (node_modules/pg-mem/src/schema/schema.ts:93:28)
      at DbSchema.queries (node_modules/pg-mem/src/schema/schema.ts:103:31)
          at queries.next (<anonymous>)
      at DbSchema.query (node_modules/pg-mem/src/schema/schema.ts:79:20)
      at MemPg.query (node_modules/pg-mem/src/adapters/adapters.ts:104:76)
      at Object.query (node_modules/node-pg-migrate/dist/db.js:38:33)

To Reproduce

-- create tables
   CREATE TABLE partner (
    "partner_id" text PRIMARY KEY NOT NULL
   );
   CREATE TABLE "partner_referral_agreement" (
      "partner_referral_agreement_id" text PRIMARY KEY NOT NULL,
      "partner_id" text NOT NULL REFERENCES "partner",
      "promo_code" text NOT NULL,
      "created_at" timestamptz NOT NULL,
      "created_by" text NOT NULL,
      "valid_from" timestamptz NOT NULL,
      "valid_to" timestamptz,
      "cancelled_at" timestamptz,
      "cancelled_by" text,
      "payable_amount" numeric(6, 2) NOT NULL
    );

pg-mem version

2.7.4

(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)