{"version":3,"file":"switchboard-migrate-7JQZM7-5.mjs","sources":["../src/services/switchboard-migrate.ts"],"sourcesContent":["import { Kysely, PostgresDialect } from \"kysely\";\nimport { Pool } from \"pg\";\nimport {\n  runMigrations,\n  getMigrationStatus,\n  REACTOR_SCHEMA,\n} from \"@powerhousedao/reactor\";\n\ninterface MigrationOptions {\n  dbPath?: string;\n  statusOnly?: boolean;\n}\n\nfunction isPostgresUrl(url: string): boolean {\n  return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nexport async function runSwitchboardMigrations(\n  options: MigrationOptions,\n): Promise<void> {\n  const dbPath =\n    options.dbPath ??\n    process.env.PH_REACTOR_DATABASE_URL ??\n    process.env.DATABASE_URL;\n\n  if (!dbPath || !isPostgresUrl(dbPath)) {\n    console.log(\"No PostgreSQL URL configured. Skipping migrations.\");\n    console.log(\"(PGlite migrations are handled automatically on startup)\");\n    return;\n  }\n\n  console.log(`Database: ${dbPath}`);\n\n  const pool = new Pool({ connectionString: dbPath });\n\n  const db = new Kysely<any>({\n    dialect: new PostgresDialect({ pool }),\n  });\n\n  try {\n    if (options.statusOnly) {\n      console.log(\"\\nChecking migration status...\");\n      const migrations = await getMigrationStatus(db, REACTOR_SCHEMA);\n\n      console.log(\"\\nMigration Status:\");\n      console.log(\"=================\");\n\n      for (const migration of migrations) {\n        const status = migration.executedAt\n          ? `[OK] Executed at ${migration.executedAt.toISOString()}`\n          : \"[--] Pending\";\n        console.log(`${status} - ${migration.name}`);\n      }\n    } else {\n      console.log(\"\\nRunning migrations...\");\n      const result = await runMigrations(db, REACTOR_SCHEMA);\n\n      if (!result.success) {\n        console.error(\"Migration failed:\", result.error?.message);\n        process.exit(1);\n      }\n\n      if (result.migrationsExecuted.length === 0) {\n        console.log(\"No migrations to run - database is up to date\");\n      } else {\n        console.log(\n          `Successfully executed ${result.migrationsExecuted.length} migration(s):`,\n        );\n        for (const name of result.migrationsExecuted) {\n          console.log(`  - ${name}`);\n        }\n      }\n    }\n  } catch (error) {\n    console.error(\n      \"Error:\",\n      error instanceof Error ? error.message : String(error),\n    );\n    process.exit(1);\n  } finally {\n    await db.destroy();\n  }\n}\n"],"names":[],"mappings":";;;;;;AAaA,SAAS,cAAc,KAAsB;CAC3C,OAAO,IAAI,WAAW,eAAe,KAAK,IAAI,WAAW,aAAa;AACxE;AAEA,eAAsB,yBACpB,SACe;CACf,MAAM,SACJ,QAAQ,UACR,QAAQ,IAAI,2BACZ,QAAQ,IAAI;CAEd,IAAI,CAAC,UAAU,CAAC,cAAc,MAAM,GAAG;EACrC,QAAQ,IAAI,oDAAoD;EAChE,QAAQ,IAAI,0DAA0D;EACtE;CACF;CAEA,QAAQ,IAAI,aAAa,QAAQ;CAEjC,MAAM,OAAO,IAAI,KAAK,EAAE,kBAAkB,OAAO,CAAC;CAElD,MAAM,KAAK,IAAI,OAAY,EACzB,SAAS,IAAI,gBAAgB,EAAE,KAAK,CAAC,EACvC,CAAC;CAED,IAAI;EACF,IAAI,QAAQ,YAAY;GACtB,QAAQ,IAAI,gCAAgC;GAC5C,MAAM,aAAa,MAAM,mBAAmB,IAAI,cAAc;GAE9D,QAAQ,IAAI,qBAAqB;GACjC,QAAQ,IAAI,mBAAmB;GAE/B,KAAK,MAAM,aAAa,YAAY;IAClC,MAAM,SAAS,UAAU,aACrB,oBAAoB,UAAU,WAAW,YAAY,MACrD;IACJ,QAAQ,IAAI,GAAG,OAAO,KAAK,UAAU,MAAM;GAC7C;EACF,OAAO;GACL,QAAQ,IAAI,yBAAyB;GACrC,MAAM,SAAS,MAAM,cAAc,IAAI,cAAc;GAErD,IAAI,CAAC,OAAO,SAAS;IACnB,QAAQ,MAAM,qBAAqB,OAAO,OAAO,OAAO;IACxD,QAAQ,KAAK,CAAC;GAChB;GAEA,IAAI,OAAO,mBAAmB,WAAW,GACvC,QAAQ,IAAI,+CAA+C;QACtD;IACL,QAAQ,IACN,yBAAyB,OAAO,mBAAmB,OAAO,eAC5D;IACA,KAAK,MAAM,QAAQ,OAAO,oBACxB,QAAQ,IAAI,OAAO,MAAM;GAE7B;EACF;CACF,SAAS,OAAO;EACd,QAAQ,MACN,UACA,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CACvD;EACA,QAAQ,KAAK,CAAC;CAChB,UAAU;EACR,MAAM,GAAG,QAAQ;CACnB;AACF","debug_id":"8ee54547-f686-5213-81f6-e06f7bd4b297"}