()
| 32 | ]; |
| 33 | |
| 34 | async function main() { |
| 35 | initializeDatabase({ connectionString: process.env.DATABASE_URL || '' }); |
| 36 | const pool = getPool(); |
| 37 | |
| 38 | // Find the perspective |
| 39 | const perspResult = await pool.query( |
| 40 | `SELECT id FROM perspectives WHERE slug = $1`, |
| 41 | [PERSPECTIVE_SLUG] |
| 42 | ); |
| 43 | |
| 44 | if (perspResult.rows.length === 0) { |
| 45 | console.log(`Perspective "${PERSPECTIVE_SLUG}" not found — skipping migration.`); |
| 46 | await pool.end(); |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | const perspectiveId = perspResult.rows[0].id; |
| 51 | console.log(`Found perspective ${perspectiveId} (${PERSPECTIVE_SLUG})`); |
| 52 | |
| 53 | for (const asset of ASSETS) { |
| 54 | const fullPath = resolve(process.cwd(), asset.path); |
| 55 | if (!existsSync(fullPath)) { |
| 56 | console.log(` Skipping ${asset.path} — file not found`); |
| 57 | continue; |
| 58 | } |
| 59 | |
| 60 | const fileData = readFileSync(fullPath); |
| 61 | console.log(` Reading ${asset.path} (${(fileData.length / 1024).toFixed(0)} KB)`); |
| 62 | |
| 63 | const result = await createAsset({ |
| 64 | perspective_id: perspectiveId, |
| 65 | asset_type: asset.assetType, |
| 66 | file_name: asset.fileName, |
| 67 | file_mime_type: asset.mimeType, |
| 68 | file_data: fileData, |
| 69 | }); |
| 70 | |
| 71 | const assetUrl = `${BASE_URL}/api/perspectives/${PERSPECTIVE_SLUG}/assets/${asset.fileName}`; |
| 72 | console.log(` Stored as ${result.id} → ${assetUrl}`); |
| 73 | |
| 74 | // Update featured_image_url for cover image |
| 75 | if (asset.assetType === 'cover_image') { |
| 76 | await pool.query( |
| 77 | `UPDATE perspectives SET featured_image_url = $1, updated_at = NOW() WHERE id = $2`, |
| 78 | [assetUrl, perspectiveId] |
| 79 | ); |
| 80 | console.log(` Updated featured_image_url`); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // Update article content to use new asset URL for report |
| 85 | const reportUrl = `/api/perspectives/${PERSPECTIVE_SLUG}/assets/report.pdf`; |
| 86 | await pool.query( |
| 87 | `UPDATE perspectives |
| 88 | SET content = REPLACE(content, '/reports/building-the-future-of-marketing.pdf', $1), |
| 89 | updated_at = NOW() |
| 90 | WHERE id = $2`, |
| 91 | [reportUrl, perspectiveId] |
no test coverage detected