move migrateData into its own function
parent
b05b18e736
commit
ac2b79c5cf
|
@ -9,13 +9,25 @@ const prompts = require('prompts');
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
// function getDatabaseType(url = process.env.DATABASE_URL) {
|
||||||
|
// const type = process.env.DATABASE_TYPE || (url && url.split(':')[0]);
|
||||||
|
|
||||||
|
// if (type === 'postgres') {
|
||||||
|
// return 'postgresql';
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return type;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const databaseType = getDatabaseType();
|
||||||
|
|
||||||
function success(msg) {
|
function success(msg) {
|
||||||
console.log(chalk.greenBright(`✓ ${msg}`));
|
console.log(chalk.greenBright(`✓ ${msg}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
function error(msg) {
|
// function error(msg) {
|
||||||
console.log(chalk.redBright(`✗ ${msg}`));
|
// console.log(chalk.redBright(`✗ ${msg}`));
|
||||||
}
|
// }
|
||||||
|
|
||||||
async function checkEnv() {
|
async function checkEnv() {
|
||||||
if (!process.env.DATABASE_URL) {
|
if (!process.env.DATABASE_URL) {
|
||||||
|
@ -71,13 +83,16 @@ async function checkV2Tables() {
|
||||||
await runSqlFile('../prisma/migrations/01_init/migration.sql');
|
await runSqlFile('../prisma/migrations/01_init/migration.sql');
|
||||||
console.log(execSync('prisma migrate resolve --applied 01_init').toString());
|
console.log(execSync('prisma migrate resolve --applied 01_init').toString());
|
||||||
console.log(execSync('prisma migrate deploy').toString());
|
console.log(execSync('prisma migrate deploy').toString());
|
||||||
console.log(
|
|
||||||
'Starting v2 data migration. Please do no cancel this process, it may take a while.',
|
|
||||||
);
|
|
||||||
await runSqlFile('../db/postgresql/migration_v2.sql');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function migrateData() {
|
||||||
|
console.log('Starting v2 data migration. Please do no cancel this process, it may take a while.');
|
||||||
|
await runSqlFile('../db/postgresql/migration_v2.sql');
|
||||||
|
|
||||||
|
success('Data migration from V1 to V2 tables completed.');
|
||||||
|
}
|
||||||
|
|
||||||
async function dropV1Keys() {
|
async function dropV1Keys() {
|
||||||
try {
|
try {
|
||||||
// drop keys
|
// drop keys
|
||||||
|
@ -171,8 +186,7 @@ async function deleteV1Tables() {
|
||||||
|
|
||||||
success('Dropped v1 database tables.');
|
success('Dropped v1 database tables.');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error('Failed to drop v1 database tables.');
|
throw new Error('Failed to drop v1 database tables.');
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +217,14 @@ async function runSqlFile(filePath) {
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
let err = false;
|
let err = false;
|
||||||
for (let fn of [checkEnv, checkConnection, checkV1Tables, checkV2Tables, deleteV1TablesPrompt]) {
|
for (let fn of [
|
||||||
|
checkEnv,
|
||||||
|
checkConnection,
|
||||||
|
checkV1Tables,
|
||||||
|
checkV2Tables,
|
||||||
|
migrateData,
|
||||||
|
deleteV1TablesPrompt,
|
||||||
|
]) {
|
||||||
try {
|
try {
|
||||||
await fn();
|
await fn();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue