Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { files, newLockFile, migrationId } = await lift.save(migration, name, preview)
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`
}
export async function ensureDatabaseExists(action: LiftAction, killInk: boolean, forceCreate: boolean = false) {
const datamodel = await getSchema()
const config = await getConfig({ datamodel })
const activeDatasource =
config.datasources.length === 1
? config.datasources[0]
: config.datasources.find(d => d.config.enabled === 'true') || config.datasources[0]
if (!activeDatasource) {
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