Skip to content

Commit 6eaa418

Browse files
authored
Merge pull request #488 from ZIMkaRU/feature/separate-db-files-for-prod-and-staging
Separate db files for prod and staging
2 parents d7c854b + 40e1299 commit 6eaa418

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

workers/api.framework.report.wrk.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const {
4242
const appDeps = require('./loc.api/di/app.deps')
4343
const TYPES = require('./loc.api/di/types')
4444
const fwDataValidator = require('./loc.api/data-validator')
45+
const { isBfxApiStaging } = require('./loc.api/helpers')
4546

4647
class WrkReportFrameWorkApi extends WrkReportServiceApi {
4748
loadCoreDeps (...args) {
@@ -128,8 +129,12 @@ class WrkReportFrameWorkApi extends WrkReportServiceApi {
128129
syncMode,
129130
dbDriver,
130131
verboseSql,
131-
dbPathAbsolute
132+
dbPathAbsolute,
133+
restUrl
132134
} = this.conf[this.group]
135+
const stagingDbLabel = isBfxApiStaging(restUrl)
136+
? '-staging'
137+
: ''
133138
const facs = []
134139

135140
if (syncMode) {
@@ -147,7 +152,7 @@ class WrkReportFrameWorkApi extends WrkReportServiceApi {
147152
'm0',
148153
'm0',
149154
{
150-
name: 'sync',
155+
name: `sync${stagingDbLabel}`,
151156
dbPathAbsolute,
152157
workerPathAbsolute,
153158
verbose: verboseSql,

workers/loc.api/helpers/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const {
1818
getAuthFromSubAccountAuth,
1919
getSubAccountAuthFromAuth
2020
} = require('./sub-account-auth')
21+
const isBfxApiStaging = require('./is-bfx-api-staging')
2122

2223
module.exports = {
2324
checkParamsAuth,
@@ -33,5 +34,6 @@ module.exports = {
3334
sumAllObjectsNumbers,
3435
pickAllLowerObjectsNumbers,
3536
sumArrayVolumes,
36-
pushLargeArr
37+
pushLargeArr,
38+
isBfxApiStaging
3739
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict'
2+
3+
const pattern = /(staging)|(test)/i
4+
5+
module.exports = (restUrl) => {
6+
return !!(
7+
restUrl &&
8+
typeof restUrl === 'string' &&
9+
pattern.test(restUrl)
10+
)
11+
}

workers/loc.api/sync/dao/db.backup.manager/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const path = require('path')
66
const moment = require('moment')
77
const { orderBy } = require('lodash')
88

9+
const { isBfxApiStaging } = require('../../../helpers')
10+
911
const { decorateInjectable } = require('../../../di/utils')
1012

1113
const depsTypes = (TYPES) => [
@@ -39,7 +41,10 @@ class DBBackupManager {
3941
this.conf.dbPathAbsolute,
4042
'backups'
4143
)
42-
this._dbFileName = 'db-sqlite_sync_m0.db'
44+
const stagingDbLabel = isBfxApiStaging(this.conf.restUrl)
45+
? '-staging'
46+
: ''
47+
this._dbFileName = `db-sqlite_sync${stagingDbLabel}_m0.db`
4348
this._dbDestination = path.join(
4449
this.conf.dbPathAbsolute,
4550
this._dbFileName

0 commit comments

Comments
 (0)