8000 feat: Add `db init` and `db status` commands by CalebBarnes · Pull Request #7115 · netlify/cli · GitHub
[go: up one dir, main page]

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

Merged
merged 33 commits into from
Jun 5, 2025
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a33288e
POC adding database init command / drizzle-kit as an external subcommand
Mar 20, 2025
fffd673
cleanup
Mar 20, 2025
4f44728
cleanup
Mar 24, 2025
759fccb
fix awaiting drizzle deps installing / add status check and getSiteCo…
Mar 24, 2025
dd1699d
fix request headers for init endpoint / misc cleanup
Mar 25, 2025
107faf7
only inquirer.prompt if initialOpts.drizzle is not explicitly passed …
Mar 25, 2025
2fd7ca0
move urls to constants with env overrides / cleanup logging / remove …
Mar 25, 2025
b9e566d
remove commented unused call to get site
Mar 25, 2025
5b08ee3
remove unnecessary check
Mar 25, 2025
115e19f
fix: change slug into the neon slug
May 1, 2025
c4155cd
Update db init command (#7257)
May 2, 2025
c0459ac
update db command help text
May 2, 2025
f30f195
update command descriptions and examples
May 2, 2025
836fd29
update help command snapshot
May 2, 2025
254cc6d
support docs gen for sub commands without ":"
May 2, 2025
9085a8f
docs gen for db commands
May 2, 2025
dbb78c7
remove "yes" flag and add "minimal" flag
May 2, 2025
e151484
improve db init ux - dont throw error on CONFLICT (db already connected)
May 5, 2025
cadddbc
install @netlify/neon package if not found in package.json
May 14, 2025
6ba266a
use same package json path
May 20, 2025
a2d9483
move neon package installation to end to avoid incorrect 8000 overwriting
May 20, 2025
255457f
add comment to drizzle config boilerplate for context
May 20, 2025
191fc80
Merge branch 'main' into feat/netlify-database-command
May 21, 2025
41d0739
fix: initDrizzle - fallback to command.project.baseDirectory when com…
CalebBarnes Jun 4, 2025
b382c46
perf: lazy-load `netlify db` commands
ndhoule Jun 4, 2025
144d8b1
Update src/commands/database/constants.ts
ndhoule Jun 4, 2025
d8060f3
feat: get user to initialize site first if they have neon installed f…
sarahetter Jun 5, 2025
0a99fba
feat: rename --minimal => --assume-no, --drizzle => --boilerplate=<type>
ndhoule Jun 5, 2025
33475e2
docs: update docs with new db flags
ndhoule Jun 5, 2025
d819f71
fix: update db init example to not use --minimal
ndhoule Jun 5, 2025
a05e85f
docs: regenerate docs again
ndhoule Jun 5, 2025
a0a71f0
Merge branch 'main' into feat/netlify-database-command
khendrikse Jun 5, 2025
501bb66
Merge branch 'main' into feat/netlify-database-command
khendrikse Jun 5, 2025
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
Prev Previous commit
Next Next commit
improve db init ux - dont throw error on CONFLICT (db already connected)
- if db already connected, we just say its connected and continue to log
the status
- improve status by fetching cli-db-status extension endpoint
  • Loading branch information
Caleb Barnes committed May 20, 2025
commit e151484c711d247b1e43d435ec9e7ebf73ce062d
41 changes: 31 additions & 10 deletions src/commands/database/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,48 @@ export const init = async (_options: OptionValues, command: BaseCommand) => {
code?: string
message?: string
}
throw new Error(`Failed to initialize DB: ${error.message ?? 'Unknown error occurred'}`)
if (error.code === 'CONFLICT') {
log(`Database already connected to this site. Skipping initialization.`)
} else {
throw new Error(`Failed to initialize DB: ${error.message ?? 'Unknown error occurred'}`)
}
}

const res = (await req.json()) as {
code?: string
message?: string
}
let status

if (res.code !== 'DATABASE_INITIALIZED') {
throw new Error(`Failed to initialize DB: ${res.message ?? 'Unknown error'}`)
try {
const statusEndpoint = new URL('/api/cli-db-status', hostSiteUrl).toString()
const statusRes = await fetch(statusEndpoint, {
headers,
})
if (!statusRes.ok) {
throw new Error(`Failed to get database status`, { cause: statusRes })
}
status = (await statusRes.json()) as {
siteConfiguration?: {
connectedDatabase?: {
isConnected: boolean
}
}
existingManagedEnvs?: string[]
}
} catch (e) {
console.error('Failed to get database status', e)
}

log(
prettyjson.render({
'Current team': account.name,
'Current site': siteInfo.name,
[`${extension.name} extension`]: 'installed on team',
['Database status']: 'connected to site',
['Database status']: status?.siteConfiguration?.connectedDatabase?.isConnected
? 'connected to site'
: 'not connected',
['Environment variables']: '',
[' NETLIFY_DATABASE_URL']: 'saved',
[' NETLIFY_DATABASE_URL_UNPOOLED']: 'saved',
[' NETLIFY_DATABASE_URL']: status?.existingManagedEnvs?.includes('NETLIFY_DATABASE_URL') ? 'saved' : 'not set',
[' NETLIFY_DATABASE_URL_UNPOOLED']: status?.existingManagedEnvs?.includes('NETLIFY_DATABASE_URL_UNPOOLED')
? 'saved'
: 'not set',
}),
)
return
Expand Down
0