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,25 +1,16 @@
-- Files table: stores uploaded file metadata
CREATE TABLE IF NOT EXISTS files (
id BIGSERIAL PRIMARY KEY,
id BIGSERIAL,
file_name VARCHAR(255) NOT NULL,
file_key VARCHAR(500) NOT NULL UNIQUE,
byte_size BIGINT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
);
-- Index for looking up files by key (most common query)
CREATE INDEX IF NOT EXISTS idx_files_file_key ON files(file_key);
COMMENT ON TABLE files IS 'Files table for storing uploaded files';
-- Index for sorting files by creation date
CREATE INDEX IF NOT EXISTS idx_files_created_at ON files(created_at DESC);
COMMENT ON COLUMN files.id IS 'Unique identifier for the file';
COMMENT ON COLUMN files.file_name IS 'Name of the uploaded file';
COMMENT ON COLUMN files.file_key IS 'Unique key for the file storage';
COMMENT ON COLUMN files.created_at IS 'Timestamp when the file was uploaded';
-- Index for file size queries
CREATE INDEX IF NOT EXISTS idx_files_byte_size ON files(byte_size);
-- Comments on columns
COMMENT ON TABLE files IS 'File metadata table for uploaded files';
COMMENT ON COLUMN files.id IS 'Primary key, auto-incrementing file ID';
COMMENT ON COLUMN files.file_name IS 'Original name of the uploaded file';
COMMENT ON COLUMN files.file_key IS 'Unique storage key/path for the file';
COMMENT ON COLUMN files.byte_size IS 'File size in bytes';
COMMENT ON COLUMN files.created_at IS 'Timestamp when the file was uploaded';
CREATE INDEX idx_files_created_at ON files(created_at);