Build a Finance SaaS Platform -16 (Change to Local PG database)

Background

Neon is too slow and sometime can not reach, I decided to change to Local database

BTW, I tried to switch to Mysql but failed, too differences with PG. So, I still use PG.

Don’t use edge

Modify app/api/[[…route]]/route.ts:

1
2
3
...
// export const runtime = 'edge'
...

Change Connenct String

Modify db/drizzle.ts

1
2
3
4
5
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';

export const sql = postgres(process.env.DATABASE_URL!);
export const db = drizzle(sql);

Modify scripts/migrate.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

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 sql = postgres(process.env.DATABASE_URL!);
const db = drizzle(sql);

const main = async () => {""
try {
await migrate(db, { migrationsFolder: "drizzle" });
} catch (error) {
console.error("Error during migration:", error );
process.exit();
}
};

main();

请我喝杯咖啡吧~

支付宝
微信