Skip to content

Commit 2d91bd9

Browse files
committed
feat: Enhances project info command output
Adds detailed database connection information to the `project-info` command, including host, port, user, and database name. It also checks for the existence of the migrations table and displays applied migrations, improving the debugging and setup experience.
1 parent 41cb690 commit 2d91bd9

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/cli/project-info.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { defineCommand } from 'citty'
22
import { loadNuxt } from '@nuxt/kit'
33
import type { ModuleOptions } from 'nuxt-users/utils'
4+
import { useDb, checkTableExists } from '../runtime/server/utils/db'
5+
import { getAppliedMigrations } from '../runtime/server/utils/migrate'
46

57
export default defineCommand({
68
meta: {
@@ -21,9 +23,52 @@ export default defineCommand({
2123
if (nuxtUsersConfig) {
2224
console.log('[Nuxt Users] 🔧 Nuxt Users module configuration:')
2325
console.log('[Nuxt Users] Database connector:', nuxtUsersConfig.connector?.name)
26+
27+
// Display database connection details (excluding password)
28+
if (nuxtUsersConfig.connector?.options) {
29+
const options = nuxtUsersConfig.connector.options
30+
if (options.host) {
31+
console.log('[Nuxt Users] Database host:', options.host)
32+
}
33+
if (options.port) {
34+
console.log('[Nuxt Users] Database port:', options.port)
35+
}
36+
if (options.user) {
37+
console.log('[Nuxt Users] Database user:', options.user)
38+
}
39+
if (options.database) {
40+
console.log('[Nuxt Users] Database name:', options.database)
41+
}
42+
if (options.path) {
43+
console.log('[Nuxt Users] Database path:', options.path)
44+
}
45+
}
46+
2447
console.log('[Nuxt Users] Users table:', nuxtUsersConfig.tables?.users)
2548
console.log('[Nuxt Users] Personal access tokens table:', nuxtUsersConfig.tables?.personalAccessTokens)
2649
console.log('[Nuxt Users] Password reset tokens table:', nuxtUsersConfig.tables?.passwordResetTokens)
50+
51+
// Check migrations table
52+
try {
53+
const migrationsTableExists = await checkTableExists(nuxtUsersConfig, 'migrations')
54+
if (migrationsTableExists) {
55+
const appliedMigrations = await getAppliedMigrations(nuxtUsersConfig)
56+
console.log('[Nuxt Users] 📊 Migrations:')
57+
console.log('[Nuxt Users] Migrations table exists: ✅')
58+
console.log('[Nuxt Users] Applied migrations count:', appliedMigrations.length)
59+
if (appliedMigrations.length > 0) {
60+
console.log('[Nuxt Users] Applied migrations:', appliedMigrations.join(', '))
61+
}
62+
}
63+
else {
64+
console.log('[Nuxt Users] 📊 Migrations:')
65+
console.log('[Nuxt Users] Migrations table exists: ❌')
66+
console.log('[Nuxt Users] Run "npx nuxt-users migrate" to set up the database')
67+
}
68+
}
69+
catch (error) {
70+
console.log('[Nuxt Users] ⚠️ Could not check migrations:', error instanceof Error ? error.message : 'Unknown error')
71+
}
2772
}
2873
else {
2974
console.log('[Nuxt Users] ⚠️ Nuxt Users module not configured in runtime config')

0 commit comments

Comments
 (0)