This commit is contained in:
2025-10-24 21:06:39 +08:00
parent 45fb8dfeb8
commit 2f56813874
6 changed files with 84 additions and 285 deletions

View File

@@ -1,30 +1,21 @@
-- Posts table: stores blog post information
CREATE TABLE IF NOT EXISTS posts (
id BIGSERIAL PRIMARY KEY,
id BIGSERIAL,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
view_count BIGINT DEFAULT 0,
cover_id BIGINT,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
);
-- Index for sorting posts by creation date
CREATE INDEX IF NOT EXISTS idx_posts_created_at ON posts(created_at DESC);
COMMENT ON TABLE posts IS 'Blog posts table';
-- Index for sorting posts by view count (popular posts)
CREATE INDEX IF NOT EXISTS idx_posts_view_count ON posts(view_count DESC);
-- Index for sorting posts by update date
CREATE INDEX IF NOT EXISTS idx_posts_updated_at ON posts(updated_at DESC);
-- Combined index for pagination queries
CREATE INDEX IF NOT EXISTS idx_posts_created_view ON posts(created_at DESC, view_count DESC);
-- Comments on columns
COMMENT ON TABLE posts IS 'Blog posts table containing article information';
COMMENT ON COLUMN posts.id IS 'Primary key, auto-incrementing post ID';
COMMENT ON COLUMN posts.title IS 'Post title';
COMMENT ON COLUMN posts.content IS 'Post content in text format';
COMMENT ON COLUMN posts.view_count IS 'Number of times the post has been viewed';
COMMENT ON COLUMN posts.id IS 'Unique identifier for the post';
COMMENT ON COLUMN posts.title IS 'Title of the blog post';
COMMENT ON COLUMN posts.content IS 'Content of the blog post';
COMMENT ON COLUMN posts.cover_id IS 'Reference to the cover image file id';
COMMENT ON COLUMN posts.created_at IS 'Timestamp when the post was created';
COMMENT ON COLUMN posts.updated_at IS 'Timestamp when the post was last updated';
COMMENT ON COLUMN posts.updated_at IS 'Timestamp when the post was last updated';
CREATE INDEX idx_posts_created_at ON posts(created_at);
CREATE INDEX idx_posts_cover_id ON posts(cover_id);