dandadan
dandadan
DTDrizzle Team
Created by dandadan on 7/4/2023 in #help
Migrations not being applied (drizzle-orm/node-postgres/migrator)
im kind of struggling with migrations... i have the following migration index.ts which i run whenever i generate a new migration
import { drizzle } from "drizzle-orm/node-postgres";
import { migrate } from "drizzle-orm/node-postgres/migrator";
import pg from "pg";
import { env } from "config";

const migrationClient = new pg.Client({
connectionString: env.DATABASE_URL,
});

const runMigration = async () => {
const db = drizzle(migrationClient, { logger: true });
await migrate(db, { migrationsFolder: "migrations" });
};

runMigration()
.then(() => {
console.log("Migrated");
})
.catch((err) => {
console.error(err);
process.exit(1);
});
import { drizzle } from "drizzle-orm/node-postgres";
import { migrate } from "drizzle-orm/node-postgres/migrator";
import pg from "pg";
import { env } from "config";

const migrationClient = new pg.Client({
connectionString: env.DATABASE_URL,
});

const runMigration = async () => {
const db = drizzle(migrationClient, { logger: true });
await migrate(db, { migrationsFolder: "migrations" });
};

runMigration()
.then(() => {
console.log("Migrated");
})
.catch((err) => {
console.error(err);
process.exit(1);
});
the generate command with drizzle-kit did generate the sql file and it looks perfectly fine, but when i attempt to run the index.ts file in order to actually run the migration ("migrate": "node -r esbuild-register ./src/db/master/index.ts",) the only output i get in the console is this: api:migrate: Query: CREATE SCHEMA IF NOT EXISTS "drizzle" and whenever i run the application it fails withapi:dev: error: relation "sessions" does not exist (using relational queries), so im guessing the changes arent being pushed to postgres with my script... any idea?
4 replies