• 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
198 lines
5.7 KiB
Go
198 lines
5.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: collection_item_versions.sql
|
|
|
|
package postgresql
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createCollectionItemVersion = `-- name: CreateCollectionItemVersion :exec
|
|
|
|
INSERT INTO collection_item_versions (item_id, collection_id, site_id, html_content, template_id, position, created_by)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
`
|
|
|
|
type CreateCollectionItemVersionParams struct {
|
|
ItemID string `json:"item_id"`
|
|
CollectionID string `json:"collection_id"`
|
|
SiteID string `json:"site_id"`
|
|
HtmlContent string `json:"html_content"`
|
|
TemplateID int32 `json:"template_id"`
|
|
Position int32 `json:"position"`
|
|
CreatedBy string `json:"created_by"`
|
|
}
|
|
|
|
// Collection item versions table queries
|
|
func (q *Queries) CreateCollectionItemVersion(ctx context.Context, arg CreateCollectionItemVersionParams) error {
|
|
_, err := q.db.ExecContext(ctx, createCollectionItemVersion,
|
|
arg.ItemID,
|
|
arg.CollectionID,
|
|
arg.SiteID,
|
|
arg.HtmlContent,
|
|
arg.TemplateID,
|
|
arg.Position,
|
|
arg.CreatedBy,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const deleteOldCollectionItemVersions = `-- name: DeleteOldCollectionItemVersions :exec
|
|
DELETE FROM collection_item_versions
|
|
WHERE created_at < $1 AND site_id = $2
|
|
`
|
|
|
|
type DeleteOldCollectionItemVersionsParams struct {
|
|
CreatedBefore int64 `json:"created_before"`
|
|
SiteID string `json:"site_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteOldCollectionItemVersions(ctx context.Context, arg DeleteOldCollectionItemVersionsParams) error {
|
|
_, err := q.db.ExecContext(ctx, deleteOldCollectionItemVersions, arg.CreatedBefore, arg.SiteID)
|
|
return err
|
|
}
|
|
|
|
const getAllCollectionItemVersionsForSite = `-- name: GetAllCollectionItemVersionsForSite :many
|
|
SELECT
|
|
civ.version_id, civ.item_id, civ.collection_id, civ.site_id, civ.html_content, civ.template_id, civ.position, civ.created_at, civ.created_by,
|
|
ci.html_content as current_html_content, ci.position as current_position
|
|
FROM collection_item_versions civ
|
|
LEFT JOIN collection_items ci ON civ.item_id = ci.item_id AND civ.collection_id = ci.collection_id AND civ.site_id = ci.site_id
|
|
WHERE civ.site_id = $1
|
|
ORDER BY civ.created_at DESC
|
|
LIMIT $2
|
|
`
|
|
|
|
type GetAllCollectionItemVersionsForSiteParams struct {
|
|
SiteID string `json:"site_id"`
|
|
LimitCount int32 `json:"limit_count"`
|
|
}
|
|
|
|
type GetAllCollectionItemVersionsForSiteRow struct {
|
|
VersionID int32 `json:"version_id"`
|
|
ItemID string `json:"item_id"`
|
|
CollectionID string `json:"collection_id"`
|
|
SiteID string `json:"site_id"`
|
|
HtmlContent string `json:"html_content"`
|
|
TemplateID int32 `json:"template_id"`
|
|
Position int32 `json:"position"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
CreatedBy string `json:"created_by"`
|
|
CurrentHtmlContent sql.NullString `json:"current_html_content"`
|
|
CurrentPosition sql.NullInt32 `json:"current_position"`
|
|
}
|
|
|
|
func (q *Queries) GetAllCollectionItemVersionsForSite(ctx context.Context, arg GetAllCollectionItemVersionsForSiteParams) ([]GetAllCollectionItemVersionsForSiteRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getAllCollectionItemVersionsForSite, arg.SiteID, arg.LimitCount)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetAllCollectionItemVersionsForSiteRow
|
|
for rows.Next() {
|
|
var i GetAllCollectionItemVersionsForSiteRow
|
|
if err := rows.Scan(
|
|
&i.VersionID,
|
|
&i.ItemID,
|
|
&i.CollectionID,
|
|
&i.SiteID,
|
|
&i.HtmlContent,
|
|
&i.TemplateID,
|
|
&i.Position,
|
|
&i.CreatedAt,
|
|
&i.CreatedBy,
|
|
&i.CurrentHtmlContent,
|
|
&i.CurrentPosition,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getCollectionItemVersion = `-- name: GetCollectionItemVersion :one
|
|
SELECT version_id, item_id, collection_id, site_id, html_content, template_id, position, created_at, created_by
|
|
FROM collection_item_versions
|
|
WHERE version_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetCollectionItemVersion(ctx context.Context, versionID int32) (CollectionItemVersion, error) {
|
|
row := q.db.QueryRowContext(ctx, getCollectionItemVersion, versionID)
|
|
var i CollectionItemVersion
|
|
err := row.Scan(
|
|
&i.VersionID,
|
|
&i.ItemID,
|
|
&i.CollectionID,
|
|
&i.SiteID,
|
|
&i.HtmlContent,
|
|
&i.TemplateID,
|
|
&i.Position,
|
|
&i.CreatedAt,
|
|
&i.CreatedBy,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getCollectionItemVersionHistory = `-- name: GetCollectionItemVersionHistory :many
|
|
SELECT version_id, item_id, collection_id, site_id, html_content, template_id, position, created_at, created_by
|
|
FROM collection_item_versions
|
|
WHERE item_id = $1 AND collection_id = $2 AND site_id = $3
|
|
ORDER BY created_at DESC
|
|
LIMIT $4
|
|
`
|
|
|
|
type GetCollectionItemVersionHistoryParams struct {
|
|
ItemID string `json:"item_id"`
|
|
CollectionID string `json:"collection_id"`
|
|
SiteID string `json:"site_id"`
|
|
LimitCount int32 `json:"limit_count"`
|
|
}
|
|
|
|
func (q *Queries) GetCollectionItemVersionHistory(ctx context.Context, arg GetCollectionItemVersionHistoryParams) ([]CollectionItemVersion, error) {
|
|
rows, err := q.db.QueryContext(ctx, getCollectionItemVersionHistory,
|
|
arg.ItemID,
|
|
arg.CollectionID,
|
|
arg.SiteID,
|
|
arg.LimitCount,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []CollectionItemVersion
|
|
for rows.Next() {
|
|
var i CollectionItemVersion
|
|
if err := rows.Scan(
|
|
&i.VersionID,
|
|
&i.ItemID,
|
|
&i.CollectionID,
|
|
&i.SiteID,
|
|
&i.HtmlContent,
|
|
&i.TemplateID,
|
|
&i.Position,
|
|
&i.CreatedAt,
|
|
&i.CreatedBy,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|