LifeMate — Personal, Family & Learning Companion
docs/child-education-access-decision
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 | // Explicit operations entrypoint; never imported or executed by the API. |
| 2 | import pg from 'pg'; |
| 3 | import { prepareRoles,reconcileGrants } from './db-role-policy.js'; |
| 4 | |
| 5 | const args = process.argv.slice(2); |
| 6 | const mode = args.shift(); |
| 7 | let adoptOwner,backupFile; |
| 8 | if (args.length) { |
| 9 | if (mode !== '--prepare' || args[0] !== '--adopt-existing' || args[1] !== '--expected-owner' || args[3] !== '--backup-file' || args.length !== 5) { |
| 10 | throw new Error('Usage: --prepare [--adopt-existing --expected-owner ROLE --backup-file PATH] or --grants'); |
| 11 | } |
| 12 | adoptOwner=args[2]; backupFile=args[4]; |
| 13 | } |
| 14 | if (!['--prepare','--grants'].includes(mode)) throw new Error('Use --prepare or --grants explicitly'); |
| 15 | const client = new pg.Client(); |
| 16 | try { |
| 17 | await client.connect(); |
| 18 | if (mode === '--prepare') { |
| 19 | const result = await prepareRoles(client,{adoptOwner,backupFile}); |
| 20 | console.log(`PASS database roles prepared; adoption=${result.adopted}; ${result.backupDigest ? `archive SHA256=${result.backupDigest} (decoding checked separately by operator helper)` : 'existing ownership preserved'}`); |
| 21 | } else { |
| 22 | await reconcileGrants(client); |
| 23 | console.log('PASS database grants reconciled; API has no ledger/DDL rights and backup is read-only'); |
| 24 | } |
| 25 | } catch (error) { |
| 26 | // No SQL, connection strings or credential contents in operator logs. |
| 27 | console.error(`Database role operation failed: ${error.code ?? 'policy'}; ${error.code ? 'inspect role/ownership metadata without secrets' : error.message}`); |
| 28 | process.exitCode=1; |
| 29 | } finally { await client.end(); } |