Skip to content

Not all shorthands available in all migration files #1513

Description

@benkroeger

Describe the bug

Some shorthands might be missing in migration files.
Say I define shorthand txt_id_default in migration file 1.ts - I'd expect it to be available in 2.ts, 3.ts and so on.

Due to the async nature of how migration files are loaded (and within a Promise.all), the actual loading order and aggregation of shorthands is not guaranteed.

https://github.com/salsita/node-pg-migrate/blob/eb4ef165d20b85d30d51de65f294115883147718/src/runner.ts#L191C9-L191C19

Strangely this only happens in the 7th migration file... migration files 1-6 seem to have all shorthands available.

Steps to reproduce

  1. create at least 7 migration files
  2. define shorthands in the first one
  3. use the shorthand in the 7th migration file or later

Logs

Error executing:
CREATE TABLE "space" (
  "id" txt_id_default,
       ^^^^
);

type "txt_id_default" does not exist

> Rolling back attempted migration ...
error: type "txt_id_default" does not exist
    at /usr/src/app/node_modules/pg/lib/client.js:545:17
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async Object.query (file:///usr/src/app/node_modules/node-pg-migrate/dist/bundle/index.js:3499:14)
    at async runner (file:///usr/src/app/node_modules/node-pg-migrate/dist/bundle/index.js:3806:9) {
  length: 101,
  severity: 'ERROR',
  code: '42704',
  detail: undefined,
  hint: undefined,
  position: '31',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'parse_type.c',
  line: '270',
  routine: 'typenameType'
}

System Info

System:
    OS: macOS 15.6.1
    CPU: (16) arm64 Apple M3 Max
    Memory: 278.33 MB / 48.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.7.0 - ~/Library/pnpm/node
    npm: 11.5.1 - ~/Library/pnpm/npm
    pnpm: 10.15.0 - ~/Library/pnpm/pnpm
  npmPackages:
    node-pg-migrate: ^8.0.3 => 8.0.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions