oguimbal / pg-mem

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

Receive problem when trying to reproduce tutorial example on my project entities #370

Open goodstemy opened 7 months ago

goodstemy commented 7 months ago

Describe the bug

I'm using nest.js + typeorm. Based on this example I tried to create test with pg-mem.

 FAIL  src/controllers/order/order.service.spec.ts
  Order module
    ✕ Should work (1 ms)

  ● Order module › Should work

    QueryFailedError: Invalid timestamp format: now

    🐜 This seems to be an execution error, which means that your request syntax seems okay,
        but the resulting statement cannot be executed → Probably not a pg-mem error.

    *️⃣ Failed SQL statement: CREATE TABLE "session" ("id" BIGSERIAL NOT NULL, "version" integer NOT NULL, "type" "public"."session_type_enum" NOT NULL, "userId" integer, "isRevoked" boolean NOT NULL DEFAULT false, "revokeReason" character varying, "createdAt" TIMESTAMP NOT NULL DEFAULT ('now'::text)::timestamp(6) with time zone, "updatedAt" TIMESTAMP NOT NULL DEFAULT ('now'::text)::timestamp(6) with time zone, CONSTRAINT "PK_f55da76ac1c3ac420f444d2ff11" PRIMARY KEY ("id"));

This query works fine if it running on real pg db.

To Reproduce

Looks like error reason in the entity field:

  @Field()
  @CreateDateColumn({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP(6)',
  })
  createdAt: Date;

pg-mem version

"version": "2.7.2",

goodstemy commented 7 months ago

Also find out rn if I change:

@Field()
  @CreateDateColumn({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP(6)',
  })
  createdAt: Date;

to

@Field()
  @CreateDateColumn({
    type: 'timestamp',
    default: () => 'NOW()',
  })
  createdAt: Date;

it works fine. But for me really matters to make timestamp with precision using current_timestamp function.

goodstemy commented 7 months ago

And also got warning (doesn't seen this first time):

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
    Arguments:
    [0] _isAMomentObject: true, _isUTC: true, _useUTC: true, _l: undefined, _i: now, _f: undefined, _strict: undefined, _locale: [object Object]
    Error:
        at Function.createFromInputFallback (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:324:25)
        at configFromString (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:2550:19)
        at configFromInput (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:2993:13)
        at prepareConfig (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:2976:13)
        at createFromConfig (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:2943:44)
        at createLocalOrUTC (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:3037:16)
        at Function.createUTC [as utc] (/Users/ivan/coding/boqpod/laox/core/node_modules/moment/moment.js:106:16)
        at value.setConversion.toTs.toTs (/Users/ivan/coding/boqpod/laox/core/node_modules/pg-mem/src/datatypes/t-timestamp.ts:97:53)
        at Evaluator.val (/Users/ivan/coding/boqpod/laox/core/node_modules/pg-mem/src/evaluator.ts:128:28)

How can I solve it?

eliasjtg commented 4 months ago

Any fix or workaround?

I have the same issue