LifeMate — Personal, Family & Learning Companion

phase-2/product-foundation-identity
chore/phase1-repository-cleanup deploy/stable-web-apk deployment-static design/mobile-accessibility-v2 design/mobile-navigation-review docs/child-education-access-decision docs/offline-data-rescue-options docs/owner-guide-and-delivery-plan docs/phase1-policy-options docs/public-review-live-2026-10-15 feat/aparat-learning-library feat/child-device-safety feat/child-identity-schema feat/flutter-mobile-navigation feat/learning-content-operations feat/local-signing-preflight feat/online-family-stage0 feat/personal-encrypted-recovery feat/private-planner-series-api feat/public-review-page feat/standalone-weekly-planner feat/weekly-planner-android final-feature-1/iran-family-school fix/auth-abuse-expiry-safety fix/auth-expiry-after-lock fix/backend-request-safety fix/lifeguide-bootstrap-naming-ci fix/lifeguide-pages-qa-base-preflight fix/lifeguide-qa-pages-env-deployment fix/local-task-persistence fix/managed-child-session-boundary fix/personal-jalali-dates fix/personal-notification-controls fix/personal-upgrade-delivery-guard fix/sms-approval-gates fix/study-duration-display infra/cloudflare-neon-migration infra/lifeguide-cloudflare-qa infra/lifeguide-github-pages-qa infra/lifeguide-supabase-qa main phase-1/foundation-completion phase-2/product-foundation-identity phase-3/planner-school-family-core phase-4/ai-learning-wellbeing phase-5/hardening-observability-release test/android-reminder-acceptance test/personal-notification-settings test/personal-recovery-acceptance test/role-entry-apk
js 52 lines 1.33 KB
Raw
1 import fs from 'node:fs/promises';
2 import path from 'node:path';
3 import pg from 'pg';
4
5 const { Client } = pg;
6 const databaseUrl = process.env.DATABASE_URL;
7 if (!databaseUrl) throw new Error('DATABASE_URL is required');
8
9 const client = new Client({
10 connectionString: databaseUrl,
11 ssl: databaseUrl.includes('localhost') ? false : { rejectUnauthorized: false },
12 });
13
14 await client.connect();
15 try {
16 await client.query(`
17 create table if not exists schema_migration (
18 filename text primary key,
19 applied_at timestamptz not null default now()
20 )
21 `);
22
23 const dir = path.resolve('migrations');
24 const files = (await fs.readdir(dir))
25 .filter((name) => /^\d+_.*\.sql$/.test(name))
26 .sort();
27
28 for (const filename of files) {
29 const exists = await client.query(
30 'select 1 from schema_migration where filename=$1',
31 [filename],
32 );
33 if (exists.rowCount) continue;
34
35 const sql = await fs.readFile(path.join(dir, filename), 'utf8');
36 await client.query('begin');
37 try {
38 await client.query(sql);
39 await client.query(
40 'insert into schema_migration(filename) values($1)',
41 [filename],
42 );
43 await client.query('commit');
44 console.log('applied', filename);
45 } catch (error) {
46 await client.query('rollback');
47 throw error;
48 }
49 }
50 } finally {
51 await client.end();
52 }