Migrations taking the first snapshot

I'm running migration like how it says in the docs, but for some reason it keeps trying to use the first migrations file generated even after running generate
import "dotenv/config";

import { migrate } from "drizzle-orm/mysql2/migrator";

import { connection, db } from "./index";

// This will run migrations on the database, skipping the ones already applied
await migrate(db, { migrationsFolder: "./drizzle" });

// Don't forget to close the connection, otherwise the script will hang
await connection.end();
import "dotenv/config";

import { migrate } from "drizzle-orm/mysql2/migrator";

import { connection, db } from "./index";

// This will run migrations on the database, skipping the ones already applied
await migrate(db, { migrationsFolder: "./drizzle" });

// Don't forget to close the connection, otherwise the script will hang
await connection.end();
This is the second migration file:
ALTER TABLE `Notifications` ADD `test` varchar(255);
ALTER TABLE `Notifications` ADD `test` varchar(255);
The first migration file starts with creating the Blocked table, so that's how I know it's running that instead of the second.
No description
1 Reply
'tonyyprints'
'tonyyprints'OP7mo ago
This is the error I'm getting.
Error: Table 'Blocked' already exists
at PromiseConnection.query (C:\Users\ghait\WebstormProjects\oppfy\node_modules\mysql2\promise.js:94:22)
at MySql2PreparedQuery.execute (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql2\session.ts:85:18)
at MySql2Session.execute (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql-core\session.ts:81:5)
at MySql2Transaction.execute (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql-core\db.ts:456:23)
at <anonymous> (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql-core\dialect.ts:62:16)
at MySql2Session.transaction (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql2\session.ts:247:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at MySqlDialect.migrate (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql-core\dialect.ts:55:3)
at migrate (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql2\migrator.ts:10:2)
at <anonymous> (c:\Users\ghait\WebstormProjects\oppfy\packages\db\migrate.ts:8:1) {
code: 'ER_TABLE_EXISTS_ERROR',
errno: 1050,
sql: 'CREATE TABLE `Blocked` (\n' +
'\t`id` serial AUTO_INCREMENT NOT NULL,\n' +
'\t`userId` varchar(255) NOT NULL,\n' +
'\t`blockedUserId` varchar(255) NOT NULL,\n' +
'\t`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n' +
'\tCONSTRAINT `Blocked_id` PRIMARY KEY(`id`)\n' +
');\n',
sqlState: '42S01',
sqlMessage: "Table 'Blocked' already exists"
}
Error: Table 'Blocked' already exists
at PromiseConnection.query (C:\Users\ghait\WebstormProjects\oppfy\node_modules\mysql2\promise.js:94:22)
at MySql2PreparedQuery.execute (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql2\session.ts:85:18)
at MySql2Session.execute (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql-core\session.ts:81:5)
at MySql2Transaction.execute (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql-core\db.ts:456:23)
at <anonymous> (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql-core\dialect.ts:62:16)
at MySql2Session.transaction (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql2\session.ts:247:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at MySqlDialect.migrate (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql-core\dialect.ts:55:3)
at migrate (C:\Users\ghait\WebstormProjects\oppfy\node_modules\src\mysql2\migrator.ts:10:2)
at <anonymous> (c:\Users\ghait\WebstormProjects\oppfy\packages\db\migrate.ts:8:1) {
code: 'ER_TABLE_EXISTS_ERROR',
errno: 1050,
sql: 'CREATE TABLE `Blocked` (\n' +
'\t`id` serial AUTO_INCREMENT NOT NULL,\n' +
'\t`userId` varchar(255) NOT NULL,\n' +
'\t`blockedUserId` varchar(255) NOT NULL,\n' +
'\t`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n' +
'\tCONSTRAINT `Blocked_id` PRIMARY KEY(`id`)\n' +
');\n',
sqlState: '42S01',
sqlMessage: "Table 'Blocked' already exists"
}
Want results from more Discord servers?
Add your server