Use post_date throughout the new schema while retaining hunt_date only as the legacy migration source.
This commit is contained in:
@@ -50,22 +50,22 @@ CREATE TABLE IF NOT EXISTS posts (
|
|||||||
title TEXT NOT NULL DEFAULT '',
|
title TEXT NOT NULL DEFAULT '',
|
||||||
body TEXT NOT NULL,
|
body TEXT NOT NULL,
|
||||||
city TEXT NOT NULL DEFAULT '',
|
city TEXT NOT NULL DEFAULT '',
|
||||||
hunt_date TEXT NOT NULL DEFAULT '',
|
post_date TEXT NOT NULL DEFAULT '',
|
||||||
hidden INTEGER NOT NULL DEFAULT 0,
|
hidden INTEGER NOT NULL DEFAULT 0,
|
||||||
created_at TEXT NOT NULL,
|
created_at TEXT NOT NULL,
|
||||||
updated_at TEXT NOT NULL,
|
updated_at TEXT NOT NULL,
|
||||||
CHECK (
|
CHECK (
|
||||||
(parent_id IS NULL AND title <> '' AND hunt_date <> '')
|
(parent_id IS NULL AND title <> '' AND post_date <> '')
|
||||||
OR
|
OR
|
||||||
(parent_id IS NOT NULL AND title = '' AND city = '' AND hunt_date = '' AND hidden = 0)
|
(parent_id IS NOT NULL AND title = '' AND city = '' AND post_date = '' AND hidden = 0)
|
||||||
)
|
)
|
||||||
)`},
|
)`},
|
||||||
{"index post replies", `
|
{"index post replies", `
|
||||||
CREATE INDEX IF NOT EXISTS idx_posts_parent_created
|
CREATE INDEX IF NOT EXISTS idx_posts_parent_created
|
||||||
ON posts(parent_id, created_at, id)`},
|
ON posts(parent_id, created_at, id)`},
|
||||||
{"index root posts", `
|
{"index root posts", `
|
||||||
CREATE INDEX IF NOT EXISTS idx_posts_root_hunt
|
CREATE INDEX IF NOT EXISTS idx_posts_root_date
|
||||||
ON posts(hunt_date, hidden)
|
ON posts(post_date, hidden)
|
||||||
WHERE parent_id IS NULL`},
|
WHERE parent_id IS NULL`},
|
||||||
{"create post votes", `
|
{"create post votes", `
|
||||||
CREATE TABLE IF NOT EXISTS post_votes (
|
CREATE TABLE IF NOT EXISTS post_votes (
|
||||||
@@ -76,7 +76,7 @@ CREATE TABLE IF NOT EXISTS post_votes (
|
|||||||
)`},
|
)`},
|
||||||
{"copy questions", `
|
{"copy questions", `
|
||||||
INSERT INTO posts (
|
INSERT INTO posts (
|
||||||
id, parent_id, author_id, title, body, city, hunt_date, hidden, created_at, updated_at
|
id, parent_id, author_id, title, body, city, post_date, hidden, created_at, updated_at
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
id, NULL, author_id, title, body, city, hunt_date, hidden, created_at, created_at
|
id, NULL, author_id, title, body, city, hunt_date, hidden, created_at, created_at
|
||||||
@@ -84,7 +84,7 @@ FROM questions
|
|||||||
ON CONFLICT (id) DO NOTHING`},
|
ON CONFLICT (id) DO NOTHING`},
|
||||||
{"copy answers", `
|
{"copy answers", `
|
||||||
INSERT INTO posts (
|
INSERT INTO posts (
|
||||||
id, parent_id, author_id, title, body, city, hunt_date, hidden, created_at, updated_at
|
id, parent_id, author_id, title, body, city, post_date, hidden, created_at, updated_at
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
'answer:' || question_id, question_id, author_id, '', body, '', '', 0, created_at, updated_at
|
'answer:' || question_id, question_id, author_id, '', body, '', '', 0, created_at, updated_at
|
||||||
|
|||||||
@@ -117,9 +117,9 @@ VALUES ('homeowner', 'question-1', 1);`); err != nil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var rootParent sql.NullString
|
var rootParent sql.NullString
|
||||||
var rootAuthor, title, rootBody, city, huntDate, rootCreated, rootUpdated string
|
var rootAuthor, title, rootBody, city, postDate, rootCreated, rootUpdated string
|
||||||
if err := conn.QueryRowContext(ctx, `
|
if err := conn.QueryRowContext(ctx, `
|
||||||
SELECT parent_id, author_id, title, body, city, hunt_date, created_at, updated_at
|
SELECT parent_id, author_id, title, body, city, post_date, created_at, updated_at
|
||||||
FROM posts
|
FROM posts
|
||||||
WHERE id = 'question-1'`).Scan(
|
WHERE id = 'question-1'`).Scan(
|
||||||
&rootParent,
|
&rootParent,
|
||||||
@@ -127,7 +127,7 @@ WHERE id = 'question-1'`).Scan(
|
|||||||
&title,
|
&title,
|
||||||
&rootBody,
|
&rootBody,
|
||||||
&city,
|
&city,
|
||||||
&huntDate,
|
&postDate,
|
||||||
&rootCreated,
|
&rootCreated,
|
||||||
&rootUpdated,
|
&rootUpdated,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
@@ -138,7 +138,7 @@ WHERE id = 'question-1'`).Scan(
|
|||||||
title != "Leaky sink" ||
|
title != "Leaky sink" ||
|
||||||
rootBody != "It drips." ||
|
rootBody != "It drips." ||
|
||||||
city != "Oakland" ||
|
city != "Oakland" ||
|
||||||
huntDate != "2026-08-26" ||
|
postDate != "2026-08-26" ||
|
||||||
rootCreated != "2026-08-26T08:00:00Z" ||
|
rootCreated != "2026-08-26T08:00:00Z" ||
|
||||||
rootUpdated != rootCreated {
|
rootUpdated != rootCreated {
|
||||||
t.Fatalf("unexpected root post")
|
t.Fatalf("unexpected root post")
|
||||||
@@ -177,7 +177,7 @@ WHERE user_id = 'homeowner' AND post_id = 'question-1'`).Scan(&voteValue); err !
|
|||||||
|
|
||||||
if _, err := conn.ExecContext(ctx, `
|
if _, err := conn.ExecContext(ctx, `
|
||||||
INSERT INTO posts (
|
INSERT INTO posts (
|
||||||
id, parent_id, author_id, title, body, city, hunt_date, hidden, created_at, updated_at
|
id, parent_id, author_id, title, body, city, post_date, hidden, created_at, updated_at
|
||||||
) VALUES (
|
) VALUES (
|
||||||
'invalid-reply', 'question-1', 'homeowner', 'Replies cannot have titles', 'Body', '', '', 0, 'now', 'now'
|
'invalid-reply', 'question-1', 'homeowner', 'Replies cannot have titles', 'Body', '', '', 0, 'now', 'now'
|
||||||
)`); err == nil {
|
)`); err == nil {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type Post struct {
|
|||||||
Title string
|
Title string
|
||||||
Body string
|
Body string
|
||||||
City string
|
City string
|
||||||
HuntDate string
|
PostDate string
|
||||||
Hidden int32
|
Hidden int32
|
||||||
CreatedAt string
|
CreatedAt string
|
||||||
UpdatedAt string
|
UpdatedAt string
|
||||||
|
|||||||
+5
-5
@@ -49,22 +49,22 @@ CREATE TABLE IF NOT EXISTS posts (
|
|||||||
title TEXT NOT NULL DEFAULT '',
|
title TEXT NOT NULL DEFAULT '',
|
||||||
body TEXT NOT NULL,
|
body TEXT NOT NULL,
|
||||||
city TEXT NOT NULL DEFAULT '',
|
city TEXT NOT NULL DEFAULT '',
|
||||||
hunt_date TEXT NOT NULL DEFAULT '',
|
post_date TEXT NOT NULL DEFAULT '',
|
||||||
hidden INTEGER NOT NULL DEFAULT 0,
|
hidden INTEGER NOT NULL DEFAULT 0,
|
||||||
created_at TEXT NOT NULL,
|
created_at TEXT NOT NULL,
|
||||||
updated_at TEXT NOT NULL,
|
updated_at TEXT NOT NULL,
|
||||||
CHECK (
|
CHECK (
|
||||||
(parent_id IS NULL AND title <> '' AND hunt_date <> '')
|
(parent_id IS NULL AND title <> '' AND post_date <> '')
|
||||||
OR
|
OR
|
||||||
(parent_id IS NOT NULL AND title = '' AND city = '' AND hunt_date = '' AND hidden = 0)
|
(parent_id IS NOT NULL AND title = '' AND city = '' AND post_date = '' AND hidden = 0)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_posts_parent_created
|
CREATE INDEX IF NOT EXISTS idx_posts_parent_created
|
||||||
ON posts(parent_id, created_at, id);
|
ON posts(parent_id, created_at, id);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_posts_root_hunt
|
CREATE INDEX IF NOT EXISTS idx_posts_root_date
|
||||||
ON posts(hunt_date, hidden)
|
ON posts(post_date, hidden)
|
||||||
WHERE parent_id IS NULL;
|
WHERE parent_id IS NULL;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS post_votes (
|
CREATE TABLE IF NOT EXISTS post_votes (
|
||||||
|
|||||||
Reference in New Issue
Block a user