@@ -5,18 +5,45 @@ import {
55} from "../utils/AuthorizationRefactor" ;
66import * as admin from "firebase-admin" ;
77
8- // Firebase Initialization
9- const serviceAccountPath = process . env . FIREBASE_SERVICE_ACCOUNT_PATH ! ;
10- const serviceAccount = require ( serviceAccountPath ) ;
8+ /**
9+ * Initialize Firebase only when this migration's `up` runs.
10+ * TypeORM loads every migration module on `migration:run`; top-level
11+ * `require(FIREBASE_SERVICE_ACCOUNT_PATH)` breaks CI when that env is unset.
12+ */
13+ function ensureFirebaseApp ( ) : void {
14+ if ( admin . apps . length ) return ;
15+
16+ const json = process . env . FIREBASE_SERVICE_ACCOUNT_JSON ?. trim ( ) ;
17+ let serviceAccount : admin . ServiceAccount ;
18+
19+ if ( json ) {
20+ try {
21+ serviceAccount = JSON . parse ( json ) as admin . ServiceAccount ;
22+ } catch {
23+ const decoded = Buffer . from ( json , "base64" ) . toString ( "utf8" ) ;
24+ serviceAccount = JSON . parse ( decoded ) as admin . ServiceAccount ;
25+ }
26+ } else {
27+ const serviceAccountPath = process . env . FIREBASE_SERVICE_ACCOUNT_PATH ;
28+ if ( ! serviceAccountPath ) {
29+ throw new Error (
30+ "AuthorizationRefactor migration requires FIREBASE_SERVICE_ACCOUNT_JSON " +
31+ "or FIREBASE_SERVICE_ACCOUNT_PATH when this migration still needs to run." ,
32+ ) ;
33+ }
34+ // eslint-disable-next-line @typescript-eslint/no-var-requires
35+ serviceAccount = require ( serviceAccountPath ) as admin . ServiceAccount ;
36+ }
1137
12- if ( ! admin . apps . length ) {
1338 admin . initializeApp ( {
1439 credential : admin . credential . cert ( serviceAccount ) ,
1540 } ) ;
1641}
1742
1843export class AuthorizationRefactor1740628691583 implements MigrationInterface {
1944 public async up ( queryRunner : QueryRunner ) : Promise < void > {
45+ ensureFirebaseApp ( ) ;
46+
2047 // Add new column as nullable initially
2148 await queryRunner . query (
2249 `ALTER TABLE "User" ADD COLUMN "firebaseUid" VARCHAR` ,
0 commit comments