πŸ“„ SKILL.md

← Vault

name: doccorretor-drive-migration

description: One-time migration of documents from Google Drive to DocCorretor β€” copy files to VPS storage, insert DB records via Edge Function. Includes 502/cloudflared tunnel fix.

tags:

- doccorretor

- google-drive

- migration

- supabase


DocCorretor Google Drive Migration (Executed Jun 2026)

⚠️ Migration Scope (Jun 2026 Update)

The initial migration covered ~138 documents (12 clients from 2023/08). The full Drive has 396 client folders across 4 years (2023–2026). Many folders were never migrated.

Drive year folder IDs (root for each year):

`

2023: 1nObuuq8AhcUo-O96UdhaTBbrjaRzI4lP

2024: 1CcabJC1HF1V-tVUlq9IjkpCLNYRMN_l5

2025: 17-KPk4ttAvtmz2hCXarIiW4O0MPh4rGZ

2026: 1rlhX77Rq5F40qctMFMP7k2AxD5-U3rSS

`

2024 month folder IDs:

`

02/2024: 1x_cZiLZMauYi1xOL5BsvMEruoqkfkyHj

03/2024: 1RtjJGHcrnbO25sHjuhJCF7Xh1x4Rgwyu

04/2024: 159STuwNcVd-mduJRejWFTWgeSOiIKrMZ

05/2024: 1mH9NKgzaljcmzZT812iPVkWfqms2M-zh

06/2024: 1nuFUpQ9z4UEr23J2gL6U339hoQ8WW3EV

07/2024: 1uadYZGkAKXcseD9bOWlG11ND43lOlpEO

08/2024: 1r2jnjUNJf_zSEaqdJNx21Uwp9jHOJ7Ta

09/2024: 1tvu4Sx74Yz15BGII7HV-oY9bPhgURJfW

10/2024: 1i7hfyBpcizqneqM3zdPMXeDtK5j4Olk7

11/2024: 1N7LVycNNROxCdchb66bP3DYFyAOweXUu

12/2024: 142tIHP8ja86ISJIAnA2wxNM-BfPKYph6

`

2026 month folder IDs:

`

03/2026: 1KzyVHG3vOfZ9_5zgz7x4HL_vdtvF3-Bw

04/2026: 1u2Hhlbg05mr7jJX3_oOBnH9KBOxG9gmu

05/2026: 1cJ-qMSVKsM_vwDXhUczzBU685XR99rrs

06/2026: 1Y8ghviSlw5-h4fARIy45Xgz0y7Seta2z

`

⚠️ rclone Token Expired β€” Use gdown Locally Instead

The VPS rclone config (/root/.config/rclone/rclone.conf) has an expired token with no refresh token.

VPS has no pip β€” cannot install gdown there.

Solution: Use gdown locally (hermes-agent venv):

`bash

/root/.hermes/hermes-agent/venv/bin/gdown {folder_id} -O /tmp/dest/ --folder

`

Available at: /root/.hermes/hermes-agent/venv/bin/gdown (Python 3.11.15)

Then SCP to VPS, fix permissions, insert via Management API (see below).

Completed: 138 documents migrated across 12 clients (Jun 2026)

Files copied to /var/www/documentos/uploads/5a4ebb41-9e54-47b3-86eb-1c18bc01ad5a/{client_id}/.

12 client folders created in client_folders table.


Architecture (Critical Finding)

Edge Functions run on Supabase's servers, NOT on the VPS. They cannot access local VPS files.

Two-step approach required:

1. Python script on VPS β†’ copies files from /tmp/drive_docs/ to storage

2. Edge Function on Supabase β†’ inserts DB records (uses service_role, bypasses RLS)

Schema (Supabase Cloud β€” project dauftiqcvgaydddoxqhh)

client_folders β€” FLAT structure (no is_folder/parent_id)

`

id | client_id | name | created_by | created_at

`

This is correct β€” both Drive folders belong to the same client in the DB.

⚠️ Outstanding work (as of Jun 2026): 47 Drive client folders from 2023/08, 2024/08, and 2026/03-06 were identified in Drive but NOT migrated. These clients were created in DB (via Management API create_clients_bulk equivalent), but their Drive files were never downloaded/uploaded. Full Drive structure (396 folders) was mapped β€” see /tmp/drive_2023.json, /tmp/drive_2024.json, /tmp/drive_2025.json, /tmp/drive_2026.json for the complete client list with folder IDs.