fix: remove non-deterministic CHECK constraint from templates table

- SQLite doesn't allow datetime('now') in CHECK constraints
- Drop tables before recreating to ensure clean schema
- 6-month filtering is already handled in application logic
- Successfully fetched and stored 199 templates

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-06-20 00:08:28 +02:00
parent 08f9d1ad30
commit f038f72049
3 changed files with 11 additions and 5 deletions

View File

@@ -39,10 +39,7 @@ CREATE TABLE IF NOT EXISTS templates (
created_at DATETIME,
updated_at DATETIME,
url TEXT,
scraped_at DATETIME DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fresh_template CHECK (
datetime(updated_at) >= datetime('now', '-6 months')
)
scraped_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Templates indexes

View File

@@ -16,7 +16,16 @@ async function fetchTemplates() {
// Initialize database
const db = await createDatabaseAdapter('./data/nodes.db');
// Apply schema if needed
// Drop existing templates table to ensure clean schema
try {
db.exec('DROP TABLE IF EXISTS templates');
db.exec('DROP TABLE IF EXISTS templates_fts');
console.log('🗑️ Dropped existing templates tables\n');
} catch (error) {
// Ignore errors if tables don't exist
}
// Apply schema with updated constraint
const schema = fs.readFileSync(path.join(__dirname, '../../src/database/schema.sql'), 'utf8');
db.exec(schema);