Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Add PostgreSQL CI integration test, fix export template i18n, fix dropdown z-index

Murtaza Nasire89cd3927035
diff --git a/.github/workflows/test-postgres.yml b/.github/workflows/test-postgres.yml
new file mode 100644
index 00000000..567f77de
--- /dev/null
+++ b/.github/workflows/test-postgres.yml
@@ -0,0 +1,56 @@
+name: PostgreSQL Migration Tests
+
+on:
+ push:
+ paths:
+ - 'src/init_db.py'
+ - 'src/utils/database.py'
+ - 'src/models/**'
+ - 'tests/test_postgres_migrations.py'
+ - 'tests/test_migration_compatibility.py'
+ pull_request:
+ paths:
+ - 'src/init_db.py'
+ - 'src/utils/database.py'
+ - 'src/models/**'
+ - 'tests/test_postgres_migrations.py'
+ - 'tests/test_migration_compatibility.py'
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+
+ services:
+ postgres:
+ image: postgres:16
+ env:
+ POSTGRES_USER: speakr
+ POSTGRES_PASSWORD: speakr
+ POSTGRES_DB: speakr_test
+ ports:
+ - 5432:5432
+ options: >-
+ --health-cmd "pg_isready -U speakr"
+ --health-interval 10s
+ --health-timeout 5s
+ --health-retries 5
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Set up Python
+ uses: actions/setup-python@v5
+ with:
+ python-version: '3.11'
+
+ - name: Install dependencies
+ run: pip install -r requirements.txt
+
+ - name: Run static migration compatibility tests
+ run: python tests/test_migration_compatibility.py
+
+ - name: Run migrations against PostgreSQL
+ env:
+ TEST_DATABASE_URI: postgresql://speakr:speakr@localhost:5432/speakr_test
+ run: python tests/test_postgres_migrations.py
diff --git a/scripts/pre-commit b/scripts/pre-commit
index 692ddeeb..592cd0d5 100755
--- a/scripts/pre-commit
+++ b/scripts/pre-commit
@@ -8,7 +8,7 @@
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
# Only run if migration-related files are staged
-if echo "$STAGED_FILES" | grep -qE '^(src/init_db\.py|src/utils/database\.py)$'; then
+if echo "$STAGED_FILES" | grep -qE '^(src/init_db\.py|src/utils/database\.py|src/models/)'; then
echo "Migration files changed — running PostgreSQL compatibility checks..."
python tests/test_migration_compatibility.py
if [ $? -ne 0 ]; then
diff --git a/static/locales/de.json b/static/locales/de.json
index c31755f7..7b352ed2 100644
--- a/static/locales/de.json
+++ b/static/locales/de.json
@@ -534,6 +534,9 @@
"leaveBlankPrompt": "Leer lassen, um Ihren Standard-Zusammenfassungs-Prompt zu verwenden",
"maxSpeakers": "Maximale Sprecheranzahl",
"minSpeakers": "Minimale Sprecheranzahl",
+ "exportTemplate": "Exportvorlage",
+ "exportTemplateHint": "Wählen Sie eine Exportvorlage für den Export von Aufnahmen mit diesem Tag",
+ "noExportTemplate": "Keine Vorlage (Benutzerstandard verwenden)",
"tagName": "Tag-Name *",
"tagNamePlaceholder": "z.B. Meetings, Interviews",
"title": "Tag Bearbeiten"
diff --git a/static/locales/en.json b/static/locales/en.json
index dc0b3841..839cc04d 100644
--- a/static/locales/en.json
+++ b/static/locales/en.json
@@ -520,6 +520,9 @@
"minSpeakers": "Min Speakers",
"namingTemplate": "Naming Template",
"namingTemplateHint": "Select a naming template to automatically format titles for recordings with this tag",
+ "exportTemplate": "Export Template",
+ "exportTemplateHint": "Select an export template to use when exporting recordings with this tag",
+ "noExportTemplate": "No template (use user default)",
"noNamingTemplate": "No template (use user default or AI title)",
"tagName": "Tag Name *",
"tagNamePlaceholder": "e.g., Meetings, Interviews",
diff --git a/static/locales/es.json b/static/locales/es.json
index 4ee5b5a8..0885d800 100644
--- a/static/locales/es.json
+++ b/static/locales/es.json
@@ -534,6 +534,9 @@
"leaveBlankPrompt": "Deja en blanco para usar tu prompt de resumen predeterminado",
"maxSpeakers": "Máximo de Oradores",
"minSpeakers": "Mínimo de Oradores",
+ "exportTemplate": "Plantilla de exportación",
+ "exportTemplateHint": "Selecciona una plantilla de exportación para usar al exportar grabaciones con esta etiqueta",
+ "noExportTemplate": "Sin plantilla (usar predeterminado del usuario)",
"tagName": "Nombre de la Etiqueta *",
"tagNamePlaceholder": "ej., Reuniones, Entrevistas",
"title": "Editar Etiqueta"
diff --git a/static/locales/fr.json b/static/locales/fr.json
index 824ec138..3d295d8d 100644
--- a/static/locales/fr.json
+++ b/static/locales/fr.json
@@ -528,6 +528,9 @@
"leaveBlankPrompt": "Laissez vide pour utiliser votre invite de résumé par défaut",
"maxSpeakers": "Maximum d'Intervenants",
"minSpeakers": "Minimum d'Intervenants",
+ "exportTemplate": "Modèle d'exportation",
+ "exportTemplateHint": "Sélectionnez un modèle d'exportation à utiliser lors de l'exportation des enregistrements avec cette étiquette",
+ "noExportTemplate": "Aucun modèle (utiliser le défaut de l'utilisateur)",
"tagName": "Nom de l'Étiquette *",
"tagNamePlaceholder": "ex., Réunions, Entretiens",
"title": "Modifier l'Étiquette"
diff --git a/static/locales/ru.json b/static/locales/ru.json
index a14f1a9d..541bbd7a 100644
--- a/static/locales/ru.json
+++ b/static/locales/ru.json
@@ -516,6 +516,9 @@
"leaveBlankPrompt": "Оставьте пустым, чтобы использовать ваш запрос резюмирования по умолчанию",
"maxSpeakers": "Макс. спикеров",
"minSpeakers": "Мин. спикеров",
+ "exportTemplate": "Шаблон экспорта",
+ "exportTemplateHint": "Выберите шаблон экспорта для использования при экспорте записей с этим тегом",
+ "noExportTemplate": "Без шаблона (использовать пользовательский по умолчанию)",
"tagName": "Название тега *",
"tagNamePlaceholder": "например, Встречи, Интервью",
"title": "Редактирование тега"
diff --git a/static/locales/zh.json b/static/locales/zh.json
index 974b513d..9442e583 100644
--- a/static/locales/zh.json
+++ b/static/locales/zh.json
@@ -606,6 +606,9 @@
"leaveBlankPrompt": "留空以使用您的默认摘要提示",
"maxSpeakers": "最大发言人数",
"minSpeakers": "最小发言人数",
+ "exportTemplate": "导出模板",
+ "exportTemplateHint": "选择导出带有此标签的录音时使用的导出模板",
+ "noExportTemplate": "无模板(使用用户默认)",
"tagName": "标签名称 *",
"tagNamePlaceholder": "例如,会议、访谈",
"title": "编辑标签"
diff --git a/templates/account.html b/templates/account.html
index 7c5f4fc7..647a4db6 100644
--- a/templates/account.html
+++ b/templates/account.html
@@ -408,7 +408,7 @@
<span>{{ current_user.username }}</span>
<i class="fas fa-chevron-down ml-2"></i>
</button>
- <div id="userDropdownMenu" class="hidden absolute right-0 mt-2 w-48 bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-lg shadow-lg z-10">
+ <div id="userDropdownMenu" class="hidden absolute right-0 mt-2 w-48 bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-lg shadow-lg z-50">
<a href="{{ url_for('recordings.index') }}" class="block px-4 py-2 text-[var(--text-secondary)] hover:bg-[var(--bg-tertiary)] hover:text-[var(--text-accent)]">
<i class="fas fa-home mr-2"></i> <span data-i18n="nav.home">Home</span>
</a>
diff --git a/tests/test_postgres_migrations.py b/tests/test_postgres_migrations.py
new file mode 100644
index 00000000..7ea39d27
--- /dev/null
+++ b/tests/test_postgres_migrations.py
@@ -0,0 +1,165 @@
+"""
+Integration test for database migrations against a real database engine.
+
+Runs initialize_database() and verifies that all tables and critical columns
+are created successfully. Works with both SQLite (default, for local runs)
+and PostgreSQL (when TEST_DATABASE_URI env var is set).
+
+IMPORTANT: This test uses TEST_DATABASE_URI (not SQLALCHEMY_DATABASE_URI) to
+avoid accidentally connecting to and destroying a real application database.
+
+Usage:
+ # Local (SQLite in-memory, safe):
+ python tests/test_postgres_migrations.py
+
+ # Against PostgreSQL (CI or explicit testing):
+ TEST_DATABASE_URI=postgresql://user:pass@localhost:5432/testdb \
+ python tests/test_postgres_migrations.py
+"""
+
+import os
+import sys
+import unittest
+
+# Ensure project root is on the path
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
+
+from flask import Flask
+from src.database import db
+# Importing models registers them with SQLAlchemy so create_all() builds all tables
+import src.models # noqa: F401
+from src.init_db import initialize_database
+
+
+def create_test_app():
+ """Create a minimal Flask app for testing database operations.
+
+ Uses TEST_DATABASE_URI env var (NOT SQLALCHEMY_DATABASE_URI) to prevent
+ accidental connection to production/dev databases.
+ """
+ app = Flask(__name__)
+ app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get(
+ 'TEST_DATABASE_URI', 'sqlite://' # in-memory SQLite by default
+ )
+ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
+ app.config['TESTING'] = True
+ db.init_app(app)
+ return app
+
+
+class TestDatabaseMigrations(unittest.TestCase):
+ """Test that initialize_database() runs cleanly against the configured DB engine."""
+
+ @classmethod
+ def setUpClass(cls):
+ cls.app = create_test_app()
+ with cls.app.app_context():
+ initialize_database(cls.app)
+
+ @classmethod
+ def tearDownClass(cls):
+ with cls.app.app_context():
+ # Use raw DROP to avoid circular FK dependency errors in SQLAlchemy's
+ # drop_all() (user <-> naming_template have mutual foreign keys)
+ from sqlalchemy import inspect, text
+ tables = inspect(db.engine).get_table_names()
+ with db.engine.connect() as conn:
+ if db.engine.name == 'postgresql':
+ for table in tables:
+ conn.execute(text(f'DROP TABLE IF EXISTS "{table}" CASCADE'))
+ else:
+ conn.execute(text('PRAGMA foreign_keys = OFF'))
+ for table in tables:
+ conn.execute(text(f'DROP TABLE IF EXISTS "{table}"'))
+ conn.execute(text('PRAGMA foreign_keys = ON'))
+ conn.commit()
+
+ def _get_table_names(self):
+ from sqlalchemy import inspect
+ inspector = inspect(db.engine)
+ return inspector.get_table_names()
+
+ def _get_column_names(self, table):
+ from sqlalchemy import inspect
+ inspector = inspect(db.engine)
+ return [col['name'] for col in inspector.get_columns(table)]
+
+ def test_core_tables_exist(self):
+ """Verify that all core tables were created."""
+ with self.app.app_context():
+ tables = self._get_table_names()
+ expected_tables = [
+ 'user', 'recording', 'transcript_chunk', 'tag',
+ 'folder', 'share', 'internal_share', 'system_setting',
+ 'speaker', 'processing_job', 'group', 'group_membership',
+ ]
+ for table in expected_tables:
+ self.assertIn(table, tables, f"Missing table: {table}")
+
+ def test_user_migration_columns(self):
+ """Verify columns added by migrations exist on the user table."""
+ with self.app.app_context():
+ columns = self._get_column_names('user')
+ expected = [
+ 'id', 'username', 'email', 'password',
+ 'transcription_language', 'output_language', 'ui_language',
+ 'summary_prompt', 'extract_events', 'name', 'job_title',
+ 'company', 'diarize', 'sso_provider', 'sso_subject',
+ 'can_share_publicly', 'monthly_token_budget',
+ 'monthly_transcription_budget', 'email_verified',
+ 'auto_speaker_labelling', 'auto_summarization',
+ ]
+ for col in expected:
+ self.assertIn(col, columns, f"Missing user column: {col}")
+
+ def test_recording_migration_columns(self):
+ """Verify columns added by migrations exist on the recording table."""
+ with self.app.app_context():
+ columns = self._get_column_names('recording')
+ expected = [
+ 'id', 'is_inbox', 'is_highlighted', 'mime_type',
+ 'completed_at', 'processing_time_seconds', 'error_message',
+ 'folder_id', 'audio_deleted_at', 'deletion_exempt',
+ 'speaker_embeddings',
+ ]
+ for col in expected:
+ self.assertIn(col, columns, f"Missing recording column: {col}")
+
+ def test_tag_migration_columns(self):
+ """Verify columns added by migrations exist on the tag table."""
+ with self.app.app_context():
+ columns = self._get_column_names('tag')
+ expected = [
+ 'id', 'protect_from_deletion', 'group_id',
+ 'retention_days', 'auto_share_on_apply',
+ 'naming_template_id', 'export_template_id',
+ ]
+ for col in expected:
+ self.assertIn(col, columns, f"Missing tag column: {col}")
+
+ def test_system_settings_initialized(self):
+ """Verify that default system settings were created."""
+ with self.app.app_context():
+ from src.models import SystemSetting
+ expected_keys = [
+ 'transcript_length_limit', 'max_file_size_mb',
+ 'asr_timeout_seconds', 'disable_auto_summarization',
+ 'enable_folders',
+ ]
+ for key in expected_keys:
+ setting = SystemSetting.query.filter_by(key=key).first()
+ self.assertIsNotNone(setting, f"Missing system setting: {key}")
+
+ def test_engine_type_matches_expectation(self):
+ """Sanity check: confirm we're testing against the expected engine."""
+ with self.app.app_context():
+ uri = self.app.config['SQLALCHEMY_DATABASE_URI']
+ engine_name = db.engine.name
+ if uri.startswith('postgresql'):
+ self.assertEqual(engine_name, 'postgresql')
+ else:
+ self.assertEqual(engine_name, 'sqlite')
+
+
+if __name__ == '__main__':
+ unittest.main()