25 lines
1.1 KiB
SQL
25 lines
1.1 KiB
SQL
-- Files table: stores uploaded file metadata
|
|
CREATE TABLE IF NOT EXISTS files (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
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
|
|
);
|
|
|
|
-- Index for looking up files by key (most common query)
|
|
CREATE INDEX IF NOT EXISTS idx_files_file_key ON files(file_key);
|
|
|
|
-- Index for sorting files by creation date
|
|
CREATE INDEX IF NOT EXISTS idx_files_created_at ON files(created_at DESC);
|
|
|
|
-- 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'; |