Made some changes to how index pages are made

This commit is contained in:
Leon Mika 2025-02-16 14:06:45 +11:00
parent ba12398d2f
commit 573517565d
14 changed files with 259 additions and 56 deletions

View file

@ -10,4 +10,12 @@ INSERT INTO bundles (
SELECT * FROM bundles WHERE site_id = $1;
-- name: GetBundleWithID :one
SELECT * FROM bundles WHERE id = $1;
SELECT * FROM bundles WHERE id = $1;
-- name: GetSiteBundleInfo :many
WITH page_counts AS (
SELECT b.bundle_id, count(*) AS page_count FROM pages b WHERE b.site_id = $1 GROUP BY bundle_id
), index_pages AS (
SELECT p.id AS index_page_id, p.bundle_id FROM pages p WHERE p.site_id = $1 AND p.role = 'index'
)
SELECT b.bundle_id, b.page_count, p.index_page_id FROM page_counts b LEFT OUTER JOIN index_pages p ON b.bundle_id = p.bundle_id;

View file

@ -5,14 +5,15 @@ INSERT INTO pages (
name,
name_provenance,
title,
role,
post_type_id,
body,
state,
props,
role,
publish_date,
created_at,
updated_at
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $11)
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $12)
RETURNING id;
-- name: UpdatePage :exec
@ -22,13 +23,14 @@ UPDATE pages SET
name = $4,
name_provenance = $5,
title = $6,
role = $7,
body = $8,
state = $9,
props = $10,
publish_date = $11,
created_at = $12,
updated_at = $13
post_type_id = $7,
role = $8,
body = $9,
state = $10,
props = $11,
publish_date = $12,
created_at = $13,
updated_at = $14
WHERE id = $1;
-- name: ListPublishablePages :many

View file

@ -17,6 +17,10 @@ CREATE TYPE page_name_provenance AS ENUM (
'date'
);
CREATE TYPE page_role AS ENUM (
'index'
);
CREATE TABLE users (
id BIGSERIAL NOT NULL PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
@ -36,7 +40,7 @@ CREATE TABLE sites (
-- Post role is used to describe a specific kind of post, such as a link.
-- When set, it specifies the layout to use for the page
CREATE TABLE post_roles (
CREATE TABLE post_types (
id BIGSERIAL NOT NULL PRIMARY KEY,
site_id BIGINT NOT NULL,
layout_name TEXT NOT NULL,
@ -48,7 +52,7 @@ CREATE TABLE posts (
id BIGSERIAL NOT NULL PRIMARY KEY,
site_id BIGINT NOT NULL,
title TEXT,
role BIGINT,
post_type_id BIGINT,
body TEXT NOT NULL,
state post_state NOT NULL,
props JSON NOT NULL,
@ -56,7 +60,7 @@ CREATE TABLE posts (
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
FOREIGN KEY (role) REFERENCES post_roles (id) ON DELETE CASCADE,
FOREIGN KEY (post_type_id) REFERENCES post_types (id) ON DELETE CASCADE,
FOREIGN KEY (site_id) REFERENCES sites (id) ON DELETE CASCADE
);
@ -77,19 +81,21 @@ CREATE TABLE pages (
name TEXT NOT NULL,
name_provenance page_name_provenance NOT NULL,
title TEXT,
role BIGINT,
post_type_id BIGINT,
body TEXT NOT NULL,
state post_state NOT NULL,
props JSON NOT NULL,
role page_role,
publish_date TIMESTAMP WITH TIME ZONE,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
UNIQUE (bundle_id, name),
FOREIGN KEY (site_id) REFERENCES sites (id) ON DELETE CASCADE,
FOREIGN KEY (role) REFERENCES post_roles (id) ON DELETE CASCADE,
FOREIGN KEY (post_type_id) REFERENCES post_types (id) ON DELETE CASCADE,
FOREIGN KEY (bundle_id) REFERENCES sites (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX page_bundle_id_role ON pages (bundle_id, role) WHERE (role is NOT null);
CREATE TABLE publish_targets (
id BIGSERIAL NOT NULL PRIMARY KEY,