Skip to content

Commit c28ffa3

Browse files
authored
feat: re-structure db commands (#8137)
1 parent be7538b commit c28ffa3

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

src/commands/database/database.ts

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -30,55 +30,55 @@ export const createDatabaseCommand = (program: BaseCommand) => {
3030
.description(`Provision a production ready Postgres database with a single command`)
3131
.addExamples([
3232
'netlify db status',
33-
'netlify db init',
34-
'netlify db init --help',
3533
...(process.env.EXPERIMENTAL_NETLIFY_DB_ENABLED === '1'
36-
? ['netlify db migrate', 'netlify db reset', 'netlify db migration new']
37-
: []),
34+
? ['netlify db migrations apply', 'netlify db reset', 'netlify db migrations new']
35+
: ['netlify db init', 'netlify db init --help']),
3836
])
3937

40-
dbCommand
41-
.command('init')
42-
.description(`Initialize a new database for the current site`)
43-
.option(
44-
'--assume-no',
45-
'Non-interactive setup. Does not initialize any third-party tools/boilerplate. Ideal for CI environments or AI tools.',
46-
false,
47-
)
48-
.addOption(
49-
new Option('--boilerplate <tool>', 'Type of boilerplate to add to your project.').choices(
50-
Array.from(supportedBoilerplates).sort(),
51-
),
52-
)
53-
.option('--no-boilerplate', "Don't add any boilerplate to your project.")
54-
.option('-o, --overwrite', 'Overwrites existing files that would be created when setting up boilerplate')
55-
.action(async (_options: Record<string, unknown>, command: BaseCommand) => {
56-
const { init } = await import('./init.js')
38+
if (process.env.EXPERIMENTAL_NETLIFY_DB_ENABLED !== '1') {
39+
dbCommand
40+
.command('init')
41+
.description(`Initialize a new database for the current site`)
42+
.option(
43+
'--assume-no',
44+
'Non-interactive setup. Does not initialize any third-party tools/boilerplate. Ideal for CI environments or AI tools.',
45+
false,
46+
)
47+
.addOption(
48+
new Option('--boilerplate <tool>', 'Type of boilerplate to add to your project.').choices(
49+
Array.from(supportedBoilerplates).sort(),
50+
),
51+
)
52+
.option('--no-boilerplate', "Don't add any boilerplate to your project.")
53+
.option('-o, --overwrite', 'Overwrites existing files that would be created when setting up boilerplate')
54+
.action(async (_options: Record<string, unknown>, command: BaseCommand) => {
55+
const { init } = await import('./init.js')
5756

58-
// Only prompt for drizzle if the user did not specify a boilerplate option, and if we're in
59-
// interactive mode
60-
if (_options.boilerplate === undefined && !_options.assumeNo) {
61-
const answers = await inquirer.prompt<{ useDrizzle: boolean }>([
62-
{
63-
type: 'confirm',
64-
name: 'useDrizzle',
65-
message: 'Set up Drizzle boilerplate?',
66-
},
67-
])
68-
if (answers.useDrizzle) {
69-
command.setOptionValue('boilerplate', 'drizzle')
57+
// Only prompt for drizzle if the user did not specify a boilerplate option, and if we're in
58+
// interactive mode
59+
if (_options.boilerplate === undefined && !_options.assumeNo) {
60+
const answers = await inquirer.prompt<{ useDrizzle: boolean }>([
61+
{
62+
type: 'confirm',
63+
name: 'useDrizzle',
64+
message: 'Set up Drizzle boilerplate?',
65+
},
66+
])
67+
if (answers.useDrizzle) {
68+
command.setOptionValue('boilerplate', 'drizzle')
69+
}
7070
}
71-
}
7271

73-
const options = _options as DatabaseInitOptions
74-
if (options.assumeNo) {
75-
options.boilerplate = false
76-
options.overwrite = false
77-
}
72+
const options = _options as DatabaseInitOptions
73+
if (options.assumeNo) {
74+
options.boilerplate = false
75+
options.overwrite = false
76+
}
7877

79-
await init(options, command)
80-
})
81-
.addExamples([`netlify db init --assume-no`, `netlify db init --boilerplate=drizzle --overwrite`])
78+
await init(options, command)
79+
})
80+
.addExamples([`netlify db init --assume-no`, `netlify db init --boilerplate=drizzle --overwrite`])
81+
}
8282

8383
dbCommand
8484
.command('status')
@@ -109,16 +109,6 @@ export const createDatabaseCommand = (program: BaseCommand) => {
109109
'netlify db connect --json',
110110
])
111111

112-
dbCommand
113-
.command('migrate')
114-
.description('Apply database migrations to the local development database')
115-
.option('--to <name>', 'Target migration name or prefix to apply up to (applies all if omitted)')
116-
.option('--json', 'Output result as JSON')
117-
.action(async (options: { to?: string; json?: boolean }, command: BaseCommand) => {
118-
const { migrate } = await import('./migrate.js')
119-
await migrate(options, command)
120-
})
121-
122112
dbCommand
123113
.command('reset')
124114
.description('Reset the local development database, removing all data and tables')
@@ -128,9 +118,19 @@ export const createDatabaseCommand = (program: BaseCommand) => {
128118
await reset(options, command)
129119
})
130120

131-
const migrationCommand = dbCommand.command('migration').description('Manage database migrations')
121+
const migrationsCommand = dbCommand.command('migrations').description('Manage database migrations')
122+
123+
migrationsCommand
124+
.command('apply')
125+
.description('Apply database migrations to the local development database')
126+
.option('--to <name>', 'Target migration name or prefix to apply up to (applies all if omitted)')
127+
.option('--json', 'Output result as JSON')
128+
.action(async (options: { to?: string; json?: boolean }, command: BaseCommand) => {
129+
const { migrate } = await import('./migrate.js')
130+
await migrate(options, command)
131+
})
132132

133-
migrationCommand
133+
migrationsCommand
134134
.command('new')
135135
.description('Create a new migration')
136136
.option('-d, --description <description>', 'Purpose of the migration (used to generate the file name)')
@@ -146,8 +146,8 @@ export const createDatabaseCommand = (program: BaseCommand) => {
146146
await migrationNew(options, command)
147147
})
148148
.addExamples([
149-
'netlify db migration new',
150-
'netlify db migration new --description "add users table" --scheme sequential',
149+
'netlify db migrations new',
150+
'netlify db migrations new --description "add users table" --scheme sequential',
151151
])
152152
}
153153
}

0 commit comments

Comments
 (0)