Refactor drizzle and db folder

This commit is contained in:
Jared Palmer 2024-11-15 10:13:21 -05:00
parent e96dfb2d74
commit c493ac342b
31 changed files with 22 additions and 23 deletions

32
lib/db/migrate.ts Normal file
View file

@ -0,0 +1,32 @@
import { config } from 'dotenv';
import { drizzle } from 'drizzle-orm/postgres-js';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';
config({
path: '.env.local',
});
const runMigrate = async () => {
if (!process.env.POSTGRES_URL) {
throw new Error('POSTGRES_URL is not defined');
}
const connection = postgres(process.env.POSTGRES_URL, { max: 1 });
const db = drizzle(connection);
console.log('⏳ Running migrations...');
const start = Date.now();
await migrate(db, { migrationsFolder: './lib/drizzle' });
const end = Date.now();
console.log('✅ Migrations completed in', end - start, 'ms');
process.exit(0);
};
runMigrate().catch((err) => {
console.error('❌ Migration failed');
console.error(err);
process.exit(1);
});