Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions src/commands/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,30 @@ export const createDatabaseCommand = (program: BaseCommand) => {
'netlify database status --branch my-feature-branch',
])

dbCommand
.command('init')
.description('Deprecated: databases are auto-provisioned via `@netlify/database`')
.action(async (_options: Record<string, unknown>, _command: BaseCommand) => {
const { log, chalk } = await import('../../utils/command-helpers.js')

log()
log(
chalk.yellow(
'`netlify db init` is no longer available. Databases are now provisioned automatically when @netlify/database is detected in your project.',
),
)
log()
log('To get started, run:')
log(` ${chalk.cyan('npm install @netlify/database')}`)
Comment on lines +109 to +121

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | πŸ”΄ Critical

🧩 Analysis chain

🌐 Web query:

What is the current official npm package and install command for Netlify Database in Netlify CLI docs: @netlify/dbor@netlify/database?

πŸ’‘ Result:

There is no separate official npm package like @netlify/db or @netlify/database required for Netlify Database in the Netlify CLI docs. Netlify Database functionality is built into the Netlify CLI itself (npm package: netlify-cli), which provides the netlify db commands such as netlify db init and netlify db status for provisioning and managing the database. For local development, use npx netlify db init (which runs the latest netlify-cli without global install). Install Netlify CLI with npm install netlify-cli -g or npm install --save-dev netlify-cli for projects/CI. Optionally, for automatic database provisioning during builds, install @netlify/neon in your project: npm install @netlify/neon. This is not the core CLI package and was mentioned in beta docs; Netlify DB uses Neon Postgres under the hood.

Citations:


Replace the deprecated @netlify/database package with correct instructions.

The deprecation message directs users to install @netlify/database, but this package does not exist. According to official Netlify docs, the correct package for automatic database provisioning is @netlify/neon. Update lines 115–116 to install the correct package:

npm install `@netlify/neon`

Alternatively, if the intent is to simply inform users that the netlify db init command is deprecated without requiring a separate package installation (since Netlify Database is built into netlify-cli), adjust the message accordingly.

πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/database/database.ts` around lines 109 - 121, Update the
deprecation message in the `db init` command handler (the chained
.description/.action block) to stop recommending the non-existent
`@netlify/database` package: replace the install hint string currently using
`npm install `@netlify/database`` with `npm install `@netlify/neon`` (or remove the
install hint entirely if you prefer to only state deprecation); ensure the
change is made in the anonymous async action that constructs the log/chalk
messages so the displayed cyan install command is corrected.

log()
log(
`If you have an existing database from the Netlify DB extension, visit ${chalk.cyan(
'https://ntl.fyi/db-migration',
)} for migration instructions.`,
)
log()
})

dbCommand
.command('connect')
.description('Connect to the database')
Expand Down
11 changes: 11 additions & 0 deletions src/commands/database/legacy/db-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,15 @@ export const status = async (_options: OptionValues, command: BaseCommand) => {
unpooledDatabaseUrlEnv?.key === 'NETLIFY_DATABASE_URL_UNPOOLED' ? 'saved' : chalk.red('not set'),
}),
)

// Show deprecation warning if a legacy extension DB is detected
if (process.env.EXPERIMENTAL_NETLIFY_DB_ENABLED === '1' && databaseUrlEnv?.key === 'NETLIFY_DATABASE_URL') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Deprecation warning guard is unreachable in the current command wiring.

src/commands/database/database.ts registers ./legacy/db-status.js only in the EXPERIMENTAL_NETLIFY_DB_ENABLED !== '1' branch, so this === '1' check prevents the warning from ever showing on that path.

Suggested fix
-  if (process.env.EXPERIMENTAL_NETLIFY_DB_ENABLED === '1' && databaseUrlEnv?.key === 'NETLIFY_DATABASE_URL') {
+  if (databaseUrlEnv?.key === 'NETLIFY_DATABASE_URL') {
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (process.env.EXPERIMENTAL_NETLIFY_DB_ENABLED === '1' && databaseUrlEnv?.key === 'NETLIFY_DATABASE_URL') {
if (databaseUrlEnv?.key === 'NETLIFY_DATABASE_URL') {
πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/database/legacy/db-status.ts` at line 81, The deprecation guard
in src/commands/database/legacy/db-status.ts uses if
(process.env.EXPERIMENTAL_NETLIFY_DB_ENABLED === '1' && databaseUrlEnv?.key ===
'NETLIFY_DATABASE_URL') which is unreachable because this legacy command is only
registered when EXPERIMENTAL_NETLIFY_DB_ENABLED !== '1'; change the condition so
the warning runs when the legacy command is active (e.g., flip the env check to
!== '1' or remove the env check entirely and only test databaseUrlEnv?.key ===
'NETLIFY_DATABASE_URL') so the deprecation message is actually emitted by the
legacy db-status command.

log()
log(
chalk.yellow(
'Warning: This site has a database from the legacy Netlify DB extension, which has been deprecated. Netlify Database is now available as a built-in feature.',
),
)
log(`For migration instructions, visit ${chalk.cyan('https://ntl.fyi/db-migration')}`)
}
}
Loading