Skip to content

Commit

Permalink
fix: drop content tables to start local server with a clean state (#2859
Browse files Browse the repository at this point in the history
)
  • Loading branch information
larbish authored Nov 20, 2024
1 parent d4e46a7 commit aa4614d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ async function processCollectionItems(nuxt: Nuxt, collections: ResolvedCollectio
let filesCount = 0
let cachedFilesCount = 0
let parsedFilesCount = 0

// Remove all existing content collections to start with a clean state
db.dropContentTables()

// Create database dump
for await (const collection of collections) {
if (collection.name === 'info') {
Expand Down
5 changes: 5 additions & 0 deletions src/utils/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ export function localDatabase(databaseLocation: string) {
deleteDevelopmentCache(id: string) {
_localDatabase[databaseLocation]!.exec(`DELETE FROM _development_cache WHERE id = '${id}'`)
},
dropContentTables() {
return _localDatabase[databaseLocation]!.prepare<unknown[], { name: string }>(`SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE '_content_%'`)
.all()
.map(({ name }) => _localDatabase[databaseLocation]!.exec(`DROP TABLE IF EXISTS ${name}`))
},
exec: (sql: string) => {
_localDatabase[databaseLocation]!.exec(sql)
},
Expand Down

0 comments on commit aa4614d

Please sign in to comment.