Skip to content

Commit

Permalink
Remove Subqueries table (#1340)
Browse files Browse the repository at this point in the history
* Remove Subqueries table

* Fix NOT_SUPPORT function in project

* Remove tests relating to old subqueries table
  • Loading branch information
stwiname authored Oct 10, 2022
1 parent 3ff3ebd commit 52a4c21
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 320 deletions.
7 changes: 3 additions & 4 deletions packages/node-core/src/db/db.module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {INestApplication} from '@nestjs/common';
import {Test} from '@nestjs/testing';
import {Sequelize} from 'sequelize';
import {NodeConfig} from '../configure/NodeConfig';
import {SubqueryRepo} from '../entities';
import {DbModule} from './db.module';

const nodeConfig = new NodeConfig({subquery: 'packages/node-core/test/v1.0.0', subqueryName: 'test'});
Expand All @@ -30,12 +29,12 @@ describe('DbModule', () => {

it('can load subquery model', async () => {
const module = await Test.createTestingModule({
imports: [DbModule.forRootWithConfig(nodeConfig), DbModule.forFeature(['Subquery'])],
imports: [DbModule.forRootWithConfig(nodeConfig)],
}).compile();

app = module.createNestApplication();
await app.init();
const subqueryRepo: SubqueryRepo = app.get('Subquery');
await expect(subqueryRepo.describe()).resolves.toBeTruthy();
// const subqueryRepo: SubqueryRepo = app.get('Subquery');
// await expect(subqueryRepo.describe()).resolves.toBeTruthy();
}, 30000);
});
4 changes: 0 additions & 4 deletions packages/node-core/src/db/db.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import {DynamicModule, Global} from '@nestjs/common';
import {Sequelize, Options as SequelizeOption} from 'sequelize';
import {NodeConfig} from '../configure/NodeConfig';
import * as entities from '../entities';
import {getLogger} from '../logger';
import {delay} from '../utils/promise';

Expand Down Expand Up @@ -44,9 +43,6 @@ const sequelizeFactory = (option: SequelizeOption, migrate: boolean) => async ()
const sequelize = new Sequelize(option);
const numRetries = 5;
await establishConnection(sequelize, numRetries);
for (const factoryFn of Object.keys(entities).filter((k) => /Factory$/.exec(k))) {
entities[factoryFn as keyof typeof entities](sequelize);
}
await sequelize.sync({alter: migrate});
return sequelize;
};
Expand Down
73 changes: 0 additions & 73 deletions packages/node-core/src/entities/Subquery.entity.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/node-core/src/entities/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/node-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export * from './logger';
export * from './profiler';
export * from './events';
export * from './configure';
export * from './entities';
export * from './db';
export * from './meta';
export * from './utils';
Expand Down
20 changes: 5 additions & 15 deletions packages/node-core/src/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,30 @@

import {QueryTypes, Sequelize} from 'sequelize';
import {NodeConfig} from '../configure/NodeConfig';
import {SubqueryRepo} from '../entities/Subquery.entity';
import {MetadataRepo} from '../indexer/entities/Metadata.entity';
import {getLogger} from '../logger';

const logger = getLogger('Project-Utils');

export async function getExistingProjectSchema(
nodeConfig: NodeConfig,
sequelize: Sequelize,
subqueryRepo: SubqueryRepo
): Promise<string> {
sequelize: Sequelize
): Promise<string | undefined> {
const DEFAULT_DB_SCHEMA = 'public';
let schema = nodeConfig.localMode ? DEFAULT_DB_SCHEMA : nodeConfig.dbSchema;
const schema = nodeConfig.localMode ? DEFAULT_DB_SCHEMA : nodeConfig.dbSchema;

let schemas: string[];
try {
const result = await sequelize.query(`SELECT schema_name FROM information_schema.schemata`, {
type: QueryTypes.SELECT,
});
schemas = result.map((x: any) => x.schema_name) as [string];
schemas = result.map((x: any) => x.schema_name);
} catch (err) {
logger.error(`Unable to fetch all schemas: ${err}`);
process.exit(1);
}
if (!schemas.includes(schema)) {
// fallback to subqueries table
const subqueryModel = await subqueryRepo.findOne({
where: {name: nodeConfig.subqueryName},
});
if (subqueryModel) {
schema = subqueryModel.dbSchema;
} else {
schema = undefined;
}
return undefined;
}
return schema;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/configure/SubqueryProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type SubqlProjectDsTemplate = Omit<SubqlProjectDs, 'startBlock'> & {
name: string;
};

const NOT_SUPPORT = (name: string) => () => {
const NOT_SUPPORT = (name: string) => {
throw new Error(`Manifest specVersion ${name}() is not supported`);
};

Expand Down
1 change: 0 additions & 1 deletion packages/node/src/indexer/fetch.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from './worker/block-dispatcher.service';

@Module({
imports: [DbModule.forFeature(['Subquery'])],
providers: [
StoreService,
ApiService,
Expand Down
4 changes: 0 additions & 4 deletions packages/node/src/indexer/indexer.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
StoreService,
PoiService,
MmrService,
SubqueryFactory,
NodeConfig,
} from '@subql/node-core';
import { GraphQLSchema } from 'graphql';
Expand Down Expand Up @@ -136,7 +135,6 @@ function createIndexerManager(

const poiService = new PoiService(nodeConfig, sequilize);
const storeService = new StoreService(sequilize, nodeConfig);
const subqueryRepo = SubqueryFactory(sequilize);
const mmrService = new MmrService(nodeConfig, sequilize);
const sandboxService = new SandboxService(
apiService,
Expand All @@ -154,7 +152,6 @@ function createIndexerManager(
storeService,
nodeConfig,
dynamicDsService,
subqueryRepo,
eventEmitter,
);

Expand All @@ -168,7 +165,6 @@ function createIndexerManager(
sandboxService,
dsProcessorService,
dynamicDsService,
subqueryRepo,
projectService,
);
}
Expand Down
4 changes: 1 addition & 3 deletions packages/node/src/indexer/indexer.manager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020-2022 OnFinality Limited authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { Inject, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { ApiPromise } from '@polkadot/api';
import { RuntimeVersion } from '@polkadot/types/interfaces';
import { hexToU8a, u8aEq } from '@polkadot/util';
Expand All @@ -21,7 +21,6 @@ import {
PoiBlock,
StoreService,
PoiService,
SubqueryRepo,
NodeConfig,
getLogger,
profiler,
Expand Down Expand Up @@ -65,7 +64,6 @@ export class IndexerManager {
private sandboxService: SandboxService,
private dsProcessorService: DsProcessorService,
private dynamicDsService: DynamicDsService,
@Inject('Subquery') protected subqueryRepo: SubqueryRepo,
private projectService: ProjectService,
) {
logger.info('indexer manager start');
Expand Down
1 change: 0 additions & 1 deletion packages/node/src/indexer/indexer.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { SandboxService } from './sandbox.service';
import { WorkerService } from './worker/worker.service';

@Module({
imports: [DbModule.forFeature(['Subquery'])],
providers: [
IndexerManager,
StoreService,
Expand Down
Loading

0 comments on commit 52a4c21

Please sign in to comment.