Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Fix recording options lost on upload, full PostgreSQL migration compatibility, and recording view UI overflow
Murtaza Nasir56c9bfc54e06
diff --git a/.gitignore b/.gitignoreindex 00ca1a2d..339ff8de 100644--- a/.gitignore+++ b/.gitignore@@ -21,6 +21,7 @@ changes.txt!.github/CLA-SETUP.md!docs/**/*.mddocker-compose.dev.yml+docker-compose.postgres.yml.clinerulestemp/.claude/diff --git a/src/init_db.py b/src/init_db.pyindex b81d2d6c..d52dcc91 100644--- a/src/init_db.py+++ b/src/init_db.py@@ -79,67 +79,72 @@ def initialize_database(app):app.logger.info("Added sso_subject column to user table")# Make password column nullable for SSO users- # SQLite doesn't support ALTER COLUMN, so we need to check and recreate if neededtry:inspector = inspect(engine)if 'user' in inspector.get_table_names():- # Check if password is NOT NULL by querying schema- with engine.connect() as conn:- result = conn.execute(text("SELECT sql FROM sqlite_master WHERE type='table' AND name='user'"))- schema = result.scalar()-- if schema and 'password VARCHAR(60) NOT NULL' in schema:- app.logger.info("Migrating user table to make password nullable for SSO support...")-- # Create new table with nullable password- conn.execute(text("""- CREATE TABLE user_new (- id INTEGER NOT NULL,- username VARCHAR(20) NOT NULL,- email VARCHAR(120) NOT NULL,- password VARCHAR(60),- is_admin BOOLEAN,- can_share_publicly BOOLEAN,- transcription_language VARCHAR(10),- output_language VARCHAR(50),- ui_language VARCHAR(10),- summary_prompt TEXT,- extract_events BOOLEAN,- name VARCHAR(100),- job_title VARCHAR(100),- company VARCHAR(100),- diarize BOOLEAN,- sso_provider VARCHAR(100),- sso_subject VARCHAR(255),- PRIMARY KEY (id),- UNIQUE (username),- UNIQUE (email)- )- """))-- # Copy all data from old table to new table- conn.execute(text("""- INSERT INTO user_new- SELECT id, username, email, password, is_admin, can_share_publicly,- transcription_language, output_language, ui_language,- summary_prompt, extract_events, name, job_title, company,- diarize, sso_provider, sso_subject- FROM user+ if engine.name == 'sqlite':+ # SQLite doesn't support ALTER COLUMN, so we need to check and recreate+ with engine.connect() as conn:+ result = conn.execute(text("SELECT sql FROM sqlite_master WHERE type='table' AND name='user'"))+ schema = result.scalar()++ if schema and 'password VARCHAR(60) NOT NULL' in schema:+ app.logger.info("Migrating user table to make password nullable for SSO support...")++ conn.execute(text("""+ CREATE TABLE user_new (+ id INTEGER NOT NULL,+ username VARCHAR(20) NOT NULL,+ email VARCHAR(120) NOT NULL,+ password VARCHAR(60),+ is_admin BOOLEAN,+ can_share_publicly BOOLEAN,+ transcription_language VARCHAR(10),+ output_language VARCHAR(50),+ ui_language VARCHAR(10),+ summary_prompt TEXT,+ extract_events BOOLEAN,+ name VARCHAR(100),+ job_title VARCHAR(100),+ company VARCHAR(100),+ diarize BOOLEAN,+ sso_provider VARCHAR(100),+ sso_subject VARCHAR(255),+ PRIMARY KEY (id),+ UNIQUE (username),+ UNIQUE (email)+ )+ """))+ conn.execute(text("""+ INSERT INTO user_new+ SELECT id, username, email, password, is_admin, can_share_publicly,+ transcription_language, output_language, ui_language,+ summary_prompt, extract_events, name, job_title, company,+ diarize, sso_provider, sso_subject+ FROM user+ """))+ conn.execute(text("DROP TABLE user"))+ conn.execute(text("ALTER TABLE user_new RENAME TO user"))+ conn.execute(text('CREATE UNIQUE INDEX IF NOT EXISTS ix_user_sso_subject ON "user" (sso_subject)'))+ conn.commit()+ app.logger.info("Successfully made password column nullable for SSO support")+ else:+ app.logger.info("Password column is already nullable, skipping migration")++ elif engine.name == 'postgresql':+ # PostgreSQL supports ALTER COLUMN directly+ with engine.connect() as conn:+ result = conn.execute(text("""+ SELECT is_nullable FROM information_schema.columns+ WHERE table_name = 'user' AND column_name = 'password'"""))-- # Drop old table- conn.execute(text("DROP TABLE user"))-- # Rename new table to user- conn.execute(text("ALTER TABLE user_new RENAME TO user"))-- # Recreate the unique index on sso_subject (quote "user" for PostgreSQL)- conn.execute(text('CREATE UNIQUE INDEX IF NOT EXISTS ix_user_sso_subject ON "user" (sso_subject)'))-- conn.commit()- app.logger.info("Successfully made password column nullable for SSO support")- else:- app.logger.info("Password column is already nullable, skipping migration")+ row = result.fetchone()+ if row and row[0] == 'NO':+ conn.execute(text('ALTER TABLE "user" ALTER COLUMN password DROP NOT NULL'))+ conn.commit()+ app.logger.info("Made password column nullable for SSO support (PostgreSQL)")+ else:+ app.logger.info("Password column is already nullable, skipping migration")except Exception as e:app.logger.warning(f"Could not migrate password column to nullable (may cause issues with SSO): {e}")@@ -203,7 +208,7 @@ def initialize_database(app):# Find tags with protect_from_deletion=True but retention_days != -1result = conn.execute(text("""SELECT COUNT(*) FROM tag- WHERE protect_from_deletion = 1+ WHERE protect_from_deletion = TRUEAND (retention_days IS NULL OR retention_days != -1)"""))count = result.scalar()@@ -213,7 +218,7 @@ def initialize_database(app):conn.execute(text("""UPDATE tagSET retention_days = -1- WHERE protect_from_deletion = 1+ WHERE protect_from_deletion = TRUEAND (retention_days IS NULL OR retention_days != -1)"""))conn.commit()@@ -249,7 +254,7 @@ def initialize_database(app):# Set all existing users to email_verified=True (grandfathered)try:with engine.connect() as conn:- conn.execute(text('UPDATE user SET email_verified = 1 WHERE email_verified = 0 OR email_verified IS NULL'))+ conn.execute(text('UPDATE "user" SET email_verified = TRUE WHERE email_verified = FALSE OR email_verified IS NULL'))conn.commit()app.logger.info("Set email_verified=True for all existing users (grandfathered)")except Exception as e:@@ -313,7 +318,7 @@ def initialize_database(app):WHERE rt.recording_id = internal_share.recording_idAND gm.user_id = internal_share.shared_with_user_idAND t.group_id IS NOT NULL- AND (t.auto_share_on_apply = 1 OR t.share_with_group_lead = 1)+ AND (t.auto_share_on_apply = TRUE OR t.share_with_group_lead = TRUE)LIMIT 1)WHERE source_type = 'manual'@@ -324,7 +329,7 @@ def initialize_database(app):WHERE rt.recording_id = internal_share.recording_idAND gm.user_id = internal_share.shared_with_user_idAND t.group_id IS NOT NULL- AND (t.auto_share_on_apply = 1 OR t.share_with_group_lead = 1)+ AND (t.auto_share_on_apply = TRUE OR t.share_with_group_lead = TRUE))'''))conn.commit()diff --git a/src/utils/database.py b/src/utils/database.pyindex 06777bc2..8b847592 100644--- a/src/utils/database.py+++ b/src/utils/database.py@@ -3,6 +3,7 @@ Database schema migration utilities.IMPORTANT: All migrations must be compatible with both SQLite and PostgreSQL.- Boolean defaults: SQLite uses 0/1, PostgreSQL requires FALSE/TRUE+- Type differences: SQLite DATETIME -> PostgreSQL TIMESTAMP, BLOB -> BYTEA- Reserved keywords: "user", "order" etc. must be quoted- The add_column_if_not_exists() function handles these automatically- Use create_index_if_not_exists() for index creation with proper quoting@@ -29,10 +30,17 @@ def add_column_if_not_exists(engine, table_name, column_name, column_type):columns = [col['name'] for col in inspector.get_columns(table_name)]if column_name not in columns:- # PostgreSQL requires TRUE/FALSE for boolean defaults, not 0/1- if engine.name == 'postgresql' and 'BOOLEAN' in column_type.upper():- column_type = column_type.replace('DEFAULT 0', 'DEFAULT FALSE')- column_type = column_type.replace('DEFAULT 1', 'DEFAULT TRUE')+ if engine.name == 'postgresql':+ # PostgreSQL requires TRUE/FALSE for boolean defaults, not 0/1+ if 'BOOLEAN' in column_type.upper():+ column_type = column_type.replace('DEFAULT 0', 'DEFAULT FALSE')+ column_type = column_type.replace('DEFAULT 1', 'DEFAULT TRUE')++ # PostgreSQL uses TIMESTAMP, not DATETIME+ column_type = re.sub(r'\bDATETIME\b', 'TIMESTAMP', column_type, flags=re.IGNORECASE)++ # PostgreSQL uses BYTEA, not BLOB+ column_type = re.sub(r'\bBLOB\b', 'BYTEA', column_type, flags=re.IGNORECASE)with engine.connect() as conn:# Quote identifiers to handle reserved keywords (e.g., "user" in PostgreSQL)diff --git a/static/css/styles.css b/static/css/styles.cssindex d53f7490..35376757 100644--- a/static/css/styles.css+++ b/static/css/styles.css@@ -3723,13 +3723,12 @@ body.fullscreen-mode {border-left: 1px solid var(--text-primary);}-/* Recording notes editor - fixed height with internal scrolling */+/* Recording notes editor - constrained height with internal scrolling */.recording-notes-editor {- flex: 1 !important; /* Take available space in flex container */display: flex !important;flex-direction: column !important;- min-height: 200px !important; /* Minimum usable height */- max-height: none !important; /* Allow parent to control max height */+ min-height: 150px !important; /* Minimum usable height */+ max-height: 35vh !important; /* Cap height so folder/tags/buttons stay visible */overflow: hidden !important; /* Prevent container from growing */}@@ -3757,15 +3756,14 @@ body.fullscreen-mode {min-height: auto !important; /* Don't force content to fill editor */}-/* Recording notes textarea fallback - fixed height with internal scrolling */+/* Recording notes textarea fallback - constrained height with internal scrolling */.recording-notes-editor textarea {background-color: var(--bg-input) !important;color: var(--text-primary) !important;border-color: var(--border-secondary) !important;- flex: 1 !important; /* Take available space */+ flex: 1 !important; /* Fill editor container */height: auto !important; /* Let flex control height */- min-height: 200px !important; /* Minimum usable height */- max-height: none !important; /* No max height - let parent control */+ min-height: 0 !important; /* Allow flex shrinking within capped parent */overflow-y: auto !important; /* Enable internal scrolling */resize: none !important; /* Prevent manual resizing */}@@ -3776,16 +3774,15 @@ body.fullscreen-mode {box-shadow: 0 0 0 2px var(--ring-focus) !important;}-/* Ensure all textareas in recording view use theme colors and fixed height */+/* Ensure all textareas in recording view use theme colors and constrained height */.recording-notes-editor textarea,textarea[ref="recordingNotesEditor"] {background-color: var(--bg-input) !important;color: var(--text-primary) !important;border: 1px solid var(--border-secondary) !important;- flex: 1 !important; /* Take available space */+ flex: 1 !important; /* Fill editor container */height: auto !important; /* Let flex control height */- min-height: 200px !important; /* Minimum usable height */- max-height: none !important; /* No max height - let parent control */+ min-height: 0 !important; /* Allow flex shrinking within capped parent */overflow-y: auto !important; /* Enable internal scrolling */resize: none !important; /* Prevent manual resizing */}diff --git a/static/js/modules/composables/audio.js b/static/js/modules/composables/audio.jsindex bca388ae..fb63b9e1 100644--- a/static/js/modules/composables/audio.js+++ b/static/js/modules/composables/audio.js@@ -15,7 +15,7 @@ export function useAudio(state, utils) {showRecordingDisclaimerModal, pendingRecordingMode, currentView, isDarkMode, wakeLock, animationFrameId,activeStreams, visualizer, micVisualizer, systemVisualizer, canRecordAudio,canRecordSystemAudio, systemAudioSupported, systemAudioError, globalError,- selectedTagIds, asrLanguage, asrMinSpeakers, asrMaxSpeakers, uploadQueue,+ selectedTagIds, selectedFolderId, asrLanguage, asrMinSpeakers, asrMaxSpeakers, uploadQueue,progressPopupMinimized, progressPopupClosed,// Incognito modeenableIncognitoMode, incognitoMode, incognitoRecording, incognitoProcessing,@@ -523,6 +523,8 @@ export function useAudio(state, utils) {file: recordedFile,notes: recordingNotes.value,tags: selectedTags, // Completely non-reactive deep copy+ folder_id: selectedFolderId.value,+ preserveOptions: true, // Prevents startUpload from overwriting recording's optionsasrOptions: {language: asrLanguage.value,min_speakers: asrMinSpeakers.value,diff --git a/static/js/modules/composables/upload.js b/static/js/modules/composables/upload.jsindex 0eb96c42..de131eae 100644--- a/static/js/modules/composables/upload.js+++ b/static/js/modules/composables/upload.js@@ -247,14 +247,16 @@ export function useUpload(state, utils) {// AND change their status to 'ready' so they move to upload progress immediatelyfor (const item of uploadQueue.value) {if (item.status === 'queued') {- // Always use the CURRENT tag selection - override whatever was captured at add time- item.tags = [...selectedTags.value];- // Always use the CURRENT ASR options- item.asrOptions = {- language: asrLanguage.value,- min_speakers: asrMinSpeakers.value,- max_speakers: asrMaxSpeakers.value- };+ if (!item.preserveOptions) {+ // For file uploads: use current UI selection (user may have changed tags after dropping)+ item.tags = [...selectedTags.value];+ item.asrOptions = {+ language: asrLanguage.value,+ min_speakers: asrMinSpeakers.value,+ max_speakers: asrMaxSpeakers.value+ };+ item.folder_id = selectedFolderId.value;+ }// Change status to 'ready' to remove from upload view but keep in queueitem.status = 'ready';}diff --git a/templates/components/recording-view.html b/templates/components/recording-view.htmlindex 60c3e3a9..ab8a2c57 100644--- a/templates/components/recording-view.html+++ b/templates/components/recording-view.html@@ -74,7 +74,7 @@<!-- Scrollable Content Area: Notes + Actions --><div class="flex-1 min-h-0 overflow-y-auto flex flex-col"><!-- Middle: Notepad (flexible height) -->- <div class="flex-1 p-3 md:p-6 flex flex-col" style="min-height: 200px;">+ <div class="p-3 md:p-6 flex flex-col"><label for="recordingNotes" class="block text-sm font-medium text-[var(--text-secondary)] mb-1.5 flex-shrink-0"><i class="fas fa-pencil-alt mr-1"></i>Recording Notes (Markdown)diff --git a/tests/test_migration_compatibility.py b/tests/test_migration_compatibility.pyindex b5dc418c..e40320c6 100644--- a/tests/test_migration_compatibility.py+++ b/tests/test_migration_compatibility.py@@ -59,6 +59,47 @@ class TestMigrationCompatibility(unittest.TestCase):"\n".join(f" - {m[:100]}..." if len(m) > 100 else f" - {m}" for m in problematic))+ def test_no_boolean_integer_comparisons_in_raw_sql(self):+ """+ Ensure raw SQL doesn't compare boolean columns to integers (0/1).++ PostgreSQL strictly separates boolean and integer types:+ - 'column = 1' fails with 'operator does not exist: boolean = integer'+ - 'column = TRUE' works on both SQLite (3.23+) and PostgreSQL++ Known boolean columns in migrations: protect_from_deletion, email_verified,+ auto_share_on_apply, share_with_group_lead, is_inbox, is_highlighted,+ deletion_exempt, is_admin, can_share_publicly.+ """+ boolean_columns = [+ 'protect_from_deletion', 'email_verified', 'auto_share_on_apply',+ 'share_with_group_lead', 'is_inbox', 'is_highlighted',+ 'deletion_exempt', 'is_admin', 'can_share_publicly',+ 'auto_speaker_labelling', 'auto_summarization'+ ]++ # Find raw SQL in text() calls+ sql_pattern = r"text\s*\(\s*['\"\"]\"\"(.*?)['\"\"]\"\"?\s*\)"+ # Simpler: find lines with known boolean column = 0 or = 1+ problematic = []+ for col in boolean_columns:+ # Match: column = 0 or column = 1 (not = TRUE/FALSE)+ pattern = rf"{col}\s*=\s*[01]\b"+ matches = re.finditer(pattern, self.content, re.IGNORECASE)+ for match in matches:+ # Get surrounding context to check if it's in a text() SQL call+ start = max(0, match.start() - 200)+ context = self.content[start:match.end() + 50]+ if 'text(' in context and 'sqlite_master' not in context:+ problematic.append(f"{col}: ...{match.group()}...")++ self.assertEqual(+ len(problematic), 0,+ f"Found boolean columns compared to integers in raw SQL. "+ f"Use TRUE/FALSE instead of 1/0 for PostgreSQL compatibility:\n" ++ "\n".join(f" - {p}" for p in problematic)+ )+def test_reserved_keywords_quoted_in_index_creation(self):"""Ensure reserved keywords like 'user' are properly quoted in index creation.@@ -116,6 +157,37 @@ class TestMigrationCompatibility(unittest.TestCase):f"Consider using the utility function for cross-database compatibility.")+ def test_incompatible_types_handled_by_utility(self):+ """+ Ensure columns with PostgreSQL-incompatible types (DATETIME, BLOB) are+ added through add_column_if_not_exists() which auto-converts them,+ and NOT via raw ALTER TABLE statements that would bypass conversion.++ PostgreSQL type differences:+ - DATETIME -> TIMESTAMP+ - BLOB -> BYTEA+ """+ incompatible_types = ['DATETIME', 'BLOB']++ # Check for raw ALTER TABLE statements using incompatible types+ for sql_type in incompatible_types:+ pattern = rf"conn\.execute\s*\(\s*text\s*\(['\"][^'\"]*ALTER\s+TABLE[^'\"]*\b{sql_type}\b[^'\"]*['\"]"+ matches = re.findall(pattern, self.content, re.IGNORECASE)++ self.assertEqual(+ len(matches), 0,+ f"Found raw ALTER TABLE statements using '{sql_type}' which is incompatible with PostgreSQL. "+ f"Use add_column_if_not_exists() which auto-converts types:\n" ++ "\n".join(f" - {m[:100]}..." if len(m) > 100 else f" - {m}" for m in matches)+ )++ # Verify that add_column_if_not_exists calls using these types exist+ # (confirming they go through the utility which handles conversion)+ for sql_type in incompatible_types:+ pattern = rf"add_column_if_not_exists\s*\([^)]*['\"]({sql_type})['\"]"+ matches = re.findall(pattern, self.content, re.IGNORECASE)+ # Just informational - these are fine because the utility converts them+def test_create_index_uses_utility_for_user_table(self):"""Ensure index creation on 'user' table uses create_index_if_not_exists().