From 54a981cd5c653bfcc189b2e1d6d97d386ff50d29 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Sat, 3 Feb 2024 22:04:39 -0800 Subject: [PATCH] make it more clear when remove vs. local db is in use --- packages/db/src/core/integration/index.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/db/src/core/integration/index.ts b/packages/db/src/core/integration/index.ts index aafde4a069..23f195efe4 100644 --- a/packages/db/src/core/integration/index.ts +++ b/packages/db/src/core/integration/index.ts @@ -12,16 +12,17 @@ import { APP_TOKEN_ERROR, STUDIO_CONFIG_MISSING_WRITABLE_COLLECTIONS_ERROR } fro import { errorMap } from './error-map.js'; import { dirname } from 'path'; import { fileURLToPath } from 'url'; -import { bold } from 'kleur/colors'; +import { blue, yellow } from 'kleur/colors'; import { fileURLIntegration } from './file-url.js'; import { setupDbTables } from '../queries.js'; import { collectionToTable } from '../../runtime/index.js'; function astroDBIntegration(): AstroIntegration { + let connectedToRemote = false; return { name: 'astro:db', hooks: { - async 'astro:config:setup'({ logger, updateConfig, config, command }) { + 'astro:config:setup': async ({ logger, updateConfig, config, command }) => { if (command === 'preview') return; // TODO: refine where we load collections @@ -33,7 +34,9 @@ function astroDBIntegration(): AstroIntegration { const studio = configWithDb.db?.studio ?? false; const foundWritableCollection = Object.entries(collections).find(([, c]) => c.writable); if (!studio && foundWritableCollection) { - logger.error(STUDIO_CONFIG_MISSING_WRITABLE_COLLECTIONS_ERROR(foundWritableCollection[0])); + logger.error( + STUDIO_CONFIG_MISSING_WRITABLE_COLLECTIONS_ERROR(foundWritableCollection[0]) + ); process.exit(1); } @@ -44,6 +47,7 @@ function astroDBIntegration(): AstroIntegration { logger.error(APP_TOKEN_ERROR); process.exit(1); } + connectedToRemote = true; dbPlugin = vitePluginDb({ connectToStudio: true, collections, @@ -71,7 +75,7 @@ function astroDBIntegration(): AstroIntegration { mode: command === 'dev' ? 'dev' : 'build', useForeignKeys: true, }); - logger.info('Collections set up 🚀'); + logger.debug('Database setup complete.'); dbPlugin = vitePluginDb({ connectToStudio: false, @@ -103,6 +107,17 @@ function astroDBIntegration(): AstroIntegration { }); await typegen({ collections, root: config.root }); }, + 'astro:server:start': async ({ logger }) => { + // Wait for the server startup to log, so that this can come afterwards. + setTimeout(() => { + logger.info( + connectedToRemote ? 'Connected to remote database.' : 'New local database created.' + ); + }, 100); + }, + 'astro:build:start': async ({ logger }) => { + logger.info('database: ' + (connectedToRemote ? yellow('remote') : blue('local database.'))); + }, }, }; }