Skip to content

Commit

Permalink
Fix circular imports
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Dec 2, 2024
1 parent 4a1f2b0 commit 5f0cd23
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
12 changes: 5 additions & 7 deletions packages/node-core/src/db/migration-service/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ import {isEqual, uniq} from 'lodash';
import {NodeConfig} from '../../configure/NodeConfig';
import {HistoricalMode, StoreService} from '../../indexer';
import {getLogger} from '../../logger';
import {EnumType, getColumnOption, modelsTypeToModelAttributes} from '../../utils';
import {EnumType, getColumnOption, modelsTypeToModelAttributes, enumNameToHash} from '../../utils';
import {formatAttributes, formatColumnName, modelToTableName} from '../sequelizeUtil';
import * as syncHelper from '../sync-helper';

type RemovedIndexes = Record<string, IndexesOptions[]>;

const logger = getLogger('db-manager');

export class Migration {
Expand Down Expand Up @@ -358,8 +356,8 @@ export class Migration {
// It is difficult for sequelize use replacement, instead we use escape to avoid injection
// UPDATE: this comment got syntax error with cockroach db, disable it for now. Waiting to be fixed.
// See https://github.com/cockroachdb/cockroach/issues/44135
const enumTypeName = syncHelper.enumNameToHash(e.name);
const enumTypeNameDeprecated = `${this.schemaName}_enum_${syncHelper.enumNameToHash(e.name)}`;
const enumTypeName = enumNameToHash(e.name);
const enumTypeNameDeprecated = `${this.schemaName}_enum_${enumNameToHash(e.name)}`;

let type: string | null = null;

Expand Down Expand Up @@ -397,8 +395,8 @@ export class Migration {
}

dropEnum(e: GraphQLEnumsType): void {
const enumTypeName = syncHelper.enumNameToHash(e.name);
const enumTypeNameDeprecated = `${this.schemaName}_enum_${syncHelper.enumNameToHash(e.name)}`;
const enumTypeName = enumNameToHash(e.name);
const enumTypeNameDeprecated = `${this.schemaName}_enum_${enumNameToHash(e.name)}`;

[enumTypeName, enumTypeNameDeprecated].forEach((typeName) => {
if (this.enumTypeMap.has(typeName)) {
Expand Down
6 changes: 3 additions & 3 deletions packages/node-core/src/db/sync-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ export function createSchemaTriggerFunction(schema: string): string {
$$ LANGUAGE plpgsql;`;
}

export function enumNameToHash(enumName: string): string {
return blake2AsHex(enumName).substr(2, 10);
}
// export function enumNameToHash(enumName: string): string {
// return blake2AsHex(enumName).substr(2, 10);
// }

export function getExistedIndexesQuery(schema: string): string {
return `SELECT indexname FROM pg_indexes WHERE schemaname = '${schema}'`;
Expand Down
2 changes: 1 addition & 1 deletion packages/node-core/src/indexer/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {SourceMapConsumer, NullableMappedPosition} from 'source-map';
import {NodeVM, NodeVMOptions, VMError, VMScript} from 'vm2';
import {NodeConfig} from '../configure/NodeConfig';
import {getLogger} from '../logger';
import {timeout} from '../utils';
import {timeout} from '../utils/promise';

export const SANDBOX_DEFAULT_BUILTINS = ['assert', 'buffer', 'crypto', 'util', 'path', 'url', 'stream'];

Expand Down
3 changes: 1 addition & 2 deletions packages/node-core/src/subcommands/forceClean.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import {Inject, Injectable} from '@nestjs/common';
import {getAllEntitiesRelations} from '@subql/utils';
import {QueryTypes, Sequelize} from '@subql/x-sequelize';
import {NodeConfig} from '../configure';
import {enumNameToHash} from '../db';
import {MonitorService} from '../indexer';
import {ISubqueryProject} from '../indexer/types';
import {getLogger} from '../logger';
import {getEnumDeprecated, getExistingProjectSchema} from '../utils';
import {getEnumDeprecated, getExistingProjectSchema, enumNameToHash} from '../utils';

const logger = getLogger('Force-clean');

Expand Down
6 changes: 5 additions & 1 deletion packages/node-core/src/utils/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ import {
isNull,
GraphQLEntityField,
GraphQLJsonFieldType,
blake2AsHex,
} from '@subql/utils';
import {ModelAttributes, ModelAttributeColumnOptions} from '@subql/x-sequelize';
import {isArray, isObject} from 'lodash';
import {enumNameToHash} from '../db';

export function enumNameToHash(enumName: string): string {
return blake2AsHex(enumName).substr(2, 10);
}

export interface EnumType {
enumValues: string[];
Expand Down

0 comments on commit 5f0cd23

Please sign in to comment.