-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from fabrix-app/v1.6
[feat] upgrade deps, add validator to schema.
- Loading branch information
Showing
15 changed files
with
2,183 additions
and
1,965 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
lib/api/services/ElasticsearchSchemaMigrationService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { FabrixService as Service } from '@fabrix/fabrix/dist/common' | ||
/** | ||
* @module SchemaMigrationService | ||
* @description Schema Migrations | ||
*/ | ||
export class ElasticsearchSchemaMigrationService extends Service { | ||
|
||
/** | ||
* Drop collection | ||
*/ | ||
async dropIndex(index, connection) { | ||
// const dialect = connection.dialect.connectionManager.dialectName | ||
// return index.sequelize.query(dialect === 'sqlite' ? 'PRAGMA foreign_keys = OFF' : 'SET FOREIGN_KEY_CHECKS = 0') | ||
// .then(() => { | ||
// return index.sync({force: true}) | ||
// }) | ||
// .then(() => { | ||
// return index.sequelize.query(dialect === 'sqlite' ? 'PRAGMA foreign_keys = ON' : 'SET FOREIGN_KEY_CHECKS = 1') | ||
// }) | ||
// .catch(err => { | ||
// return index.sync({force: true}) | ||
// }) | ||
} | ||
|
||
/** | ||
* Alter an existing schema | ||
*/ | ||
async alterIndex(index, connection) { | ||
// const dialect = connection.dialect.connectionManager.dialectName | ||
// return connection.sync(index) | ||
// return index.sync() | ||
} | ||
|
||
migrateIndexs(indexs, connection) { | ||
// let promises = [] | ||
// Object.entries(indexs).forEach(([ _, index ]: [ any, {[key: string]: any}]) => { | ||
// if (index.migrate === 'drop') { | ||
// promises.push(this.dropIndex(index, connection)) | ||
// } | ||
// else if (index.migrate === 'alter') { | ||
// promises.push(this.alterIndex(index, connection)) | ||
// } | ||
// else if (index.migrate === 'none') { | ||
// return | ||
// } | ||
// else { | ||
// return | ||
// } | ||
// }) | ||
// return promises | ||
} | ||
|
||
/** | ||
* Drop collections in current connection | ||
* @param connection connection object | ||
*/ | ||
async dropDB(connection) { | ||
// const dialect = connection.dialect.connectionManager.dialectName | ||
// return connection.query(dialect === 'sqlite' ? 'PRAGMA foreign_keys = OFF' : 'SET FOREIGN_KEY_CHECKS = 0') | ||
// .then(() => { | ||
// return connection.sync({force: true}) | ||
// }) | ||
// .then(() => { | ||
// return connection.query(dialect === 'sqlite' ? 'PRAGMA foreign_keys = ON' : 'SET FOREIGN_KEY_CHECKS = 1') | ||
// }) | ||
// .catch(err => { | ||
// return connection.sync({force: true}) | ||
// }) | ||
} | ||
|
||
/** | ||
* Alter an existing database | ||
*/ | ||
async alterDB(connection) { | ||
// return connection.sync() | ||
} | ||
|
||
/** | ||
* Migrate the DB | ||
* Checks the connection level instances first and the reverts to index level migration strategy | ||
*/ | ||
async migrateDB(connections) { | ||
let promises = [] | ||
|
||
// Object.entries(connections).forEach(([ _, store ]: [ any, {[key: string]: any}]) => { | ||
// if (store.migrate === 'drop') { | ||
// promises.push(this.dropDB(store)) | ||
// } | ||
// else if (store.migrate === 'alter') { | ||
// promises.push(this.alterDB(store)) | ||
// } | ||
// else if (store.migrate === 'none') { | ||
// return | ||
// } | ||
// else { | ||
// promises = [...promises, ...this.migrateIndexs(store.indexs, store)] | ||
// } | ||
// }) | ||
|
||
return Promise.all(promises) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { ElasticsearchService } from './ElasticsearchService' | ||
export { ElasticsearchSchemaMigrationService } from './ElasticsearchSchemaMigrationService' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export { spool } from './spool' | ||
export { elasticsearch } from './elasticsearch' | ||
export { stores } from './stores' | ||
export { models } from './models' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const models = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const stores = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
const joi = require('joi') | ||
|
||
export const Schemas = { | ||
storesConfig: joi.object().keys({ | ||
|
||
}).unknown(), | ||
modelsConfig: joi.object().keys({ | ||
|
||
}).unknown(), | ||
pluginsConfig: joi.object().keys({ | ||
|
||
}).unknown(), | ||
|
||
elasticConfig: joi.object().keys({ | ||
connection: joi.object().keys({ | ||
log: joi.string() | ||
}).unknown(), | ||
validateConnection: joi.boolean() | ||
}).unknown(), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as joi from 'joi' | ||
import { Schemas } from './schemas' | ||
|
||
export const Validator = { | ||
validateStoresConfig (config) { | ||
return new Promise((resolve, reject) => { | ||
joi.validate(config, Schemas.storesConfig, (err, value) => { | ||
if (err) { | ||
return reject(err) | ||
} | ||
return resolve(value) | ||
}) | ||
}) | ||
}, | ||
validateModelsConfig (config) { | ||
return new Promise((resolve, reject) => { | ||
joi.validate(config, Schemas.modelsConfig, (err, value) => { | ||
if (err) { | ||
return reject(err) | ||
} | ||
return resolve(value) | ||
}) | ||
}) | ||
}, | ||
validateElasticConfig (config) { | ||
return new Promise((resolve, reject) => { | ||
joi.validate(config, Schemas.elasticConfig, (err, value) => { | ||
if (err) { | ||
return reject(err) | ||
} | ||
return resolve(value) | ||
}) | ||
}) | ||
} | ||
} |
Oops, something went wrong.