diff --git a/internal/store/migrate.go b/internal/store/migrate.go index 646f1b2..fd5c10b 100644 --- a/internal/store/migrate.go +++ b/internal/store/migrate.go @@ -50,22 +50,22 @@ CREATE TABLE IF NOT EXISTS posts ( title TEXT NOT NULL DEFAULT '', body TEXT NOT NULL, city TEXT NOT NULL DEFAULT '', - hunt_date TEXT NOT NULL DEFAULT '', + post_date TEXT NOT NULL DEFAULT '', hidden INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, CHECK ( - (parent_id IS NULL AND title <> '' AND hunt_date <> '') + (parent_id IS NULL AND title <> '' AND post_date <> '') 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", ` CREATE INDEX IF NOT EXISTS idx_posts_parent_created ON posts(parent_id, created_at, id)`}, {"index root posts", ` -CREATE INDEX IF NOT EXISTS idx_posts_root_hunt - ON posts(hunt_date, hidden) +CREATE INDEX IF NOT EXISTS idx_posts_root_date + ON posts(post_date, hidden) WHERE parent_id IS NULL`}, {"create post votes", ` CREATE TABLE IF NOT EXISTS post_votes ( @@ -76,7 +76,7 @@ CREATE TABLE IF NOT EXISTS post_votes ( )`}, {"copy questions", ` 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 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`}, {"copy answers", ` 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 'answer:' || question_id, question_id, author_id, '', body, '', '', 0, created_at, updated_at diff --git a/internal/store/migrate_posts_test.go b/internal/store/migrate_posts_test.go index 7c8eed6..6a81d37 100644 --- a/internal/store/migrate_posts_test.go +++ b/internal/store/migrate_posts_test.go @@ -117,9 +117,9 @@ VALUES ('homeowner', 'question-1', 1);`); err != nil { } 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, ` -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 WHERE id = 'question-1'`).Scan( &rootParent, @@ -127,7 +127,7 @@ WHERE id = 'question-1'`).Scan( &title, &rootBody, &city, - &huntDate, + &postDate, &rootCreated, &rootUpdated, ); err != nil { @@ -138,7 +138,7 @@ WHERE id = 'question-1'`).Scan( title != "Leaky sink" || rootBody != "It drips." || city != "Oakland" || - huntDate != "2026-08-26" || + postDate != "2026-08-26" || rootCreated != "2026-08-26T08:00:00Z" || rootUpdated != rootCreated { 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, ` 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 ( 'invalid-reply', 'question-1', 'homeowner', 'Replies cannot have titles', 'Body', '', '', 0, 'now', 'now' )`); err == nil { diff --git a/internal/store/sqlc/models.go b/internal/store/sqlc/models.go index ea2b8a0..f2b2acc 100644 --- a/internal/store/sqlc/models.go +++ b/internal/store/sqlc/models.go @@ -24,7 +24,7 @@ type Post struct { Title string Body string City string - HuntDate string + PostDate string Hidden int32 CreatedAt string UpdatedAt string diff --git a/schema.sql b/schema.sql index 0ac50c3..5571cad 100644 --- a/schema.sql +++ b/schema.sql @@ -49,22 +49,22 @@ CREATE TABLE IF NOT EXISTS posts ( title TEXT NOT NULL DEFAULT '', body TEXT NOT NULL, city TEXT NOT NULL DEFAULT '', - hunt_date TEXT NOT NULL DEFAULT '', + post_date TEXT NOT NULL DEFAULT '', hidden INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, CHECK ( - (parent_id IS NULL AND title <> '' AND hunt_date <> '') + (parent_id IS NULL AND title <> '' AND post_date <> '') 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 ON posts(parent_id, created_at, id); -CREATE INDEX IF NOT EXISTS idx_posts_root_hunt - ON posts(hunt_date, hidden) +CREATE INDEX IF NOT EXISTS idx_posts_root_date + ON posts(post_date, hidden) WHERE parent_id IS NULL; CREATE TABLE IF NOT EXISTS post_votes (