chore: archive-screenshots supabase-py 리팩터 + Storage 버킷 자동 생성
- sb_secret_* 신형 키 형식 지원을 위해 urllib → supabase-py 클라이언트로 전환 - ensure_bucket(): screenshots 버킷 없으면 public으로 자동 생성 - 41개 GCS 임시 스크린샷 → Supabase Storage 영구 URL로 아카이브 완료 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
9c4d10609f
commit
b84410341f
9 files changed
+678
-80
No files matched your search
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* npm run db:sync
|
||||
*
|
||||
* Fetches all marketing_reports from Supabase and writes them to src/data/db/.
|
||||
* Run this manually after SQL Editor updates if the dev server is not running.
|
||||
*/
|
||||
|
||||
import { createClient } from '@supabase/supabase-js';
|
||||
import { writeFileSync, mkdirSync, existsSync } from 'fs';
|
||||
import path from 'path';
|
||||
import { config } from 'dotenv';
|
||||
|
||||
config(); // load .env
|
||||
|
||||
const supabaseUrl = process.env.VITE_SUPABASE_URL!;
|
||||
const key = process.env.SUPABASE_SERVICE_ROLE_KEY ?? process.env.VITE_SUPABASE_ANON_KEY!;
|
||||
|
||||
if (!supabaseUrl || !key) {
|
||||
console.error('❌ Missing VITE_SUPABASE_URL or SUPABASE_SERVICE_ROLE_KEY in .env');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const supabase = createClient(supabaseUrl, key, { auth: { persistSession: false } });
|
||||
const outDir = path.resolve('src/data/db');
|
||||
|
||||
if (!existsSync(outDir)) mkdirSync(outDir, { recursive: true });
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('marketing_reports')
|
||||
.select('id, clinic_name, url, status, report, channel_data, scrape_data, created_at, updated_at')
|
||||
.order('created_at', { ascending: false });
|
||||
|
||||
if (error) {
|
||||
console.error('❌ Supabase error:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const rows = data ?? [];
|
||||
for (const row of rows) {
|
||||
writeFileSync(path.join(outDir, `${row.id}.json`), JSON.stringify(row, null, 2), 'utf-8');
|
||||
}
|
||||
|
||||
// Write index
|
||||
const index = rows.map((r: any) => ({
|
||||
id: r.id,
|
||||
clinic_name: r.clinic_name,
|
||||
url: r.url,
|
||||
status: r.status,
|
||||
created_at: r.created_at,
|
||||
gu_rating: r.channel_data?.gangnamUnni?.rating ?? null,
|
||||
lead_doctor: r.report?.clinicInfo?.leadDoctor?.name ?? null,
|
||||
}));
|
||||
writeFileSync(path.join(outDir, '_index.json'), JSON.stringify(index, null, 2), 'utf-8');
|
||||
|
||||
console.log(`✅ Synced ${rows.length} report(s) → ${outDir}`);
|
||||
console.table(index.map((r: any) => ({
|
||||
id: r.id.slice(0, 8),
|
||||
clinic: r.clinic_name,
|
||||
status: r.status,
|
||||
gu: r.gu_rating,
|
||||
doctor: r.lead_doctor,
|
||||
})));
|
||||
Reference in new issue
Block a user