-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_encryption_support.sql
More file actions
32 lines (26 loc) · 1.19 KB
/
Copy pathadd_encryption_support.sql
File metadata and controls
32 lines (26 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- Migration: Add AES-256 Encryption Support to DocTransfer
-- This migration adds encryption metadata fields to the documents table
-- Add encryption metadata columns
ALTER TABLE documents
ADD COLUMN IF NOT EXISTS encryption_key TEXT,
ADD COLUMN IF NOT EXISTS encryption_iv TEXT,
ADD COLUMN IF NOT EXISTS is_encrypted BOOLEAN DEFAULT false,
ADD COLUMN IF NOT EXISTS original_file_name TEXT,
ADD COLUMN IF NOT EXISTS original_file_type TEXT;
-- Note: password column will now store bcrypt hashes instead of plain text
-- Existing plain text passwords will be incompatible and need to be reset
-- Add comment to password column
COMMENT ON COLUMN documents.password IS 'Bcrypt hash of password (not plain text)';
-- Update existing records to mark as not encrypted
UPDATE documents
SET is_encrypted = false
WHERE is_encrypted IS NULL;
-- Create index for faster lookups
CREATE INDEX IF NOT EXISTS idx_documents_encrypted ON documents(is_encrypted);
-- Display migration info
DO $$
BEGIN
RAISE NOTICE 'Encryption migration completed successfully';
RAISE NOTICE 'Important: Existing documents are NOT encrypted';
RAISE NOTICE 'Important: Existing passwords are plain text and need to be re-set';
END $$;