🪻 distributed transcription service thistle.dunkirk.sh
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: collapse migrations

+15 -81
+15 -81
src/db/schema.ts
··· 13 13 const migrations = [ 14 14 { 15 15 version: 1, 16 - name: "Complete schema with class system", 16 + name: "Initial schema with all tables and constraints", 17 17 sql: ` 18 18 -- Users table 19 19 CREATE TABLE IF NOT EXISTS users ( ··· 24 24 avatar TEXT DEFAULT 'd', 25 25 role TEXT NOT NULL DEFAULT 'user', 26 26 last_login INTEGER, 27 + email_verified BOOLEAN DEFAULT 0, 28 + email_notifications_enabled BOOLEAN DEFAULT 1, 27 29 created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')) 28 30 ); 29 31 30 32 CREATE INDEX IF NOT EXISTS idx_users_role ON users(role); 31 33 CREATE INDEX IF NOT EXISTS idx_users_last_login ON users(last_login); 34 + CREATE INDEX IF NOT EXISTS idx_users_email_verified ON users(email_verified); 32 35 33 36 -- Sessions table 34 37 CREATE TABLE IF NOT EXISTS sessions ( ··· 84 87 85 88 CREATE INDEX IF NOT EXISTS idx_classes_semester_year ON classes(semester, year); 86 89 CREATE INDEX IF NOT EXISTS idx_classes_archived ON classes(archived); 90 + CREATE INDEX IF NOT EXISTS idx_classes_course_code ON classes(course_code); 87 91 88 92 -- Class members table 89 93 CREATE TABLE IF NOT EXISTS class_members ( ··· 132 136 CREATE INDEX IF NOT EXISTS idx_transcriptions_class_id ON transcriptions(class_id); 133 137 CREATE INDEX IF NOT EXISTS idx_transcriptions_status ON transcriptions(status); 134 138 CREATE INDEX IF NOT EXISTS idx_transcriptions_whisper_job_id ON transcriptions(whisper_job_id); 135 - `, 136 - }, 137 - { 138 - version: 2, 139 - name: "Add section column to classes table", 140 - sql: ` 141 - ALTER TABLE classes ADD COLUMN section TEXT; 142 - CREATE INDEX IF NOT EXISTS idx_classes_course_code ON classes(course_code); 143 - `, 144 - }, 145 - { 146 - version: 3, 147 - name: "Add class waitlist table", 148 - sql: ` 139 + CREATE INDEX IF NOT EXISTS idx_transcriptions_meeting_time_id ON transcriptions(meeting_time_id); 140 + 141 + -- Class waitlist table 149 142 CREATE TABLE IF NOT EXISTS class_waitlist ( 150 143 id TEXT PRIMARY KEY, 151 144 user_id INTEGER NOT NULL, 152 145 course_code TEXT NOT NULL, 153 146 course_name TEXT NOT NULL, 154 147 professor TEXT NOT NULL, 155 - section TEXT, 156 148 semester TEXT NOT NULL, 157 149 year INTEGER NOT NULL, 150 + meeting_times TEXT, 158 151 additional_info TEXT, 159 152 created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')), 160 153 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ··· 162 155 163 156 CREATE INDEX IF NOT EXISTS idx_waitlist_user_id ON class_waitlist(user_id); 164 157 CREATE INDEX IF NOT EXISTS idx_waitlist_course_code ON class_waitlist(course_code); 165 - `, 166 - }, 167 - { 168 - version: 4, 169 - name: "Add meeting_times to class_waitlist", 170 - sql: ` 171 - ALTER TABLE class_waitlist ADD COLUMN meeting_times TEXT; 172 - `, 173 - }, 174 - { 175 - version: 5, 176 - name: "Remove section columns", 177 - sql: ` 178 - DROP INDEX IF EXISTS idx_classes_section; 179 - ALTER TABLE classes DROP COLUMN section; 180 - ALTER TABLE class_waitlist DROP COLUMN section; 181 - `, 182 - }, 183 - { 184 - version: 6, 185 - name: "Add subscriptions table for Polar integration", 186 - sql: ` 158 + 187 159 -- Subscriptions table 188 160 CREATE TABLE IF NOT EXISTS subscriptions ( 189 161 id TEXT PRIMARY KEY, ··· 202 174 CREATE INDEX IF NOT EXISTS idx_subscriptions_user_id ON subscriptions(user_id); 203 175 CREATE INDEX IF NOT EXISTS idx_subscriptions_status ON subscriptions(status); 204 176 CREATE INDEX IF NOT EXISTS idx_subscriptions_customer_id ON subscriptions(customer_id); 205 - `, 206 - }, 207 - { 208 - version: 7, 209 - name: "Create ghost user for deleted accounts", 210 - sql: ` 211 - -- Create a ghost user account for orphaned transcriptions 212 - INSERT OR IGNORE INTO users (id, email, password_hash, name, avatar, role, created_at) 213 - VALUES (0, 'ghosty@thistle.internal', NULL, 'Ghosty', '👻', 'user', strftime('%s', 'now')); 214 - `, 215 - }, 216 - { 217 - version: 8, 218 - name: "Add email verification system", 219 - sql: ` 220 - -- Add email verification flag to users 221 - ALTER TABLE users ADD COLUMN email_verified BOOLEAN DEFAULT 0; 222 177 223 178 -- Email verification tokens table 224 179 CREATE TABLE IF NOT EXISTS email_verification_tokens ( ··· 245 200 246 201 CREATE INDEX IF NOT EXISTS idx_password_reset_tokens_user_id ON password_reset_tokens(user_id); 247 202 CREATE INDEX IF NOT EXISTS idx_password_reset_tokens_token ON password_reset_tokens(token); 248 - `, 249 - }, 250 - { 251 - version: 10, 252 - name: "Add email notification preferences", 253 - sql: ` 254 - ALTER TABLE users ADD COLUMN email_notifications_enabled BOOLEAN DEFAULT 1; 255 - `, 256 - }, 257 - { 258 - version: 9, 259 - name: "Add email change tokens table", 260 - sql: ` 203 + 261 204 -- Email change tokens table 262 205 CREATE TABLE IF NOT EXISTS email_change_tokens ( 263 206 id TEXT PRIMARY KEY, ··· 271 214 272 215 CREATE INDEX IF NOT EXISTS idx_email_change_tokens_user_id ON email_change_tokens(user_id); 273 216 CREATE INDEX IF NOT EXISTS idx_email_change_tokens_token ON email_change_tokens(token); 274 - `, 275 - }, 276 - { 277 - version: 11, 278 - name: "Add NOT NULL constraints and missing indexes", 279 - sql: ` 280 - -- Note: SQLite doesn't support ALTER COLUMN to add NOT NULL to existing columns 281 - -- These tables were created in migration 6 and 8, but the columns should have been NOT NULL 282 - -- The constraints are enforced at the application level, this migration documents the intent 283 - 284 - -- Add missing indexes for performance 285 - CREATE INDEX IF NOT EXISTS idx_users_email_verified ON users(email_verified); 286 - CREATE INDEX IF NOT EXISTS idx_transcriptions_meeting_time_id ON transcriptions(meeting_time_id); 217 + 218 + -- Create ghost user for deleted accounts 219 + INSERT OR IGNORE INTO users (id, email, password_hash, name, avatar, role, created_at) 220 + VALUES (0, 'ghosty@thistle.internal', NULL, 'Ghosty', '👻', 'user', strftime('%s', 'now')); 287 221 `, 288 222 }, 289 223 ];