From d63d0c4c44cb2356645fd112cec01598301f5949 Mon Sep 17 00:00:00 2001
From: Kujtim Hoxha <kujtimii.h@gmail.com>
Date: Sun, 13 Apr 2025 11:29:20 +0200
Subject: wip files

---
 internal/db/migrations/000001_initial.up.sql | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

(limited to 'internal/db/migrations/000001_initial.up.sql')

diff --git a/internal/db/migrations/000001_initial.up.sql b/internal/db/migrations/000001_initial.up.sql
index 03479449d..4ac297dc5 100644
--- a/internal/db/migrations/000001_initial.up.sql
+++ b/internal/db/migrations/000001_initial.up.sql
@@ -18,6 +18,28 @@ UPDATE sessions SET updated_at = strftime('%s', 'now')
 WHERE id = new.id;
 END;
 
+-- Files
+CREATE TABLE IF NOT EXISTS files (
+    id TEXT PRIMARY KEY,
+    session_id TEXT NOT NULL,
+    path TEXT NOT NULL,
+    content TEXT NOT NULL,
+    version TEXT NOT NULL,
+    created_at INTEGER NOT NULL,  -- Unix timestamp in milliseconds
+    updated_at INTEGER NOT NULL,  -- Unix timestamp in milliseconds
+    FOREIGN KEY (session_id) REFERENCES sessions (id) ON DELETE CASCADE
+);
+
+CREATE INDEX IF NOT EXISTS idx_files_session_id ON files (session_id);
+CREATE INDEX IF NOT EXISTS idx_files_path ON files (path);
+
+CREATE TRIGGER IF NOT EXISTS update_files_updated_at
+AFTER UPDATE ON files
+BEGIN
+UPDATE files SET updated_at = strftime('%s', 'now')
+WHERE id = new.id;
+END;
+
 -- Messages
 CREATE TABLE IF NOT EXISTS messages (
     id TEXT PRIMARY KEY,
-- 
cgit v1.2.3

