Skip to content
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

fix: drop content tables to start local server with a clean state #2859

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -236,7 +236,7 @@
}

const _localDatabase: Record<string, Database.Database | undefined> = {}
export function localDatabase(databaseLocation: string) {

Check failure on line 239 in src/utils/dev.ts

View workflow job for this annotation

GitHub Actions / ubuntu

Return type of exported function has or is using name 'BetterSqlite3.Database' from external module "/home/runner/work/content/content/node_modules/.pnpm/@types[email protected]/node_modules/@types/better-sqlite3/index" but cannot be named.
if (!_localDatabase[databaseLocation]) {
_localDatabase[databaseLocation] = Database(databaseLocation)
_localDatabase[databaseLocation]!.exec('CREATE TABLE IF NOT EXISTS _development_cache (id TEXT PRIMARY KEY, checksum TEXT, parsedContent TEXT)')
Expand All @@ -259,6 +259,11 @@
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
Loading