fix(import): decouple scan from HTTP connection, prevent duplicate imports
- Add scan_manager: background asyncio task + Redis event store so scans survive UI navigation; SSE stream reads from Redis and is reconnectable - Replace SSE-tied scan endpoint with POST /nc-scan/start + GET /nc-scan/stream - Fix frontend: AbortController + useEffect cleanup cancels stream on unmount without stopping the server-side scan - Add unique constraint on audio_versions.nc_file_path (migration 0009) to prevent duplicate imports from concurrent scans; handle IntegrityError gracefully in nc_scan with rollback + skip - Fix API health check: use plain python instead of uv (not in dev image) - Optimize Taskfile: fix duplicate dev:restart, add dev:fresh/dev:rebuild/ dev:status, migrate uses run --rm, check includes typecheck Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
36
api/alembic/versions/0009_audio_version_nc_path_unique.py
Normal file
36
api/alembic/versions/0009_audio_version_nc_path_unique.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""Add unique constraint on audio_versions.nc_file_path.
|
||||
|
||||
Prevents duplicate imports when concurrent scans race on the same file.
|
||||
|
||||
Revision ID: 0009_av_nc_path_uq
|
||||
Revises: 0008_drop_nc_columns
|
||||
Create Date: 2026-04-12
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision = "0009_av_nc_path_uq"
|
||||
down_revision = "0008_drop_nc_columns"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Remove any existing duplicates first (keep the oldest version per path)
|
||||
op.execute("""
|
||||
DELETE FROM audio_versions
|
||||
WHERE id NOT IN (
|
||||
SELECT DISTINCT ON (nc_file_path) id
|
||||
FROM audio_versions
|
||||
ORDER BY nc_file_path, uploaded_at ASC
|
||||
)
|
||||
""")
|
||||
op.create_unique_constraint(
|
||||
"uq_audio_version_nc_file_path",
|
||||
"audio_versions",
|
||||
["nc_file_path"],
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_constraint("uq_audio_version_nc_file_path", "audio_versions", type_="unique")
|
||||
Reference in New Issue
Block a user