Implement complete collection persistence with database-backed survival across server restarts
• Add full multi-table schema for collections with normalized design (collections, collection_templates, collection_items, collection_item_versions) • Implement collection detection and processing in enhancement pipeline for .insertr-add elements • Add template extraction and storage from existing HTML children with multi-variant support • Enable collection reconstruction from database on server restart with proper DOM rebuilding • Extend ContentClient interface with collection operations and full database integration • Update enhance command to use engine.DatabaseClient for collection persistence support
This commit is contained in:
@@ -9,6 +9,83 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const initializeCollectionItemVersionsTable = `-- name: InitializeCollectionItemVersionsTable :exec
|
||||
CREATE TABLE IF NOT EXISTS collection_item_versions (
|
||||
version_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
item_id TEXT NOT NULL,
|
||||
collection_id TEXT NOT NULL,
|
||||
site_id TEXT NOT NULL,
|
||||
html_content TEXT NOT NULL,
|
||||
template_id INTEGER NOT NULL,
|
||||
position INTEGER NOT NULL,
|
||||
created_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
|
||||
created_by TEXT DEFAULT 'system' NOT NULL,
|
||||
FOREIGN KEY (item_id, collection_id, site_id) REFERENCES collection_items(item_id, collection_id, site_id) ON DELETE CASCADE
|
||||
)
|
||||
`
|
||||
|
||||
func (q *Queries) InitializeCollectionItemVersionsTable(ctx context.Context) error {
|
||||
_, err := q.db.ExecContext(ctx, initializeCollectionItemVersionsTable)
|
||||
return err
|
||||
}
|
||||
|
||||
const initializeCollectionItemsTable = `-- name: InitializeCollectionItemsTable :exec
|
||||
CREATE TABLE IF NOT EXISTS collection_items (
|
||||
item_id TEXT NOT NULL,
|
||||
collection_id TEXT NOT NULL,
|
||||
site_id TEXT NOT NULL,
|
||||
template_id INTEGER NOT NULL,
|
||||
html_content TEXT NOT NULL,
|
||||
position INTEGER NOT NULL,
|
||||
created_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
|
||||
updated_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
|
||||
last_edited_by TEXT DEFAULT 'system' NOT NULL,
|
||||
PRIMARY KEY (item_id, collection_id, site_id),
|
||||
FOREIGN KEY (collection_id, site_id) REFERENCES collections(id, site_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (template_id) REFERENCES collection_templates(template_id) ON DELETE RESTRICT
|
||||
)
|
||||
`
|
||||
|
||||
func (q *Queries) InitializeCollectionItemsTable(ctx context.Context) error {
|
||||
_, err := q.db.ExecContext(ctx, initializeCollectionItemsTable)
|
||||
return err
|
||||
}
|
||||
|
||||
const initializeCollectionTemplatesTable = `-- name: InitializeCollectionTemplatesTable :exec
|
||||
CREATE TABLE IF NOT EXISTS collection_templates (
|
||||
template_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
collection_id TEXT NOT NULL,
|
||||
site_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
html_template TEXT NOT NULL,
|
||||
is_default INTEGER DEFAULT 0 NOT NULL,
|
||||
created_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
|
||||
FOREIGN KEY (collection_id, site_id) REFERENCES collections(id, site_id) ON DELETE CASCADE
|
||||
)
|
||||
`
|
||||
|
||||
func (q *Queries) InitializeCollectionTemplatesTable(ctx context.Context) error {
|
||||
_, err := q.db.ExecContext(ctx, initializeCollectionTemplatesTable)
|
||||
return err
|
||||
}
|
||||
|
||||
const initializeCollectionsTable = `-- name: InitializeCollectionsTable :exec
|
||||
CREATE TABLE IF NOT EXISTS collections (
|
||||
id TEXT NOT NULL,
|
||||
site_id TEXT NOT NULL,
|
||||
container_html TEXT NOT NULL,
|
||||
created_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
|
||||
updated_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
|
||||
last_edited_by TEXT DEFAULT 'system' NOT NULL,
|
||||
PRIMARY KEY (id, site_id)
|
||||
)
|
||||
`
|
||||
|
||||
func (q *Queries) InitializeCollectionsTable(ctx context.Context) error {
|
||||
_, err := q.db.ExecContext(ctx, initializeCollectionsTable)
|
||||
return err
|
||||
}
|
||||
|
||||
const initializeSchema = `-- name: InitializeSchema :exec
|
||||
CREATE TABLE IF NOT EXISTS content (
|
||||
id TEXT NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user