Unable to run migrations

I have this small script I'm running to perform the db migrations:
import { migrate } from "drizzle-orm/vercel-postgres/migrator";
import { db } from ".";

const runMigrations = async () => {
console.log("migration started...");
const res = await migrate(db, { migrationsFolder: "drizzle" });
console.log("migration performed succesfully!", res);
process.exit(0);
};

runMigrations().catch((err) => {
console.log("Error trying to apply migrations: ", err);
process.exit(0);
});
import { migrate } from "drizzle-orm/vercel-postgres/migrator";
import { db } from ".";

const runMigrations = async () => {
console.log("migration started...");
const res = await migrate(db, { migrationsFolder: "drizzle" });
console.log("migration performed succesfully!", res);
process.exit(0);
};

runMigrations().catch((err) => {
console.log("Error trying to apply migrations: ", err);
process.exit(0);
});
I've made sure the migrationsFolder is the one I want, it has a sql migration file that looks like this (it has more fields ofc):
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "action_status" AS ENUM('PENDING', 'COMPLETED');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "action_status" AS ENUM('PENDING', 'COMPLETED');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
I get no erros but my db remains the same, you got any ideas ?
5 Replies
Mr Volcano
Mr VolcanoOP13mo ago
I'm using vercel postgres btw
Mr Volcano
Mr VolcanoOP13mo ago
Here is a view from dbeaver after I run the migrations script: As you can see there are 2 schemas: 1. Public (same with my local db). But it's empty. I would expect the tables to get created. 2. Drizzle. Which has some migrations folders etc, not what Im looking for
No description
Mr Volcano
Mr VolcanoOP13mo ago
HA, I solved it. I just had to delete the "drizzle" schema and the migrations got applied and the "public" schema got its tables created Now I'm trying to understand why it worked
Angelelz
Angelelz13mo ago
I think that drizzle keeps track of the applied migrations in your database. You deleted that table, so drizzle thought it needed to run all migrations Now, your problem was that somehow the migration was marked as applied but it was not applied. Sometimes dropping the is a better solution for type of problems
Mr Volcano
Mr VolcanoOP13mo ago
Sounds right to me Interesting stuff, thanks for the response!
Want results from more Discord servers?
Add your server