forked from tovyblox/tovy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrateDatabase.mts
35 lines (31 loc) · 903 Bytes
/
migrateDatabase.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { exec } from "child_process";
import * as dotenv from 'dotenv'
dotenv.config()
if (process.env.MIGRATE_DATABASE_URL) {
const migrate = exec(`DATABASE_URL="${process.env.MIGRATE_DATABASE_URL}" npx prisma migrate deploy`);
migrate.stdout?.on("data", (data) => {
process.stdout.write(data);
});
//on error
migrate.on("close", (code) => {
process.stdout.write("Migrate exited with code " + code);
if (code !== 0) {
process.exit(1);
}
process.exit(0);
});
} else if (process.env.DATABASE_URL) {
const migrate = exec(`DATABASE_URL="${process.env.DATABASE_URL}" npx prisma migrate deploy`);
migrate.stdout?.on("data", (data) => {
process.stdout.write(data);
});
//on error
migrate.on("close", (code) => {
process.stdout.write("Migrate exited with code " + code);
if (code !== 0) {
process.exit(1);
}
});
} else {
throw new Error('No database url provided');
}