Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (migration.warnings && migration.warnings.length > 0) {
console.log(chalk.bold(`\n\nโ ๏ธ There might be data loss when applying the migration:\n`))
for (const warning of migration.warnings) {
console.log(chalk(` โข ${warning.description}`))
}
console.log()
}
if (preview) {
lift.stop()
return `\nRun ${chalk.greenBright('prisma lift save --name MIGRATION_NAME')} to create the migration\n`
}
await getSchema() // just to leverage on its error handling
const schemaDir = (await getSchemaDir())! // TODO: Probably getSchemaDir() should return Promise instead of Promise
const migrationsDir = path.join(schemaDir, 'migrations', migrationId)
await serializeFileMap(files, migrationsDir)
const lockFilePath = path.join(schemaDir, 'migrations', 'lift.lock')
await writeFile(lockFilePath, newLockFile)
lift.stop()
return `\nLift just created your migration ${printMigrationId(migrationId)} in\n\n${chalk.dim(
printFiles(`migrations/${migrationId}`, files),
)}\n\nRun ${chalk.greenBright('prisma2 lift up')} to apply the migration\n`
}
throw new Error(`Couldn't find a datasource in the schema.prisma file`)
}
const canConnect = await canConnectToDatabase(activeDatasource.url.value)
if (canConnect === true) {
return
}
const { code, message } = canConnect
if (code !== 'P1003') {
throw new Error(`${code}: ${message}`)
}
// last case: status === 'DatabaseDoesNotExist'
const schemaDir = await getSchemaDir()
if (!schemaDir) {
throw new Error(`Could not locate schema.prisma`)
}
if (forceCreate) {
await createDatabase(activeDatasource.url.value, schemaDir)
} else {
await interactivelyCreateDatabase(activeDatasource.url.value, action, schemaDir)
}
}
async function doesSqliteDbExist(connectionString: string): Promise {
let filePath = connectionString
if (filePath.startsWith('file:')) {
filePath = filePath.slice(5)
}
const cwd = await getSchemaDir()
if (!cwd) {
throw new Error(`Could not find schema.prisma in ${process.cwd()}`)
}
const absoluteTarget = path.resolve(cwd, filePath)
return exists(absoluteTarget)
}