Skip to content

feat: Add db init and db status commands #7115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

CalebBarnes
Copy link

@CalebBarnes CalebBarnes commented Mar 20, 2025

Summary

This PR introduces a new db command to the Netlify CLI, enabling users to provision and manage production-ready Postgres databases with minimal effort.

Features

  • Adds netlify db command with two primary subcommands:

    • db init - Initialize a new database and connects it to the current site
    • db status - Check the status of the database connection
  • Seamless integration with Drizzle ORM:

    • Optional initialization of Drizzle configuration and schema boilerplate
    • Adds helpful database scripts to package.json
    • Auto-installs required Drizzle dependencies
  • Flexible setup options:

    • Interactive mode with prompts for setup preferences
    • --minimal flag for non-interactive setup (ideal for CI/AI tools)
    • --drizzle / --no-drizzle flags to control ORM setup
    • --overwrite option to replace existing boilerplate files

Example Usage

# Initialize a database with interactive prompts
netlify db init

# Check database connection status
netlify db status

# Non-interactive setup for AI agents or CI environments
netlify db init --minimal

# Initialize with Drizzle ORM and overwrite existing files
netlify db init --drizzle --overwrite

The implementation automatically handles extension installation, creating a database, and connecting it to the site via environment variables.

Documentation Generation Enhancement

I expanded the CLI documentation generator to support subcommands more robustly. Previously, subcommand docs were only generated if the command name contained a colon (:), such as dev:exec, which would be treated as a subcommand of dev. This approach missed subcommands defined as nested classes or those with explicit parent references.

Now, the docs generator also recognizes subcommands by checking the command's parent property, allowing it to correctly generate documentation for subcommands like those under the new db command without relying solely on colon-separated naming.


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

Copy link

github-actions bot commented Mar 20, 2025

📊 Benchmark results

Comparing with 795a451

  • Dependency count: 1,150 (no change)
  • Package size: 280 MB ⬇️ 0.00% decrease vs. 795a451
  • Number of ts-expect-error directives: 392 ⬆️ 0.51% increase vs. 795a451

@khendrikse
Copy link
Contributor

We could add logic that if we notice that the site is not linked yet, we ask them if they want to do that, if they say yes we continue into that workflow?

@khendrikse khendrikse force-pushed the feat/netlify-database-command branch from 4fc477a to bd11f72 Compare April 9, 2025 14:02
@CalebBarnes CalebBarnes force-pushed the feat/netlify-database-command branch from 0f307a0 to 1cf19cb Compare May 2, 2025 20:01
@CalebBarnes CalebBarnes marked this pull request as ready for review May 2, 2025 20:04
@CalebBarnes CalebBarnes requested a review from a team as a code owner May 2, 2025 20:04
@CalebBarnes CalebBarnes requested a review from a team as a code owner May 2, 2025 23:09
@CalebBarnes CalebBarnes changed the title feat: database init command feat: Add db init and db status commands May 2, 2025
CalebBarnes and others added 17 commits May 2, 2025 16:23
…unused function / add --yes option to use defaults and --overwrite to overwrite files
* feat: add local dev branch option

* add UNPOOLED env to db status command

* add nf-db-user-id to req headers and update endpoint url

* fix name for NETLIFY_DATABASE_URL_UNPOOLED

* update NEON_DATABASE_EXTENSION_SLUG to 'neon' and remove NETLIFY_WEB_UI constant

* remove dev command and dev-branch.ts

* init: remove/replace headers for Nf-UIExt headers / remove dev branch questions

* update getExtension, installExtension to call jigsaw directly instead of calling react ui endpoints

* token -> netlifyToken

* drizzle - fixes/cleanup & remove dev branch config

* remove localDevBranch from Answers type

---------

Co-authored-by: Karin <=>
@CalebBarnes CalebBarnes force-pushed the feat/netlify-database-command branch from da4a73c to f4a9e6a Compare May 2, 2025 23:23
- if db already connected, we just say its connected and continue to log
the status
- improve status by fetching cli-db-status extension endpoint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants