Skip to content

Commit 02bc375

Browse files
committed
chore: wip
1 parent 082a6f8 commit 02bc375

File tree

13 files changed

+66
-53
lines changed

13 files changed

+66
-53
lines changed

.stacks/buddy/src/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { command, log } from '@stacksjs/cli'
44
import { env, frameworkVersion, isProjectCreated } from '@stacksjs/utils'
55
import { projectPath } from '@stacksjs/path'
66
import { Action } from '@stacksjs/types'
7-
import { build, changelog, clean, commit, create, dev, example, fresh, generate, key, lint, make, preinstall, prepublish, release, setup, test, update } from './commands'
7+
import { build, changelog, clean, commit, create, dev, example, fresh, generate, key, lint, make, migrate, preinstall, prepublish, release, setup, test, update } from './commands'
88

99
const cli = command('stacks')
1010

@@ -49,6 +49,7 @@ async function main() {
4949
await lint(cli)
5050
await release(cli)
5151
await make(cli)
52+
await migrate(cli)
5253
await example(cli)
5354
await test(cli)
5455

.stacks/buddy/src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export * from './generate'
1010
export * from './lint'
1111
export * from './key'
1212
export * from './make'
13+
export * from './migrate'
1314
export * from './onboarding'
1415
export * from './prepublish'
1516
export * from './preinstall'

.stacks/buddy/src/commands/make.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ExitCode } from '@stacksjs/types'
22
import type { CLI, MakeOptions } from '@stacksjs/types'
3-
import { intro, italic, log, outro, prompts } from '@stacksjs/cli'
4-
3+
import { intro, italic, log, outro, prompts, runCommand } from '@stacksjs/cli'
4+
import { projectPath } from '@stacksjs/path'
55
import {
66
createModel,
77
createNotification,
@@ -11,7 +11,6 @@ import {
1111
factory as makeFactory,
1212
fx as makeFunction,
1313
language as makeLanguage,
14-
migration as makeMigration,
1514
page as makePage,
1615
stack as makeStack,
1716

@@ -115,23 +114,6 @@ async function make(buddy: CLI) {
115114
await makeDatabase(options)
116115
})
117116

118-
buddy
119-
.command('make:migration', descriptions.migration)
120-
.option('-n, --name', 'The name of the migration')
121-
.option('--verbose', descriptions.verbose, { default: false })
122-
.option('--debug', descriptions.debug, { default: false })
123-
.action(async (options: MakeOptions) => {
124-
const name = buddy.args[0] || options.name
125-
options.name = name
126-
127-
if (!name) {
128-
log.error('You need to specify a name. Read more about the documentation here.')
129-
process.exit()
130-
}
131-
132-
await makeMigration(options)
133-
})
134-
135117
buddy
136118
.command('make:factory', descriptions.factory)
137119
.option('-n, --name', 'The name of the factory')
@@ -253,6 +235,24 @@ async function make(buddy: CLI) {
253235

254236
await createModel(options)
255237
})
238+
239+
buddy
240+
.command('make:migration', descriptions.migration)
241+
.option('-n, --name', 'The name of the migration')
242+
.option('-e, --env', 'The environment to run the migration in', { default: 'dev' })
243+
.action(async (options: MakeOptions) => {
244+
const path = `${projectPath()}/.stacks/database/schema.prisma`
245+
const name = buddy.args[0] || options.name
246+
options.name = name
247+
248+
if (!name) {
249+
log.error('You need to specify the migration name')
250+
process.exit()
251+
}
252+
253+
await runCommand(`npx prisma migrate ${options.env} --name=${name} --schema=${path}`)
254+
log.success(path, name)
255+
})
256256
}
257257

258258
function hasNoOptions(options: MakeOptions) {

.stacks/buddy/src/commands/migrate.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { CLI } from '@stacksjs/types'
2+
import { log, runCommand } from '@stacksjs/cli'
3+
import { projectPath } from '@stacksjs/path'
4+
5+
async function migrate(buddy: CLI) {
6+
const descriptions = {
7+
init: 'Initialize Migration',
8+
lintFix: 'Automagically fixes all lint errors',
9+
verbose: 'Enable verbose output',
10+
debug: 'Enable debug mode',
11+
}
12+
13+
buddy
14+
.command('migrate:init', descriptions.init)
15+
.action(async () => {
16+
const path = `${projectPath()}/.stacks/database/schema.prisma`
17+
18+
await runCommand(`npx prisma migrate init --schema=${path}`)
19+
20+
log.success('Migration initialized successfully')
21+
})
22+
}
23+
24+
export { migrate }

.stacks/core/actions/src/generate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,7 @@ export async function migrations() {
124124

125125
await migrate(path, { database: 'postgresql' })
126126

127-
await runCommand(`npx prisma migrate --schema=${path}`) // run this command to generate the migrations..
127+
await runCommand(`npx prisma migrate --schema=${path}`)
128+
129+
log.success('Successfully updated migrations')
128130
}

.stacks/core/database-v2/src/factory.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

.stacks/core/database-v2/src/index.ts

Whitespace-only changes.

.stacks/core/database-v2/src/migrate.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

.stacks/core/database-v2/src/seed.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)