Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3c19e9c
fix: move recreateTables() to integration hooks
bholmesdev Apr 30, 2024
4427383
feat: recreate and seed at load, not in virtual runtime
bholmesdev Apr 30, 2024
333131b
feat: eager build db on startup and seed file change
bholmesdev Apr 30, 2024
2c6de6b
fix: respect database_file in dbUrl
bholmesdev Apr 30, 2024
56c4c97
chore: remove duplicate recreateTables call
bholmesdev Apr 30, 2024
82ad425
chore: remove now self-explanatory comments
bholmesdev Apr 30, 2024
a901140
fix: remove invalidateModule call for eager loading
bholmesdev Apr 30, 2024
69b1f77
feat: respect seed package paths
bholmesdev Apr 30, 2024
4abe41d
fix: remove duplicate recreateTables() call
bholmesdev Apr 30, 2024
1ed4c02
refactor: move recreateTables() to vite-plugin-db
bholmesdev Apr 30, 2024
4694c8e
refactor: move queries.ts from runtime/ to core/
bholmesdev Apr 30, 2024
98b1491
fix: update test import to core/queries
bholmesdev Apr 30, 2024
026062e
refactor: move executeSeedFile to vite-plugin-db
bholmesdev Apr 30, 2024
fe7a947
refactor: extract seeding and recreating to helper fns
bholmesdev Apr 30, 2024
c15b585
chore: changeset
bholmesdev Apr 30, 2024
533edb2
chore: revert connectToStudio refactor
bholmesdev Apr 30, 2024
d8b46db
wip: log db url
bholmesdev Apr 30, 2024
6f6fef2
fix(test): normalize astro_database_file flag for windows
bholmesdev Apr 30, 2024
01cca1c
Revert "wip: log db url"
bholmesdev Apr 30, 2024
53ed848
Revert "Revert "wip: log db url""
bholmesdev Apr 30, 2024
33747cb
fix: correctly resolve relative paths with unit test
bholmesdev Apr 30, 2024
a390dbd
chore: remove unused dbDirPath
bholmesdev May 1, 2024
f81cf8b
chore: remove unused import
bholmesdev May 1, 2024
9ba3d60
chore: remove unused type
bholmesdev May 1, 2024
1b41be4
fix: remove bad import
bholmesdev May 2, 2024
3b014fd
[db] Load seed files with vite dev server (#10941)
bholmesdev May 3, 2024
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
Next Next commit
fix: move recreateTables() to integration hooks
  • Loading branch information
bholmesdev committed May 2, 2024
commit 3c19e9cd5e05569eac09115d47098c8bd328a9ac
19 changes: 14 additions & 5 deletions packages/db/src/core/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { fileURLIntegration } from './file-url.js';
import { typegenInternal } from './typegen.js';
import { type LateSeedFiles, type LateTables, resolved, vitePluginDb } from './vite-plugin-db.js';
import { vitePluginInjectEnvTs } from './vite-plugin-inject-env-ts.js';
import { createLocalDatabaseClient } from '../../runtime/db-client.js';
import { recreateTables } from '../../runtime/seed-local.js';

function astroDBIntegration(): AstroIntegration {
let connectToStudio = false;
Expand Down Expand Up @@ -89,10 +91,14 @@ function astroDBIntegration(): AstroIntegration {
seedFiles.get = () => integrationSeedPaths;
configFileDependencies = dependencies;

const localDbUrl = new URL(DB_PATH, config.root);
if (!connectToStudio && !existsSync(localDbUrl)) {
await mkdir(dirname(fileURLToPath(localDbUrl)), { recursive: true });
await writeFile(localDbUrl, '');
if (!connectToStudio) {
const localDbUrl = new URL(DB_PATH, config.root);
if (!existsSync(localDbUrl)) {
await mkdir(dirname(fileURLToPath(localDbUrl)), { recursive: true });
await writeFile(localDbUrl, '');
}
const db = createLocalDatabaseClient({ dbUrl: localDbUrl.href });
await recreateTables({ db, tables: tables.get() ?? {} });
}

await typegenInternal({ tables: tables.get() ?? {}, root: config.root });
Expand Down Expand Up @@ -131,12 +137,15 @@ function astroDBIntegration(): AstroIntegration {
.map((s) => (typeof s === 'string' && s.startsWith('.') ? new URL(s, root) : s))
.filter((s): s is URL => s instanceof URL);
const eagerReloadSeedPaths = [...eagerReloadIntegrationSeedPaths, ...localSeedPaths];
server.watcher.on('all', (event, relativeEntry) => {
server.watcher.on('all', async (event, relativeEntry) => {
if (event === 'unlink' || event === 'unlinkDir') return;
// When a seed file changes, load manually
// to track when seeding finishes and log a message.
const entry = new URL(relativeEntry, root);
if (eagerReloadSeedPaths.find((path) => entry.href === path.href)) {
const localDbUrl = new URL(DB_PATH, root);
const db = createLocalDatabaseClient({ dbUrl: localDbUrl.href });
await recreateTables({ db, tables: tables.get() ?? {} });
loadSeedModule();
}
});
Expand Down
1 change: 0 additions & 1 deletion packages/db/src/runtime/seed-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export async function seedLocal({
userSeedGlob: Record<string, { default?: () => Promise<void> }>;
integrationSeedFunctions: Array<() => Promise<void>>;
}) {
await recreateTables({ db, tables });
const seedFunctions: Array<() => Promise<void>> = [];
const seedFilePath = Object.keys(userSeedGlob)[0];
if (seedFilePath) {
Expand Down