diff --git a/packages/node-core/src/indexer/store.service.ts b/packages/node-core/src/indexer/store.service.ts index f7a4b4898b..11cb8bcf28 100644 --- a/packages/node-core/src/indexer/store.service.ts +++ b/packages/node-core/src/indexer/store.service.ts @@ -54,6 +54,7 @@ import { modelsTypeToModelAttributes, SmartTags, smartTags, + getEnumDeprecated, } from '../utils'; import {Metadata, MetadataFactory, MetadataRepo, PoiFactory, PoiRepo, ProofOfIndex} from './entities'; import {StoreOperations} from './StoreOperations'; @@ -178,17 +179,8 @@ export class StoreService { {replacements: [enumTypeName, schema]} ); - // If enum has created before and not under schema, still following the original logic - // This logic should be deprecated for new project const enumTypeNameDeprecated = `${schema}_enum_${enumNameToHash(e.name)}`; - const [resultsDeprecated] = await this.sequelize.query( - `select e.enumlabel as enum_value - from pg_type t - join pg_enum e on t.oid = e.enumtypid - where t.typname = ? - order by enumsortorder;`, - {replacements: [enumTypeNameDeprecated]} - ); + const resultsDeprecated = await getEnumDeprecated(this.sequelize, enumTypeNameDeprecated); if (resultsDeprecated.length !== 0) { results = resultsDeprecated; type = `"${enumTypeNameDeprecated}"`; diff --git a/packages/node-core/src/utils/project.ts b/packages/node-core/src/utils/project.ts index 14b8fca92f..bd65ed12b5 100644 --- a/packages/node-core/src/utils/project.ts +++ b/packages/node-core/src/utils/project.ts @@ -59,3 +59,15 @@ export function transformBypassBlocks(bypassBlocks: (number | string)[]): number export function cleanedBatchBlocks(bypassBlocks: number[], currentBlockBatch: number[]): number[] { return without(currentBlockBatch, ...transformBypassBlocks(bypassBlocks)); } + +export async function getEnumDeprecated(sequelize: Sequelize, enumTypeNameDeprecated: string): Promise { + const [resultsDeprecated] = await sequelize.query( + `select e.enumlabel as enum_value + from pg_type t + join pg_enum e on t.oid = e.enumtypid + where t.typname = ? + order by enumsortorder;`, + {replacements: [enumTypeNameDeprecated]} + ); + return resultsDeprecated; +} diff --git a/packages/node/src/subcommands/forceClean.service.ts b/packages/node/src/subcommands/forceClean.service.ts index f4d92424b3..f9fdaa19ed 100644 --- a/packages/node/src/subcommands/forceClean.service.ts +++ b/packages/node/src/subcommands/forceClean.service.ts @@ -8,6 +8,7 @@ import { NodeConfig, getExistingProjectSchema, enumNameToHash, + getEnumDeprecated, } from '@subql/node-core'; import { getAllEntitiesRelations } from '@subql/utils'; import { QueryTypes, Sequelize } from 'sequelize'; @@ -45,10 +46,18 @@ export class ForceCleanService { // Deprecate, now enums are moved under schema, drop schema will remove project enums await Promise.all( modelsRelation.enums.map(async (e) => { - const enumTypeName = `${schema}_enum_${enumNameToHash(e.name)}`; - await this.sequelize.query(` - DROP TYPE "${enumTypeName}"; + const enumTypeNameDeprecated = `${schema}_enum_${enumNameToHash( + e.name, + )}`; + const resultsDeprecated = await getEnumDeprecated( + this.sequelize, + enumTypeNameDeprecated, + ); + if (resultsDeprecated.length !== 0) { + await this.sequelize.query(` + DROP TYPE "${enumTypeNameDeprecated}"; `); + } }), );