LifeMate — Personal, Family & Learning Companion
phase-5/hardening-observability-release
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
| 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 | const client = new Client( |
| 8 | databaseUrl |
| 9 | ? { |
| 10 | connectionString: databaseUrl, |
| 11 | ssl: |
| 12 | process.env.PGSSLMODE === 'require' |
| 13 | ? { rejectUnauthorized: false } |
| 14 | : false, |
| 15 | } |
| 16 | : { |
| 17 | host: process.env.PGHOST, |
| 18 | port: Number(process.env.PGPORT ?? 5432), |
| 19 | database: process.env.PGDATABASE, |
| 20 | user: process.env.PGUSER, |
| 21 | password: process.env.PGPASSWORD, |
| 22 | ssl: |
| 23 | process.env.PGSSLMODE === 'require' |
| 24 | ? { rejectUnauthorized: false } |
| 25 | : false, |
| 26 | }, |
| 27 | ); |
| 28 | |
| 29 | await client.connect(); |
| 30 | try { |
| 31 | await client.query(` |
| 32 | create table if not exists schema_migration ( |
| 33 | filename text primary key, |
| 34 | applied_at timestamptz not null default now() |
| 35 | ) |
| 36 | `); |
| 37 | |
| 38 | const dir = path.resolve('migrations'); |
| 39 | const files = (await fs.readdir(dir)) |
| 40 | .filter((name) => /^\d+_.*\.sql$/.test(name)) |
| 41 | .sort(); |
| 42 | |
| 43 | for (const filename of files) { |
| 44 | const exists = await client.query( |
| 45 | 'select 1 from schema_migration where filename=$1', |
| 46 | [filename], |
| 47 | ); |
| 48 | if (exists.rowCount) continue; |
| 49 | |
| 50 | const sql = await fs.readFile(path.join(dir, filename), 'utf8'); |
| 51 | await client.query('begin'); |
| 52 | try { |
| 53 | await client.query(sql); |
| 54 | await client.query( |
| 55 | 'insert into schema_migration(filename) values($1)', |
| 56 | [filename], |
| 57 | ); |
| 58 | await client.query('commit'); |
| 59 | console.log('applied', filename); |
| 60 | } catch (error) { |
| 61 | await client.query('rollback'); |
| 62 | throw error; |
| 63 | } |
| 64 | } |
| 65 | } finally { |
| 66 | await client.end(); |
| 67 | } |