Started working on pages
This commit is contained in:
parent
e2f159e980
commit
ba12398d2f
30 changed files with 1391 additions and 145 deletions
13
sql/queries/bundles.sql
Normal file
13
sql/queries/bundles.sql
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
-- name: InsertBundle :one
|
||||
INSERT INTO bundles (
|
||||
site_id,
|
||||
name,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES ($1, $2, $3, $3) RETURNING id;
|
||||
|
||||
-- name: ListBundles :many
|
||||
SELECT * FROM bundles WHERE site_id = $1;
|
||||
|
||||
-- name: GetBundleWithID :one
|
||||
SELECT * FROM bundles WHERE id = $1;
|
||||
47
sql/queries/pages.sql
Normal file
47
sql/queries/pages.sql
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
-- name: InsertPage :one
|
||||
INSERT INTO pages (
|
||||
site_id,
|
||||
bundle_id,
|
||||
name,
|
||||
name_provenance,
|
||||
title,
|
||||
role,
|
||||
body,
|
||||
state,
|
||||
props,
|
||||
publish_date,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $11)
|
||||
RETURNING id;
|
||||
|
||||
-- name: UpdatePage :exec
|
||||
UPDATE pages SET
|
||||
site_id = $2,
|
||||
bundle_id = $3,
|
||||
name = $4,
|
||||
name_provenance = $5,
|
||||
title = $6,
|
||||
role = $7,
|
||||
body = $8,
|
||||
state = $9,
|
||||
props = $10,
|
||||
publish_date = $11,
|
||||
created_at = $12,
|
||||
updated_at = $13
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: ListPublishablePages :many
|
||||
SELECT *
|
||||
FROM pages
|
||||
WHERE id > $1 AND site_id = $2 AND state = 'published'
|
||||
ORDER BY id LIMIT 100;
|
||||
|
||||
-- name: ListPages :many
|
||||
SELECT * FROM pages WHERE site_id = $1 ORDER BY name ASC LIMIT 25;
|
||||
|
||||
-- name: GetPageWithID :one
|
||||
SELECT * FROM pages WHERE id = $1;
|
||||
|
||||
-- name: DeletePageWithID :exec
|
||||
DELETE FROM pages WHERE id = $1;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
-- name: ListPosts :many
|
||||
SELECT * FROM posts WHERE site_id = $1 ORDER BY post_date DESC LIMIT 25;
|
||||
SELECT * FROM posts WHERE site_id = $1 ORDER BY publish_date DESC LIMIT 25;
|
||||
|
||||
-- name: GetPostWithID :one
|
||||
SELECT * FROM posts WHERE id = $1 LIMIT 1;
|
||||
|
|
@ -7,7 +7,7 @@ SELECT * FROM posts WHERE id = $1 LIMIT 1;
|
|||
-- name: ListPublishablePosts :many
|
||||
SELECT *
|
||||
FROM posts
|
||||
WHERE id > $1 AND site_id = $2 AND state = 'published' AND post_date <= $3
|
||||
WHERE id > $1 AND site_id = $2 AND state = 'published' AND publish_date <= $3
|
||||
ORDER BY id LIMIT 100;
|
||||
|
||||
-- name: InsertPost :one
|
||||
|
|
@ -17,9 +17,10 @@ INSERT INTO posts (
|
|||
body,
|
||||
state,
|
||||
props,
|
||||
post_date,
|
||||
created_at
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
publish_date,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING id;
|
||||
|
||||
-- name: UpdatePost :exec
|
||||
|
|
@ -29,8 +30,8 @@ UPDATE posts SET
|
|||
body = $4,
|
||||
state = $5,
|
||||
props = $6,
|
||||
post_date = $7
|
||||
-- updated_at = $7
|
||||
publish_date = $7,
|
||||
updated_at = $8
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: DeletePost :exec
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@ CREATE TYPE target_type AS ENUM (
|
|||
'netlify'
|
||||
);
|
||||
|
||||
CREATE TYPE page_name_provenance AS ENUM (
|
||||
'user',
|
||||
'title',
|
||||
'date'
|
||||
);
|
||||
|
||||
CREATE TABLE users (
|
||||
id BIGSERIAL NOT NULL PRIMARY KEY,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
|
|
@ -28,19 +34,63 @@ CREATE TABLE sites (
|
|||
FOREIGN KEY (owner_user_id) REFERENCES users (id)
|
||||
);
|
||||
|
||||
CREATE TABLE posts (
|
||||
id BIGSERIAL NOT NULL PRIMARY KEY,
|
||||
site_id BIGINT NOT NULL,
|
||||
title TEXT,
|
||||
body TEXT NOT NULL,
|
||||
state post_state NOT NULL,
|
||||
props JSON NOT NULL,
|
||||
post_date TIMESTAMP WITH TIME ZONE,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
-- 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 (
|
||||
id BIGSERIAL NOT NULL PRIMARY KEY,
|
||||
site_id BIGINT NOT NULL,
|
||||
layout_name TEXT NOT NULL,
|
||||
|
||||
FOREIGN KEY (site_id) REFERENCES sites (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE posts (
|
||||
id BIGSERIAL NOT NULL PRIMARY KEY,
|
||||
site_id BIGINT NOT NULL,
|
||||
title TEXT,
|
||||
role BIGINT,
|
||||
body TEXT NOT NULL,
|
||||
state post_state NOT NULL,
|
||||
props JSON NOT NULL,
|
||||
publish_date TIMESTAMP WITH TIME ZONE,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL,
|
||||
|
||||
FOREIGN KEY (role) REFERENCES post_roles (id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (site_id) REFERENCES sites (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE bundles (
|
||||
id BIGSERIAL NOT NULL PRIMARY KEY,
|
||||
site_id BIGINT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL,
|
||||
|
||||
FOREIGN KEY (site_id) REFERENCES sites (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE pages (
|
||||
id BIGSERIAL NOT NULL PRIMARY KEY,
|
||||
site_id BIGINT NOT NULL,
|
||||
bundle_id BIGINT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
name_provenance page_name_provenance NOT NULL,
|
||||
title TEXT,
|
||||
role BIGINT,
|
||||
body TEXT NOT NULL,
|
||||
state post_state NOT NULL,
|
||||
props JSON NOT NULL,
|
||||
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 (bundle_id) REFERENCES sites (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE publish_targets (
|
||||
id BIGSERIAL NOT NULL PRIMARY KEY,
|
||||
site_id BIGINT NOT NULL,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue