Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat: backfill video file types script (#1503)
gbirman03d18ea826a9
diff --git a/rust/cloud-storage/macro_db_client/migrations/20260212200000_backfill_video_file_types.sql b/rust/cloud-storage/macro_db_client/migrations/20260212200000_backfill_video_file_types.sqldeleted file mode 100644index b1d19621b2..0000000000--- a/rust/cloud-storage/macro_db_client/migrations/20260212200000_backfill_video_file_types.sql+++ /dev/null@@ -1,19 +0,0 @@-UPDATE "Document"-SET "fileType" = CASE- WHEN "name" ILIKE '%.mkv' THEN 'mkv'- WHEN "name" ILIKE '%.webm' THEN 'webm'- WHEN "name" ILIKE '%.avi' THEN 'avi'- WHEN "name" ILIKE '%.mov' THEN 'mov'- WHEN "name" ILIKE '%.wmv' THEN 'wmv'- WHEN "name" ILIKE '%.mpg' THEN 'mpg'- WHEN "name" ILIKE '%.mpeg' THEN 'mpeg'- WHEN "name" ILIKE '%.m4v' THEN 'm4v'- WHEN "name" ILIKE '%.flv' THEN 'flv'- WHEN "name" ILIKE '%.f4v' THEN 'f4v'- WHEN "name" ILIKE '%.3gp' THEN '3gp'-END-WHERE "fileType" IS NULL- AND ("name" ILIKE '%.mkv' OR "name" ILIKE '%.webm' OR "name" ILIKE '%.avi'- OR "name" ILIKE '%.mov' OR "name" ILIKE '%.wmv' OR "name" ILIKE '%.mpg'- OR "name" ILIKE '%.mpeg' OR "name" ILIKE '%.m4v' OR "name" ILIKE '%.flv'- OR "name" ILIKE '%.f4v' OR "name" ILIKE '%.3gp');diff --git a/scripts/backfill-video-file-types.sh b/scripts/backfill-video-file-types.shnew file mode 100755index 0000000000..ba5b64af98--- /dev/null+++ b/scripts/backfill-video-file-types.sh@@ -0,0 +1,83 @@+#!/bin/bash+set -euo pipefail++DRY_RUN="${DRY_RUN:-false}"++if [ "$DRY_RUN" = "true" ]; then+ echo "=== DRY RUN MODE ==="+fi++if [ -z "${DATABASE_URL:-}" ]; then+ echo "DATABASE_URL is required"+ exit 1+fi++if [ -z "${S3_BUCKET:-}" ]; then+ echo "S3_BUCKET is required"+ exit 1+fi++VIDEO_EXTENSIONS="mov|mkv|webm|avi|wmv|mpg|mpeg|m4v|flv|f4v|3gp"++echo "=== Finding documents with null fileType and video extensions ==="++ROWS=$(psql "$DATABASE_URL" -t -A -F $'\t' -c "+ SELECT d.id, d.name, d.owner, di.id as version_id+ FROM \"Document\" d+ JOIN \"DocumentInstance\" di ON di.\"documentId\" = d.id+ WHERE d.\"fileType\" IS NULL+ AND d.name ~* '\.($VIDEO_EXTENSIONS)$'+")++if [ -z "$ROWS" ]; then+ echo "No documents to backfill."+ exit 0+fi++echo "$ROWS" | while IFS=$'\t' read -r doc_id name owner version_id; do+ extension=$(echo "$name" | grep -oiE "\.($VIDEO_EXTENSIONS)$" | tr '[:upper:]' '[:lower:]' | sed 's/^\.//')+ clean_name=$(echo "$name" | sed -E "s/\.($VIDEO_EXTENSIONS)$//i")+ old_key="${owner}/${doc_id}/${version_id}"+ new_key="${owner}/${doc_id}/${version_id}.${extension}"++ echo ""+ echo "--- Processing: $name (${doc_id}) ---"+ echo " extension: $extension"+ echo " old key: $old_key"+ echo " new key: $new_key"++ if [ "$DRY_RUN" = "true" ]; then+ echo " clean name: $clean_name"+ echo " [dry run] would copy S3 key and update DB"+ continue+ fi++ # Check if extensionless key exists+ if aws s3api head-object --bucket "$S3_BUCKET" --key "$old_key" > /dev/null 2>&1; then+ echo " S3: copying $old_key -> $new_key"+ aws s3api copy-object \+ --bucket "$S3_BUCKET" \+ --copy-source "${S3_BUCKET}/${old_key}" \+ --key "$new_key" > /dev/null+ echo " S3: copy complete"+ elif aws s3api head-object --bucket "$S3_BUCKET" --key "$new_key" > /dev/null 2>&1; then+ echo " S3: $new_key already exists, skipping copy"+ else+ echo " S3: WARNING - neither key exists, skipping"+ continue+ fi++ echo " DB: updating fileType='$extension', name='$clean_name'"+ psql "$DATABASE_URL" -c "+ UPDATE \"Document\"+ SET \"fileType\" = '$extension',+ \"name\" = '$clean_name'+ WHERE id = '$doc_id'+ AND \"fileType\" IS NULL;+ " > /dev/null++ echo " Done."+done++echo ""+echo "=== Backfill complete ==="