Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ce578a6
feat: jiti support and improve logging
brenoepics Jul 12, 2025
ad873ae
feat: add tests and migration examples for jiti integration
brenoepics Jul 12, 2025
30cce19
refactor: remove ts-node support and related configurations
brenoepics Jul 12, 2025
ea5720b
feat: migrate tests from ts-node to jiti
brenoepics Jul 13, 2025
30b45bd
refactor: remove json5 dependency
brenoepics Jul 13, 2025
b688ef6
refactor: remove tsx and related configurations
brenoepics Jul 13, 2025
ea94575
docs: add TypeScript and modern JavaScript support documentation
brenoepics Jul 13, 2025
52222ce
docs: update getting started guide with TypeScript migration examples
brenoepics Jul 13, 2025
068f021
docs: improve clarity and grammar in CLI and troubleshooting docs
brenoepics Jul 13, 2025
76093ab
docs: fix type error on json import
brenoepics Jul 13, 2025
c459c1b
docs: lint
brenoepics Jul 13, 2025
69b2e99
docs: fix vitepress typecheck
brenoepics Jul 14, 2025
8d8b866
Merge branch 'main' into feat-jiti
brenoepics Jul 14, 2025
f278a18
fix: update jiti version range
brenoepics Jul 14, 2025
4dd6918
Apply suggestion from @Shinigami92
brenoepics Jul 15, 2025
bba0bc4
Revert "docs: fix vitepress typecheck"
brenoepics Jul 15, 2025
7a9fe7f
Revert "docs: fix type error on json import"
brenoepics Jul 15, 2025
36bac76
Merge remote-tracking branch 'fork/feat-jiti' into feat-jiti
brenoepics Jul 15, 2025
dc05850
Merge branch 'main' into feat-jiti
brenoepics Jul 15, 2025
658dd05
tests(jiti): use `ToBeTypeOf` assertion
brenoepics Jul 15, 2025
d0bc887
chore: split type import
brenoepics Jul 15, 2025
7d28c4b
fix: actually test migration files
brenoepics Jul 15, 2025
1839463
fix: move `jiti` to `runner.ts`
brenoepics Jul 15, 2025
9ccbc89
feat: jiti support and improve logging
brenoepics Jul 12, 2025
691dc70
feat: add tests and migration examples for jiti integration
brenoepics Jul 12, 2025
f07a225
refactor: remove ts-node support and related configurations
brenoepics Jul 12, 2025
db95bdd
feat: migrate tests from ts-node to jiti
brenoepics Jul 13, 2025
95333ea
refactor: remove json5 dependency
brenoepics Jul 13, 2025
01a2272
refactor: remove tsx and related configurations
brenoepics Jul 13, 2025
d8def5a
docs: add TypeScript and modern JavaScript support documentation
brenoepics Jul 13, 2025
489bc0f
docs: update getting started guide with TypeScript migration examples
brenoepics Jul 13, 2025
b9d4350
docs: improve clarity and grammar in CLI and troubleshooting docs
brenoepics Jul 13, 2025
e4763cd
docs: fix type error on json import
brenoepics Jul 13, 2025
8f3cd24
docs: lint
brenoepics Jul 13, 2025
850337d
docs: fix vitepress typecheck
brenoepics Jul 14, 2025
3ab11ce
fix: update jiti version range
brenoepics Jul 14, 2025
a1bd5de
Revert "docs: fix vitepress typecheck"
brenoepics Jul 15, 2025
4d5f677
Revert "docs: fix type error on json import"
brenoepics Jul 15, 2025
fd48ea7
test: remove outdated TODO comment in `createTable` spec (#1466)
brenoepics Jul 15, 2025
83f67d9
docs: simplify theme config and add tsconfig for Vitepress (#1468)
brenoepics Jul 15, 2025
d71260a
chore(deps): update pnpm to v10.13.1 (#1467)
renovate[bot] Jul 15, 2025
595426a
tests(jiti): use `ToBeTypeOf` assertion
brenoepics Jul 15, 2025
90e3ec4
chore: split type import
brenoepics Jul 15, 2025
7e17711
fix: actually test migration files
brenoepics Jul 15, 2025
8afb7f5
fix: move `jiti` to `runner.ts`
brenoepics Jul 15, 2025
0f884ed
Merge remote-tracking branch 'fork/feat-jiti' into feat-jiti
brenoepics Jul 15, 2025
4fd489c
Merge branch 'main' into feat-jiti
brenoepics Jul 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 6 additions & 62 deletions .github/workflows/postgres-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ jobs:
if: always()
run: docker logs "${{ job.services.postgres.id }}"

typescript-migration-via-ts-node-test:
typescript-migration-via-jiti-test:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -641,7 +641,7 @@ jobs:
# Maps tcp port 5432 on service container to the host
- 5432:5432

name: 'TypeScript Migration Test with ts-node: pg-${{ matrix.postgres_version }}, node-${{ matrix.node_version }}, ubuntu-latest'
name: 'TypeScript Migration Test with jiti: pg-${{ matrix.postgres_version }}, node-${{ matrix.node_version }}, ubuntu-latest'
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand All @@ -662,69 +662,13 @@ jobs:
run: pnpm run build

- name: Integration Test
run: pnpm run migrate up --tsconfig tsconfig.json --ts-node -m test/ts/migrations && pnpm run migrate down 0 --tsconfig tsconfig.json --ts-node -m test/ts/migrations --timestamps
run: pnpm run migrate up -m test/ts/migrations && pnpm run migrate down 0 -m test/ts/migrations --timestamps
env:
DATABASE_URL: postgres://ubuntu:ubuntu@localhost:5432/integration_test

- name: Postgres logs
if: always()
run: docker logs "${{ job.services.postgres.id }}"

typescript-migration-via-tsx-test:
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [22]
postgres_version: [17]
fail-fast: false
timeout-minutes: 10

services:
postgres:
image: postgres:${{ matrix.postgres_version }}-alpine
env:
POSTGRES_USER: ubuntu
POSTGRES_PASSWORD: ubuntu
POSTGRES_DB: integration_test
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432

name: 'TypeScript Migration Test with tsx: pg-${{ matrix.postgres_version }}, node-${{ matrix.node_version }}, ubuntu-latest'
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Install pnpm
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

- name: Set node version to ${{ matrix.node_version }}
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: ${{ matrix.node_version }}
cache: 'pnpm'

- name: Install deps
run: pnpm install

- name: Build
run: pnpm run build

- name: Integration Test
run: pnpm run migrate up --tsconfig tsconfig.json --tsx -m test/ts/migrations && pnpm run migrate down 0 --tsconfig tsconfig.json --tsx -m test/ts/migrations --timestamps
env:
DATABASE_URL: postgres://ubuntu:ubuntu@localhost:5432/integration_test

- name: Postgres logs
if: always()
run: docker logs "${{ job.services.postgres.id }}"

typescript-customrunner-url-test:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -772,7 +716,7 @@ jobs:
run: pnpm run build

- name: Integration Test
run: node --experimental-specifier-resolution=node --loader ts-node/esm test/ts/customRunnerDBUrl.ts
run: node --experimental-specifier-resolution=node --import jiti/register test/ts/customRunnerDBUrl.ts
Comment thread
brenoepics marked this conversation as resolved.
env:
DATABASE_URL: postgres://ubuntu:ubuntu@localhost:5432/integration_test

Expand Down Expand Up @@ -827,7 +771,7 @@ jobs:
run: pnpm run build

- name: Integration Test
run: node --experimental-specifier-resolution=node --loader ts-node/esm test/ts/customRunnerDBClient.ts
run: node --experimental-specifier-resolution=node --import jiti/register test/ts/customRunnerDBClient.ts
env:
DATABASE_URL: postgres://ubuntu:ubuntu@localhost:5432/integration_test

Expand Down Expand Up @@ -882,7 +826,7 @@ jobs:
run: pnpm run build

- name: Integration Test
run: node --experimental-specifier-resolution=node --loader ts-node/esm test/ts/customRunnerUndefCount.ts
run: node --experimental-specifier-resolution=node --import jiti/register test/ts/customRunnerUndefCount.ts
env:
DATABASE_URL: postgres://ubuntu:ubuntu@localhost:5432/integration_test

Expand Down
84 changes: 0 additions & 84 deletions bin/node-pg-migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import {
PG_MIGRATE_LOCK_ID,
runner as migrationRunner,
} from 'node-pg-migrate';
import { readFileSync } from 'node:fs';
import { register } from 'node:module';
import { join, resolve } from 'node:path';
import { cwd } from 'node:process';
import { pathToFileURL } from 'node:url';
import { format } from 'node:util';
import type { ClientConfig } from 'pg';
import type ConnectionParametersType from 'pg/lib/connection-parameters';
Expand Down Expand Up @@ -76,9 +73,6 @@ const timestampArg = 'timestamp';
const dryRunArg = 'dry-run';
const fakeArg = 'fake';
const decamelizeArg = 'decamelize';
const tsconfigArg = 'tsconfig';
const tsNodeArg = 'ts-node';
const tsxArg = 'tsx';
const verboseArg = 'verbose';
const rejectUnauthorizedArg = 'reject-unauthorized';
const envPathArg = 'envPath';
Expand Down Expand Up @@ -182,20 +176,6 @@ const parser = yargs(process.argv.slice(2))
describe: 'Path to template for creating migrations',
type: 'string',
},
[tsconfigArg]: {
describe: 'Path to tsconfig.json file',
type: 'string',
},
[tsNodeArg]: {
default: true,
describe: 'Use ts-node for typescript files',
type: 'boolean',
},
[tsxArg]: {
default: false,
describe: 'Use tsx for typescript files',
type: 'boolean',
},
[envPathArg]: {
describe: 'Path to the .env file that should be used for configuration',
type: 'string',
Expand Down Expand Up @@ -294,58 +274,6 @@ let TEMPLATE_FILE_NAME = argv[templateFileNameArg];
let CHECK_ORDER = argv[checkOrderArg];
let VERBOSE = argv[verboseArg];
let DECAMELIZE = argv[decamelizeArg];
let tsconfigPath = argv[tsconfigArg];
let useTsNode = argv[tsNodeArg];
let useTsx = argv[tsxArg];

async function readTsconfig(): Promise<void> {
if (tsconfigPath) {
let tsconfig;
const json5 = await tryImport<typeof import('json5')>('json5');

try {
const config = readFileSync(resolve(cwd(), tsconfigPath), {
encoding: 'utf8',
});
tsconfig = json5 ? json5.parse(config) : JSON.parse(config);

if (tsconfig['ts-node']) {
tsconfig = {
...tsconfig,
...tsconfig['ts-node'],
compilerOptions: {
// eslint-disable-next-line unicorn/no-useless-fallback-in-spread
...(tsconfig.compilerOptions ?? {}),
// eslint-disable-next-line unicorn/no-useless-fallback-in-spread
...(tsconfig['ts-node'].compilerOptions ?? {}),
},
};
}
} catch (error) {
console.error("Can't load tsconfig.json:", error);
}

if (useTsx) {
process.env.TSX_TSCONFIG_PATH = tsconfigPath;
} else if (useTsNode) {
const tsnode = await tryImport<typeof import('ts-node')>('ts-node');
if (!tsnode) {
console.error(
"For TypeScript support, please install 'ts-node' module"
);
}

if (tsconfig && tsnode) {
register('ts-node/esm', pathToFileURL('./'));
if (!MIGRATIONS_FILE_LANGUAGE) {
MIGRATIONS_FILE_LANGUAGE = 'ts';
}
} else {
process.exit(1);
}
}
}
}

function applyIf<TArg, TKey extends string = string>(
arg: TArg,
Expand Down Expand Up @@ -442,9 +370,6 @@ function readJson(json: unknown): void {
(val): val is string | ConnectionParametersType | ClientConfig =>
typeof val === 'string' || typeof val === 'object'
);
tsconfigPath = applyIf(tsconfigPath, tsconfigArg, json, isString);
useTsNode = applyIf(useTsNode, tsNodeArg, json, isBoolean);
useTsx = applyIf(useTsx, tsxArg, json, isBoolean);

if ('url' in json && json.url) {
DB_CONNECTION ??= json.url;
Expand Down Expand Up @@ -484,15 +409,6 @@ if (configFileName) {
readJson(json?.[section] === undefined ? json : json[section]);
}

await readTsconfig();

if (useTsx) {
const tsx = await tryImport<typeof import('tsx/esm/api')>('tsx/esm');
if (!tsx) {
console.error("For TSX support, please install 'tsx' module");
}
}

const action = argv._.shift();

// defaults
Expand Down
4 changes: 2 additions & 2 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ function sidebarReference(): DefaultTheme.SidebarItem[] {
function sidebarFAQ(): DefaultTheme.SidebarItem[] {
return [
{
text: 'Transpiling Migrations',
link: 'transpiling',
text: 'Typescript Migrations',
link: 'typescript',
},
{
text: 'Troubleshooting',
Expand Down
6 changes: 2 additions & 4 deletions docs/src/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You could also specify your database url by setting the environment variable `DA
DATABASE_URL=postgres://postgres@localhost/database node-pg-migrate
```

You can specify custom JSON file with config (the format is same as for `db` entry
You can specify a custom JSON file with config (the format is same as for `db` entry
of [config](https://www.npmjs.com/package/config) file), for example:

```jsonc
Expand Down Expand Up @@ -76,7 +76,7 @@ More on that below.
> [!TIP]
> See all by running `node-pg-migrate --help`.
>
> Most of the configuration options can be also specified in [config](https://www.npmjs.com/package/config) file.
> Most of the configuration options can be also specified in the [config](https://www.npmjs.com/package/config) file.

You can adjust defaults by passing arguments to `node-pg-migrate`:

Expand All @@ -96,7 +96,6 @@ You can adjust defaults by passing arguments to `node-pg-migrate`:
| `migration-filename-format` | | `timestamp` | Choose prefix of file, `utc` (`20200605075829074`), `timestamp` (`1591343909074`), or `index` (`0012`) |
| `migration-file-language` | `j` | `js` | Language of the migration file to create (`js`, `ts` or `sql`) |
| `template-file-name` | | `undefined` | Utilize a custom migration template file with language inferred from its extension. The file should export the up method, accepting a MigrationBuilder instance. |
| `tsconfig` | | `undefined` | Path to tsconfig.json. Used to setup transpiling of TS migration files. (Also sets `migration-file-language` to typescript, if not overridden) |
| `envPath` | | `same level where it's invoked` | Retrieve the path to a .env file. This feature proves handy when dealing with nested projects or when referencing a global .env file. |
| `timestamp` | | `false` | Treats number argument to up/down migration as timestamp (running up migrations less or equal to timestamp or down migrations greater or equal to timestamp) |
| `check-order` | | `true` | Check order of migrations before running them, to switch it off supply `--no-check-order` |
Expand Down Expand Up @@ -137,6 +136,5 @@ Other available options are:
"checkOrder": true,
"verbose": true,
"decamelize": false,
"tsconfig": "tsconfig.json",
}
```
66 changes: 0 additions & 66 deletions docs/src/faq/transpiling.md

This file was deleted.

6 changes: 3 additions & 3 deletions docs/src/faq/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ Or always use lower case identifiers to prevent confusion (unquoted identifiers
## Refused connection issues

- Password to your database may not contain some characters (which have special meaning in url schema) when used in `DATABASE_URL`.
Use other means to provide password or change the password. [see](https://github.com/salsita/node-pg-migrate/issues/439)
Use other means to provide a password or change the password. [see](https://github.com/salsita/node-pg-migrate/issues/439)
- Make sure connection is not stopped by firewalls, security rules, etc.
Try `telnet url port` to try to connect (e.g. `telnet 127.0.0.1 5432`) to postgres server.
If command will not end with error, but will wait for further input from you, server (or some other service running on that port :man_shrugging:) is accessible and waits for the correct user/password.
Otherwise, the server does not run or listen on specified port, or there is some other connection problem. You have to investigate...
If the command does not end with an error but will wait for further input from you, the server (or some other service running on that port :man_shrugging:) is accessible and waits for the correct user/password.
Otherwise, the server does not run or listen on the specified port, or there is some other connection problem. You have to investigate...

## Running in transaction

Expand Down
Loading