Changeset 0.28.0 (#172)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
-- ==========================================
|
||||
-- Chat Switchboard — 013 Files
|
||||
-- ==========================================
|
||||
-- Unified files table replacing attachments.
|
||||
-- Handles both upgrade (attachments exists) and fresh install.
|
||||
-- Unified files table. Fresh install — no legacy attachments migration.
|
||||
-- Consolidated v0.28.0: removes attachments→files migration dance.
|
||||
-- ==========================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS files (
|
||||
@@ -25,38 +25,6 @@ CREATE TABLE IF NOT EXISTS files (
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Ensure attachments table exists so the INSERT is always valid.
|
||||
-- Upgrade: no-op (table already has data). Fresh install: empty table.
|
||||
CREATE TABLE IF NOT EXISTS attachments (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
channel_id UUID, user_id UUID, message_id UUID, project_id UUID,
|
||||
filename VARCHAR(255), content_type VARCHAR(127), size_bytes BIGINT,
|
||||
storage_key TEXT, extracted_text TEXT, metadata JSONB, created_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
INSERT INTO files (
|
||||
id, channel_id, message_id, user_id, project_id,
|
||||
origin, filename, content_type, size_bytes, storage_key,
|
||||
display_hint, extracted_text, metadata, created_at, updated_at
|
||||
)
|
||||
SELECT
|
||||
id, channel_id, message_id, user_id, project_id,
|
||||
'user_upload',
|
||||
filename, content_type, size_bytes, storage_key,
|
||||
CASE
|
||||
WHEN content_type LIKE 'image/%' THEN 'inline'
|
||||
WHEN content_type LIKE 'video/%' THEN 'inline'
|
||||
WHEN content_type LIKE 'audio/%' THEN 'inline'
|
||||
WHEN content_type = 'application/pdf' THEN 'thumbnail'
|
||||
WHEN content_type LIKE 'text/%' THEN 'inline'
|
||||
ELSE 'download'
|
||||
END,
|
||||
extracted_text, metadata, created_at, created_at
|
||||
FROM attachments
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
DROP TABLE IF EXISTS attachments;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_files_channel ON files(channel_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_files_message ON files(message_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_files_user ON files(user_id);
|
||||
|
||||
Reference in New Issue
Block a user