DT
Drizzle Team•16mo ago
Paul

When pushing migrations to Supabase, it skips saying the schema "drizzle" already exists.

When I update my schema and try to push the migration to Supabase, I get the following error. How can I move forward with pushing it as opposed to having it skip? I guess part of the issue is I don't understand how migrations really work so not sure what this error is telling me is wrong. In my database, I already have 2 entries in a table called __drizzle_migrations under the drizzle schema that was auto-created by drizzle-kit when migrating the first few times
Migrating...
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P06',
message: 'schema "drizzle" already exists, skipping',
file: 'schemacmds.c',
line: '128',
routine: 'CreateSchemaCommand'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "__drizzle_migrations" already exists, skipping',
file: 'parse_utilcmd.c',
line: '209',
routine: 'transformCreateStmt'
}
Migrating...
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P06',
message: 'schema "drizzle" already exists, skipping',
file: 'schemacmds.c',
line: '128',
routine: 'CreateSchemaCommand'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42P07',
message: 'relation "__drizzle_migrations" already exists, skipping',
file: 'parse_utilcmd.c',
line: '209',
routine: 'transformCreateStmt'
}
My migration file looks like this:
import postgres from "postgres";
import { drizzle, PostgresJsDatabase } from "drizzle-orm/postgres-js";
import { migrate } from "drizzle-orm/postgres-js/migrator";

import { env } from "@core/env";

const client = postgres(env.POSTGRES_DB_URL, {
ssl: { rejectUnauthorized: false },
});

async function postgresMigrate() {
try {
const db: PostgresJsDatabase = drizzle(client);

// Migrate
console.log("Migrating...");
await migrate(db, { migrationsFolder: "drizzle" });
console.log("Done!");
} finally {
process.exit(0);
}
}

postgresMigrate();
import postgres from "postgres";
import { drizzle, PostgresJsDatabase } from "drizzle-orm/postgres-js";
import { migrate } from "drizzle-orm/postgres-js/migrator";

import { env } from "@core/env";

const client = postgres(env.POSTGRES_DB_URL, {
ssl: { rejectUnauthorized: false },
});

async function postgresMigrate() {
try {
const db: PostgresJsDatabase = drizzle(client);

// Migrate
console.log("Migrating...");
await migrate(db, { migrationsFolder: "drizzle" });
console.log("Done!");
} finally {
process.exit(0);
}
}

postgresMigrate();
4 Replies
Wezter
Wezter•16mo ago
Did you find a good solution for this? 😄
ultrakiller
ultrakiller•16mo ago
hey! did you find a solution for this issue? migrations have stopped being applied to supabase it seems.
sik
sik•16mo ago
does it work locally? like do the migrations apply on the local database instance
ultrakiller
ultrakiller•16mo ago
uh that was weird, drizzle was trying to connect to the supplied database URL but the connection wasn't approved, so it started randomly applying migrations to a local postgres database running at postgresql://localhost hence the migrations weren't applied to the supabase instance
Want results from more Discord servers?
Add your server