From 9002c18d8f9e3a3e84fab0bfed610ce402b558e3 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Tue, 19 Dec 2023 21:16:09 +1100 Subject: [PATCH 1/3] Update migrate example script The `Migrator` needs absolute paths for the `migrationFolder`, without it the script will throw an error. It also requires that `fs` and `path` are passed in. --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 00096b8..5d66e3b 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,13 @@ Create a migration script as shown below: ```typescript // scripts/migrate.ts +import * as path from 'path' +import { promises as fs } from 'fs'; import { Kysely, Migrator, PostgresDialect, FileMigrationProvider } from 'kysely' import { run } from 'kysely-migration-cli' +const migrationFolder = new URL('./migrations', import.meta.url).pathname + const db = new Kysely({ dialect: new PostgresDialect({ connectionString: process.env.DATABASE_URL, @@ -34,10 +38,14 @@ const db = new Kysely({ const migrator = new Migrator({ db, - provider: new FileMigrationProvider('./migrations'), + provider: new FileMigrationProvider({ + fs, + path, + migrationFolder, + }), }) -run(db, migrator) +run(db, migrator, migrationFolder) ``` Then run: From bdf7b3b57c3746e99e861016ce48db8314bb4495 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Tue, 19 Dec 2023 21:18:19 +1100 Subject: [PATCH 2/3] Update migrate script with pg Pool --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d66e3b..3f40e9b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ Create a migration script as shown below: // scripts/migrate.ts import * as path from 'path' -import { promises as fs } from 'fs'; +import { promises as fs } from 'fs' +import pg from 'pg' import { Kysely, Migrator, PostgresDialect, FileMigrationProvider } from 'kysely' import { run } from 'kysely-migration-cli' @@ -32,7 +33,9 @@ const migrationFolder = new URL('./migrations', import.meta.url).pathname const db = new Kysely({ dialect: new PostgresDialect({ - connectionString: process.env.DATABASE_URL, + pool: new pg.Pool({ + connectionString: process.env.DATABASE_URL, + }), }), }) From db9c912eeae464c7b3fdacb1b4c077b2d0242b85 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Tue, 19 Dec 2023 22:09:24 +1100 Subject: [PATCH 3/3] Update README.md Co-authored-by: Kay Gosho --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3f40e9b..cd4ce27 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,12 @@ import pg from 'pg' import { Kysely, Migrator, PostgresDialect, FileMigrationProvider } from 'kysely' import { run } from 'kysely-migration-cli' +// For ESM environment const migrationFolder = new URL('./migrations', import.meta.url).pathname +// For CJS environment +// const migrationFolder = path.join(__dirname, './migrations') + const db = new Kysely({ dialect: new PostgresDialect({ pool: new pg.Pool({