// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.30.0 // source: setup.sql package postgresql import ( "context" ) const createCollectionItemVersionsLookupIndex = `-- name: CreateCollectionItemVersionsLookupIndex :exec CREATE INDEX IF NOT EXISTS idx_collection_item_versions_lookup ON collection_item_versions(item_id, collection_id, site_id, created_at DESC) ` func (q *Queries) CreateCollectionItemVersionsLookupIndex(ctx context.Context) error { _, err := q.db.ExecContext(ctx, createCollectionItemVersionsLookupIndex) return err } const createCollectionItemsLookupIndex = `-- name: CreateCollectionItemsLookupIndex :exec CREATE INDEX IF NOT EXISTS idx_collection_items_lookup ON collection_items(collection_id, site_id, position) ` func (q *Queries) CreateCollectionItemsLookupIndex(ctx context.Context) error { _, err := q.db.ExecContext(ctx, createCollectionItemsLookupIndex) return err } const createCollectionItemsTemplateIndex = `-- name: CreateCollectionItemsTemplateIndex :exec CREATE INDEX IF NOT EXISTS idx_collection_items_template ON collection_items(template_id) ` func (q *Queries) CreateCollectionItemsTemplateIndex(ctx context.Context) error { _, err := q.db.ExecContext(ctx, createCollectionItemsTemplateIndex) return err } const createCollectionTemplatesDefaultIndex = `-- name: CreateCollectionTemplatesDefaultIndex :exec CREATE INDEX IF NOT EXISTS idx_collection_templates_default ON collection_templates(collection_id, site_id, is_default DESC) ` func (q *Queries) CreateCollectionTemplatesDefaultIndex(ctx context.Context) error { _, err := q.db.ExecContext(ctx, createCollectionTemplatesDefaultIndex) return err } const createCollectionTemplatesLookupIndex = `-- name: CreateCollectionTemplatesLookupIndex :exec CREATE INDEX IF NOT EXISTS idx_collection_templates_lookup ON collection_templates(collection_id, site_id) ` func (q *Queries) CreateCollectionTemplatesLookupIndex(ctx context.Context) error { _, err := q.db.ExecContext(ctx, createCollectionTemplatesLookupIndex) return err } const createCollectionTemplatesOneDefaultIndex = `-- name: CreateCollectionTemplatesOneDefaultIndex :exec CREATE UNIQUE INDEX IF NOT EXISTS idx_collection_templates_one_default ON collection_templates(collection_id, site_id) WHERE is_default = TRUE ` func (q *Queries) CreateCollectionTemplatesOneDefaultIndex(ctx context.Context) error { _, err := q.db.ExecContext(ctx, createCollectionTemplatesOneDefaultIndex) return err } const createCollectionsSiteIndex = `-- name: CreateCollectionsSiteIndex :exec CREATE INDEX IF NOT EXISTS idx_collections_site_id ON collections(site_id) ` func (q *Queries) CreateCollectionsSiteIndex(ctx context.Context) error { _, err := q.db.ExecContext(ctx, createCollectionsSiteIndex) return err } const createCollectionsUpdatedAtIndex = `-- name: CreateCollectionsUpdatedAtIndex :exec CREATE INDEX IF NOT EXISTS idx_collections_updated_at ON collections(updated_at) ` func (q *Queries) CreateCollectionsUpdatedAtIndex(ctx context.Context) error { _, err := q.db.ExecContext(ctx, createCollectionsUpdatedAtIndex) return err } const createContentSiteIndex = `-- name: CreateContentSiteIndex :exec CREATE INDEX IF NOT EXISTS idx_content_site_id ON content(site_id) ` func (q *Queries) CreateContentSiteIndex(ctx context.Context) error { _, err := q.db.ExecContext(ctx, createContentSiteIndex) return err } const createContentUpdatedAtIndex = `-- name: CreateContentUpdatedAtIndex :exec CREATE INDEX IF NOT EXISTS idx_content_updated_at ON content(updated_at) ` func (q *Queries) CreateContentUpdatedAtIndex(ctx context.Context) error { _, err := q.db.ExecContext(ctx, createContentUpdatedAtIndex) return err } const createUpdateFunction = `-- name: CreateUpdateFunction :exec CREATE OR REPLACE FUNCTION update_content_timestamp() RETURNS TRIGGER AS $$ BEGIN NEW.updated_at = EXTRACT(EPOCH FROM NOW()); RETURN NEW; END; $$ LANGUAGE plpgsql ` func (q *Queries) CreateUpdateFunction(ctx context.Context) error { _, err := q.db.ExecContext(ctx, createUpdateFunction) return err } const createVersionsLookupIndex = `-- name: CreateVersionsLookupIndex :exec CREATE INDEX IF NOT EXISTS idx_content_versions_lookup ON content_versions(content_id, site_id, created_at DESC) ` func (q *Queries) CreateVersionsLookupIndex(ctx context.Context) error { _, err := q.db.ExecContext(ctx, createVersionsLookupIndex) return err } const initializeCollectionItemVersionsTable = `-- name: InitializeCollectionItemVersionsTable :exec CREATE TABLE IF NOT EXISTS collection_item_versions ( version_id SERIAL PRIMARY KEY, 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 BIGINT DEFAULT (EXTRACT(EPOCH FROM 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 BIGINT DEFAULT (EXTRACT(EPOCH FROM NOW())) NOT NULL, updated_at BIGINT DEFAULT (EXTRACT(EPOCH FROM 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 SERIAL PRIMARY KEY, collection_id TEXT NOT NULL, site_id TEXT NOT NULL, name TEXT NOT NULL, html_template TEXT NOT NULL, is_default BOOLEAN DEFAULT FALSE NOT NULL, created_at BIGINT DEFAULT (EXTRACT(EPOCH FROM 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 BIGINT DEFAULT (EXTRACT(EPOCH FROM NOW())) NOT NULL, updated_at BIGINT DEFAULT (EXTRACT(EPOCH FROM 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, site_id TEXT NOT NULL, html_content TEXT NOT NULL, original_template TEXT, created_at BIGINT DEFAULT (EXTRACT(EPOCH FROM NOW())) NOT NULL, updated_at BIGINT DEFAULT (EXTRACT(EPOCH FROM NOW())) NOT NULL, last_edited_by TEXT DEFAULT 'system' NOT NULL, PRIMARY KEY (id, site_id) ) ` func (q *Queries) InitializeSchema(ctx context.Context) error { _, err := q.db.ExecContext(ctx, initializeSchema) return err } const initializeVersionsTable = `-- name: InitializeVersionsTable :exec CREATE TABLE IF NOT EXISTS content_versions ( version_id SERIAL PRIMARY KEY, content_id TEXT NOT NULL, site_id TEXT NOT NULL, html_content TEXT NOT NULL, original_template TEXT, created_at BIGINT DEFAULT (EXTRACT(EPOCH FROM NOW())) NOT NULL, created_by TEXT DEFAULT 'system' NOT NULL ) ` func (q *Queries) InitializeVersionsTable(ctx context.Context) error { _, err := q.db.ExecContext(ctx, initializeVersionsTable) return err }