Cannot migrate up with ts migration #1267
hardysabs2
started this conversation in
General
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
If my migration is a .js then
npx node-pg-migrate up -d DATABASE_URL
is successful thus:
MIGRATION 1725749186216_my-first-migration (UP)
CREATE TABLE "users" (
"id" serial PRIMARY KEY,
"name" varchar(1000) NOT NULL,
"createdAt" timestamp DEFAULT current_timestamp NOT NULL
);
INSERT INTO "public"."pgmigrations" (name, run_on) VALUES ('1725749186216_my-first-migration', NOW());
Migrations complete!
However, I could not find a way to create a ts migration file so I set the extension myself and wrote the code inside it
migrations/1725749186216_my-first-migration.ts
exports.up = (pgm: import("node-pg-migrate").MigrationBuilder) => {
pgm.createTable("users", {
id: "id",
name: { type: "varchar(1000)", notNull: true },
createdAt: {
type: "timestamp",
notNull: true,
default: pgm.func("current_timestamp")
}
});
};
but I am struggling to find the right commands to transpile and run this migration as an up.
I'm keen to understand how I can run node-pg-migrate create (or ts equivalent) to create a ts migration rather than a js one and how to run node-pg-migrate up (or ts equivalent) to run the migration.
npx node-pg-migrate up -d DATABASE_URL
This does not recognise the ts - I think it is expecting js
npx ts-node node-pg-migrate up -d DATABASE_URL -j ts
or
I get - Error: Cannot find module './node-pg-migrate'
or
ts-node node_modules/.bin/node-pg-migrate up -d DATABASE_URL -j ts
Error: Can't get migration files: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:
or
ts-node node_modules/.bin/node-pg-migrate.cjs up -d DATABASE_URL -j ts
node:internal/modules/cjs/loader:1148
throw err;
^
Error: Cannot find module './node-pg-migrate.cjs'
Some guidance on
a) create to create a ts migration
b) how to run the ts migration up
would be greatly appreciated.
I am on version 7.7.0-rc.0
Beta Was this translation helpful? Give feedback.
All reactions