This commit is contained in:
cupcakearmy 2021-03-21 12:49:46 +01:00
parent 7913a27fc2
commit b5c3ecb728
No known key found for this signature in database
GPG Key ID: 81C683415BBD86B0
5 changed files with 1080 additions and 1240 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
node_modules
dist
dist
*.log

1230
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,7 @@
},
"devDependencies": {
"@types/glob": "^7.1.3",
"@types/ms": "^0.7.31",
"@types/semver": "^7.3.4",
"typescript": "^4"
},
@ -29,6 +30,7 @@
"commander": "^7.1.0",
"firebase-admin": "^9.5.0",
"glob": "^7.1.6",
"ms": "^2.1.3",
"semver": "^7.3.4"
}
}

View File

@ -4,6 +4,7 @@ import admin from 'firebase-admin'
import semver from 'semver'
import glob from 'glob'
import chalk from 'chalk'
import ms from 'ms'
const App = admin.initializeApp()
const DB = admin.firestore()
@ -92,20 +93,31 @@ async function runMigrations(migrations: MigrationFile[], options: Options) {
continue
}
const result: MigrationResult = {
version: migration.version,
executed: Timestamp.now(),
status: MigrationResultStatus.Successful,
}
const start = process.hrtime.bigint()
let error = false
try {
await migration.fn(DB, admin.firestore)
await remoteDoc.ref.set(result)
printMigration(migration, chalk.green(`✅ Success`))
} catch (e) {
await remoteDoc.ref.set({ ...result, status: MigrationResultStatus.Failed })
printMigration(migration, chalk.red(`❌ Error while running.`))
error = true
console.error(e)
break
} finally {
const delta = (process.hrtime.bigint() - start) / BigInt(1000000)
const time = ms(Number(delta))
const message = error ? chalk.red(`❌ Error while running.`) : chalk.green(`✅ Success`)
printMigration(migration, `${message} ${chalk.gray(time)}`)
const result: MigrationResult = {
version: migration.version,
executed: Timestamp.now(),
status: error ? MigrationResultStatus.Failed : MigrationResultStatus.Successful,
}
await remoteDoc.ref.set(result)
if (error) {
console.log('⚠️ Skipping next migrations')
break
}
}
}
}

1055
yarn.lock Normal file

File diff suppressed because it is too large Load Diff