mirror of
https://github.com/cupcakearmy/firemorph.git
synced 2024-12-30 12:16:26 +00:00
add time
This commit is contained in:
parent
7913a27fc2
commit
b5c3ecb728
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
node_modules
|
||||
dist
|
||||
dist
|
||||
*.log
|
1230
package-lock.json
generated
1230
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -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"
|
||||
}
|
||||
}
|
||||
|
30
src/index.ts
30
src/index.ts
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user