(
model: GraphQLModelsType,
attributes: ModelAttributes<any>,
indexes: IndexesOptions[],
schema: string
)
| 248 | } |
| 249 | |
| 250 | defineModel( |
| 251 | model: GraphQLModelsType, |
| 252 | attributes: ModelAttributes<any>, |
| 253 | indexes: IndexesOptions[], |
| 254 | schema: string |
| 255 | ): ModelStatic<any> { |
| 256 | const sequelizeModel = this.sequelize.define(model.name, attributes, { |
| 257 | underscored: true, |
| 258 | comment: model.description, |
| 259 | freezeTableName: false, |
| 260 | timestamps: false, |
| 261 | schema, |
| 262 | indexes, |
| 263 | }); |
| 264 | |
| 265 | if (this.historical) { |
| 266 | // WARNING these hooks depend on `this.blockHeight` which is a changing value. DO NOT move this into a function outside of this class |
| 267 | sequelizeModel.addScope('defaultScope', { |
| 268 | attributes: { |
| 269 | exclude: ['__id', '__block_range'], |
| 270 | }, |
| 271 | }); |
| 272 | |
| 273 | sequelizeModel.addHook('beforeFind', (options) => { |
| 274 | (options.where as any).__block_range = { |
| 275 | [Op.contains]: this.getHistoricalUnit(), |
| 276 | }; |
| 277 | }); |
| 278 | sequelizeModel.addHook('beforeValidate', (attributes, options) => { |
| 279 | attributes.__block_range = [this.getHistoricalUnit(), null]; |
| 280 | }); |
| 281 | |
| 282 | if (!this.config.enableCache) { |
| 283 | sequelizeModel.addHook('beforeBulkCreate', (instances, options) => { |
| 284 | instances.forEach((item) => { |
| 285 | item.__block_range = [this.getHistoricalUnit(), null]; |
| 286 | }); |
| 287 | }); |
| 288 | } |
| 289 | // TODO, remove id and block_range constraint, check id manually |
| 290 | // see https://github.com/subquery/subql/issues/1542 |
| 291 | } |
| 292 | |
| 293 | return sequelizeModel; |
| 294 | } |
| 295 | |
| 296 | private async useDeprecatePoi(schema: string): Promise<boolean> { |
| 297 | const sql = `SELECT * FROM information_schema.columns WHERE table_schema = ? AND table_name = '_poi' AND column_name = 'projectId'`; |
no test coverage detected