Closed
Description
Spec
Runtime: Deno
Database Provider: Neon
Reproduce:
I run into this error when I try to migrate.
Code
deno.json
{
"imports": {
"db/": "./src/db/",
"kysely": "npm:kysely@^0.27.2",
"kysely-postgres-js": "npm:kysely-postgres-js@^2.0.0",
"postgres": "https://deno.land/x/[email protected]/mod.js"
},
"tasks": {
"migrate": "deno run -A ./src/db/migrator.ts"
}
}
migrator:
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { promises as fs } from "node:fs";
import { Migrator, FileMigrationProvider } from "kysely";
import { db } from "db/database.ts";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function migrateToLatest() {
const migrator = new Migrator({
db,
provider: new FileMigrationProvider({
fs,
path,
migrationFolder: path.join(__dirname, "./migrations")
})
});
const { error, results } = await migrator.migrateToLatest();
results?.forEach((it) => {
if (it.status === "Success") {
console.log(`migration "${it.migrationName}" was executed successfully`);
} else if (it.status === "Error") {
console.error(`failed to execute migration "${it.migrationName}"`);
}
});
if (error) {
console.error("failed to migrate");
console.error(error);
Deno.exit(1);
}
await db.destroy();
}
migrateToLatest();
db instance:
import { Database } from "db/types/index.ts";
import postgres from "postgres";
import { Kysely } from "kysely";
import { PostgresJSDialect } from "kysely-postgres-js";
import { load } from "https://deno.land/[email protected]/dotenv/mod.ts";
const env = await load();
const dialect = new PostgresJSDialect({
postgres: postgres({
database: env["PGDATABASE"]!,
host: env["PGHOST"]!,
user: env["PGUSER"]!,
password: env["PGPASSWORD"]!,
port: 5434,
max: 10,
})
});
export const db = new Kysely<Database>({
dialect
});
Metadata
Metadata
Assignees
Labels
No labels