Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions src/commands/migrate/make.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CommonArgs } from '../../arguments/common.mjs'
import { assertExtension, ExtensionArg } from '../../arguments/extension.mjs'
import { createMigrationNameArg } from '../../arguments/migration-name.mjs'
import { getConfigOrFail } from '../../config/get-config.mjs'
import { usingKysely } from '../../kysely/using-kysely.mjs'
import { createSubcommand } from '../../utils/create-subcommand.mjs'
import { defineArgs } from '../../utils/define-args.mjs'
import { defineCommand } from '../../utils/define-command.mjs'
Expand All @@ -26,40 +27,42 @@ const Command = defineCommand(args, {

const config = await getConfigOrFail(args)

assertExtension(extension, config, 'migrations')
await usingKysely(config, async () => {
assertExtension(extension, config, 'migrations')

const { getMigrationPrefix, migrationFolder } = config.migrations
const { getMigrationPrefix, migrationFolder } = config.migrations

const wasMigrationsFolderCreated = Boolean(
await mkdir(migrationFolder, { recursive: true }),
)
const wasMigrationsFolderCreated = Boolean(
await mkdir(migrationFolder, { recursive: true }),
)

if (wasMigrationsFolderCreated) {
consola.debug('Migrations folder created')
}
if (wasMigrationsFolderCreated) {
consola.debug('Migrations folder created')
}

const filename = `${await getMigrationPrefix()}${
args.migration_name
}.${extension}`
const filename = `${await getMigrationPrefix()}${
args.migration_name
}.${extension}`

consola.debug('Filename:', filename)
consola.debug('Filename:', filename)

const filePath = join(migrationFolder, filename)
const filePath = join(migrationFolder, filename)

consola.debug('File path:', filePath)
consola.debug('File path:', filePath)

const templateExtension = await getTemplateExtension(extension)
const templateExtension = await getTemplateExtension(extension)

const templatePath = join(
__dirname,
`templates/migration-template.${templateExtension}`,
)
const templatePath = join(
__dirname,
`templates/migration-template.${templateExtension}`,
)

consola.debug('Template path:', templatePath)
consola.debug('Template path:', templatePath)

await copyFile(templatePath, filePath)
await copyFile(templatePath, filePath)

consola.success(`Created migration file at ${filePath}`)
consola.success(`Created migration file at ${filePath}`)
})
},
})

Expand Down