From 43f69db83e72b976dd770c1b28909b540a87a249 Mon Sep 17 00:00:00 2001 From: Kevin Szuchet Date: Tue, 5 Aug 2025 12:40:38 +0300 Subject: [PATCH 1/3] feat: Store AB Version and include it when responding to /entities/active --- package.json | 2 +- src/adapters/db.ts | 44 ++++++++++--------- src/logic/handlers/status-handler.ts | 8 ++-- src/logic/handlers/textures-handler.ts | 3 +- .../1754383462330_add-version-column.ts | 22 ++++++++++ src/types/types.ts | 1 + .../logic/handlers/status-handler.spec.ts | 3 +- .../logic/handlers/textures-handler.spec.ts | 25 +++++++---- .../unit/logic/registry-orchestrators.spec.ts | 1 + test/utils.ts | 1 + yarn.lock | 9 ++++ 11 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 src/migrations/1754383462330_add-version-column.ts diff --git a/package.json b/package.json index 2ee74da8..1a2daac8 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@dcl/crypto": "^3.4.5", "@dcl/platform-crypto-middleware": "^1.1.0", "@dcl/platform-server-commons": "^0.0.4", - "@dcl/schemas": "^15.7.0", + "@dcl/schemas": "https://sdk-team-cdn.decentraland.org/@dcl/schemas/branch/feat/add-version-to-ab-events/dcl-schemas-17.2.1-16744594799.commit-8a01e1d.tgz", "@well-known-components/env-config-provider": "^1.2.0", "@well-known-components/fetch-component": "^3.0.0", "@well-known-components/http-server": "^2.1.0", diff --git a/src/adapters/db.ts b/src/adapters/db.ts index ebe8338f..05ca2880 100644 --- a/src/adapters/db.ts +++ b/src/adapters/db.ts @@ -7,7 +7,7 @@ export function createDbAdapter({ pg }: Pick): DbComponent async function getSortedRegistriesByOwner(owner: EthAddress): Promise { const query: SQLStatement = SQL` SELECT - id, type, timestamp, deployer, pointers, content, metadata, status, bundles + id, type, timestamp, deployer, pointers, content, metadata, status, bundles, version FROM registries WHERE @@ -26,7 +26,7 @@ export function createDbAdapter({ pg }: Pick): DbComponent ): Promise { const query = SQL` SELECT - id, type, timestamp, deployer, pointers, content, metadata, status, bundles + id, type, timestamp, deployer, pointers, content, metadata, status, bundles, version FROM registries WHERE @@ -52,7 +52,7 @@ export function createDbAdapter({ pg }: Pick): DbComponent async function getRegistryById(id: string): Promise { const query: SQLStatement = SQL` SELECT - id, type, timestamp, deployer, pointers, content, metadata, status, bundles + id, type, timestamp, deployer, pointers, content, metadata, status, bundles, version FROM registries WHERE @@ -66,7 +66,7 @@ export function createDbAdapter({ pg }: Pick): DbComponent async function insertRegistry(registry: Registry.DbEntity): Promise { const query: SQLStatement = SQL` INSERT INTO registries ( - id, type, timestamp, deployer, pointers, content, metadata, status, bundles + id, type, timestamp, deployer, pointers, content, metadata, status, bundles, version ) VALUES ( ${registry.id}, @@ -77,7 +77,8 @@ export function createDbAdapter({ pg }: Pick): DbComponent ${JSON.stringify(registry.content)}::jsonb, ${JSON.stringify(registry.metadata)}::jsonb, ${registry.status}, - ${JSON.stringify(registry.bundles)}::jsonb + ${JSON.stringify(registry.bundles)}::jsonb, + ${registry.version} ) ON CONFLICT (id) DO UPDATE SET @@ -91,7 +92,8 @@ export function createDbAdapter({ pg }: Pick): DbComponent deployer = CASE WHEN EXCLUDED.deployer != '' THEN EXCLUDED.deployer ELSE registries.deployer - END + END, + version = EXCLUDED.version RETURNING id, type, @@ -101,7 +103,8 @@ export function createDbAdapter({ pg }: Pick): DbComponent content, metadata, status, - bundles + bundles, + version ` const result = await pg.query(query) @@ -124,19 +127,15 @@ export function createDbAdapter({ pg }: Pick): DbComponent content, metadata, status, - bundles + bundles, + version ` const result = await pg.query(query) return result.rows || null } - async function upsertRegistryBundle( - id: string, - platform: string, - lods: boolean, - status: string - ): Promise { + async function upsertRegistryBundle(id: string, platform: string, lods: boolean): Promise { const bundleType = lods ? 'lods' : 'assets' const query: SQLStatement = SQL` UPDATE registries @@ -159,7 +158,7 @@ export function createDbAdapter({ pg }: Pick): DbComponent ): Promise { const query: SQLStatement = SQL` SELECT - id, pointers, timestamp, status, bundles + id, pointers, timestamp, status, bundles, version FROM registries WHERE @@ -196,7 +195,7 @@ export function createDbAdapter({ pg }: Pick): DbComponent const baseQuery = SQL` SELECT - id, type, timestamp, deployer, pointers, content, metadata, status, bundles + id, type, timestamp, deployer, pointers, content, metadata, status, bundles, version FROM registries WHERE @@ -218,7 +217,7 @@ export function createDbAdapter({ pg }: Pick): DbComponent async function insertHistoricalRegistry(registry: Registry.DbEntity): Promise { const query: SQLStatement = SQL` INSERT INTO historical_registries ( - id, type, timestamp, deployer, pointers, content, metadata, status, bundles, migrated_at + id, type, timestamp, deployer, pointers, content, metadata, status, bundles, version, migrated_at ) VALUES ( ${registry.id}, @@ -230,6 +229,7 @@ export function createDbAdapter({ pg }: Pick): DbComponent ${JSON.stringify(registry.metadata)}::jsonb, ${registry.status}, ${JSON.stringify(registry.bundles)}::jsonb, + ${registry.version}, ${Date.now()} ) ON CONFLICT (id) DO UPDATE @@ -240,7 +240,8 @@ export function createDbAdapter({ pg }: Pick): DbComponent content = EXCLUDED.content, metadata = EXCLUDED.metadata, status = EXCLUDED.status, - bundles = EXCLUDED.bundles + bundles = EXCLUDED.bundles, + version = EXCLUDED.version RETURNING id, type, @@ -250,7 +251,8 @@ export function createDbAdapter({ pg }: Pick): DbComponent content, metadata, status, - bundles + bundles, + version ` const result = await pg.query(query) @@ -260,7 +262,7 @@ export function createDbAdapter({ pg }: Pick): DbComponent async function getSortedHistoricalRegistriesByOwner(owner: EthAddress): Promise { const query: SQLStatement = SQL` SELECT - id, type, timestamp, deployer, pointers, content, metadata, status, bundles + id, type, timestamp, deployer, pointers, content, metadata, status, bundles, version FROM historical_registries WHERE @@ -274,7 +276,7 @@ export function createDbAdapter({ pg }: Pick): DbComponent async function getHistoricalRegistryById(id: string): Promise { const query: SQLStatement = SQL` SELECT - id, type, timestamp, deployer, pointers, content, metadata, status, bundles + id, type, timestamp, deployer, pointers, content, metadata, status, bundles, version FROM historical_registries WHERE diff --git a/src/logic/handlers/status-handler.ts b/src/logic/handlers/status-handler.ts index a59d1538..f3e933ba 100644 --- a/src/logic/handlers/status-handler.ts +++ b/src/logic/handlers/status-handler.ts @@ -17,11 +17,11 @@ export const createStatusEventHandler = ({ const platforms: ('webgl' | 'windows' | 'mac')[] = [] if (event.type === Events.Type.ASSET_BUNDLE && event.subType === Events.SubType.AssetBundle.MANUALLY_QUEUED) { - const manuallyQueuedEvent = event as AssetBundleConversionManuallyQueuedEvent + const { metadata } = event as AssetBundleConversionManuallyQueuedEvent - entityId = manuallyQueuedEvent.metadata.entityId - platforms.push(manuallyQueuedEvent.metadata.platform) - isLods = manuallyQueuedEvent.metadata.isLods + entityId = metadata.entityId + platforms.push(metadata.platform) + isLods = metadata.isLods } else { const deploymentEvent = event as DeploymentToSqs diff --git a/src/logic/handlers/textures-handler.ts b/src/logic/handlers/textures-handler.ts index d6e6e6e7..784dbbcb 100644 --- a/src/logic/handlers/textures-handler.ts +++ b/src/logic/handlers/textures-handler.ts @@ -56,7 +56,8 @@ export const createTexturesEventHandler = ({ entity = await registryOrchestrator.persistAndRotateStates({ ...fetchedEntity, deployer: '', // cannot infer from textures event - bundles: defaultBundles + bundles: defaultBundles, + version: event.metadata.version }) } diff --git a/src/migrations/1754383462330_add-version-column.ts b/src/migrations/1754383462330_add-version-column.ts new file mode 100644 index 00000000..fd7b3e85 --- /dev/null +++ b/src/migrations/1754383462330_add-version-column.ts @@ -0,0 +1,22 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate' + +export const shorthands: ColumnDefinitions | undefined = undefined + +const REGISTRIES_TABLE = 'registries' +const HISTORICAL_REGISTRIES_TABLE = 'historical_registries' +const VERSION_COLUMN = 'version' + +export async function up(pgm: MigrationBuilder): Promise { + pgm.addColumn(REGISTRIES_TABLE, { + [VERSION_COLUMN]: { type: 'varchar(255)', notNull: false } + }) + pgm.addColumn(HISTORICAL_REGISTRIES_TABLE, { + [VERSION_COLUMN]: { type: 'varchar(255)', notNull: false } + }) +} + +export async function down(pgm: MigrationBuilder): Promise { + pgm.dropColumn(REGISTRIES_TABLE, VERSION_COLUMN) + pgm.dropColumn(HISTORICAL_REGISTRIES_TABLE, VERSION_COLUMN) +} diff --git a/src/types/types.ts b/src/types/types.ts index 442cc771..22adb369 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -23,6 +23,7 @@ export namespace Registry { export type DbEntity = Omit & { deployer: string; bundles: Bundles } & { status: Status type: EntityType | 'world' + version: string | null } export type PartialDbEntity = Pick diff --git a/test/unit/logic/handlers/status-handler.spec.ts b/test/unit/logic/handlers/status-handler.spec.ts index 4ee5cb12..fa952e52 100644 --- a/test/unit/logic/handlers/status-handler.spec.ts +++ b/test/unit/logic/handlers/status-handler.spec.ts @@ -74,7 +74,8 @@ function createAssetBundleConversionManuallyQueuedEvent( entityId, platform, isLods: false, - isPriority: false + isPriority: false, + version: 'v1' } } } diff --git a/test/unit/logic/handlers/textures-handler.spec.ts b/test/unit/logic/handlers/textures-handler.spec.ts index 7192c9c7..7560db47 100644 --- a/test/unit/logic/handlers/textures-handler.spec.ts +++ b/test/unit/logic/handlers/textures-handler.spec.ts @@ -30,6 +30,7 @@ describe('textures-handler', () => { statusCode: ManifestStatusCode.SUCCESS, isLods: false, isWorld: false, + version: 'v1', ...overrides.metadata }, type: Events.Type.ASSET_BUNDLE, @@ -142,7 +143,8 @@ describe('textures-handler', () => { platform: 'windows', statusCode: ManifestStatusCode.SUCCESS, isLods: false, - isWorld: true + isWorld: true, + version: 'v1' } }) const entity = createEntity() @@ -191,7 +193,8 @@ describe('textures-handler', () => { platform: 'windows', statusCode: ManifestStatusCode.SUCCESS, isLods: false, - isWorld: false + isWorld: false, + version: 'v1' } }) const entity = createEntity() @@ -225,7 +228,8 @@ describe('textures-handler', () => { platform: 'mac', statusCode: ManifestStatusCode.CONVERSION_ERRORS_TOLERATED, isLods: false, - isWorld: false + isWorld: false, + version: 'v1' } }) const entity = createEntity() @@ -259,7 +263,8 @@ describe('textures-handler', () => { platform: 'webgl', statusCode: ManifestStatusCode.ALREADY_CONVERTED, isLods: false, - isWorld: false + isWorld: false, + version: 'v1' } }) const entity = createEntity() @@ -293,7 +298,8 @@ describe('textures-handler', () => { platform: 'windows', statusCode: ManifestStatusCode.ASSET_BUNDLE_BUILD_FAIL, isLods: false, - isWorld: false + isWorld: false, + version: 'v1' } }) const entity = createEntity() @@ -327,7 +333,8 @@ describe('textures-handler', () => { platform: 'windows', statusCode: ManifestStatusCode.SUCCESS, isLods: true, - isWorld: false + isWorld: false, + version: 'v1' } }) const entity = createEntity() @@ -374,7 +381,8 @@ describe('textures-handler', () => { platform: 'windows', statusCode: ManifestStatusCode.SUCCESS, isLods: false, - isWorld: false + isWorld: false, + version: 'v1' } }) const entity = createEntity() @@ -408,7 +416,8 @@ describe('textures-handler', () => { platform: 'windows', statusCode: ManifestStatusCode.SUCCESS, isLods: true, - isWorld: false + isWorld: false, + version: 'v1' } }) const entity = createEntity() diff --git a/test/unit/logic/registry-orchestrators.spec.ts b/test/unit/logic/registry-orchestrators.spec.ts index 0ca8ef6a..2b60c242 100644 --- a/test/unit/logic/registry-orchestrators.spec.ts +++ b/test/unit/logic/registry-orchestrators.spec.ts @@ -32,6 +32,7 @@ describe('registry orchestrator should', () => { webgl: Registry.SimplifiedStatus.PENDING } }, + version: null, ...partial }) diff --git a/test/utils.ts b/test/utils.ts index a9ed655d..bafb40ba 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -114,6 +114,7 @@ export function createRegistryEntity( timestamp: 0, content: [], type: EntityType.SCENE, + version: null, ...overrideProperties } } diff --git a/yarn.lock b/yarn.lock index c97924b0..1b11ff36 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1228,6 +1228,15 @@ ajv-errors "^3.0.0" ajv-keywords "^5.1.0" +"@dcl/schemas@https://sdk-team-cdn.decentraland.org/@dcl/schemas/branch/feat/add-version-to-ab-events/dcl-schemas-17.2.1-16744594799.commit-8a01e1d.tgz": + version "17.2.1-16744594799.commit-8a01e1d" + resolved "https://sdk-team-cdn.decentraland.org/@dcl/schemas/branch/feat/add-version-to-ab-events/dcl-schemas-17.2.1-16744594799.commit-8a01e1d.tgz#d3061a51f407500c7fa8618b15fdd55ef348e740" + dependencies: + ajv "^8.11.0" + ajv-errors "^3.0.0" + ajv-keywords "^5.1.0" + mitt "^3.0.1" + "@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": version "4.4.1" resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.1.tgz#d1145bf2c20132d6400495d6df4bf59362fd9d56" From ee213704263c13c1a61ba4227952593ef0943f9b Mon Sep 17 00:00:00 2001 From: Kevin Szuchet Date: Wed, 6 Aug 2025 09:56:27 +0300 Subject: [PATCH 2/3] chore: Bump schemas --- package.json | 2 +- yarn.lock | 17 ++++------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 1a2daac8..5c1ad80c 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@dcl/crypto": "^3.4.5", "@dcl/platform-crypto-middleware": "^1.1.0", "@dcl/platform-server-commons": "^0.0.4", - "@dcl/schemas": "https://sdk-team-cdn.decentraland.org/@dcl/schemas/branch/feat/add-version-to-ab-events/dcl-schemas-17.2.1-16744594799.commit-8a01e1d.tgz", + "@dcl/schemas": "^18.0.0", "@well-known-components/env-config-provider": "^1.2.0", "@well-known-components/fetch-component": "^3.0.0", "@well-known-components/http-server": "^2.1.0", diff --git a/yarn.lock b/yarn.lock index 1b11ff36..4bd8818f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1209,10 +1209,10 @@ ajv-keywords "^5.1.0" mitt "^3.0.1" -"@dcl/schemas@^15.7.0": - version "15.7.0" - resolved "https://registry.yarnpkg.com/@dcl/schemas/-/schemas-15.7.0.tgz#865fdf51ace0c1741fe326b74efac454c03f09bd" - integrity sha512-TOlLPFh56JrmyRmRHnMSbMnQpHqXWZ/LRiM8y5lw+gRPMPJvEXL8C0lKbH1Seqsz9Q5K8hF0FTqoTMKBtRiKKg== +"@dcl/schemas@^18.0.0": + version "18.0.0" + resolved "https://registry.yarnpkg.com/@dcl/schemas/-/schemas-18.0.0.tgz#f4df29b31e998e4c8e51dfb2ec106b7b1e4a6581" + integrity sha512-RGG7TUjLslzpsej177CK79WlPKfaAH0SXtW3fYV2btNs93mB6ppGLAh8fx6GBy7kErVBflFRenQFWLJ1gsrNrQ== dependencies: ajv "^8.11.0" ajv-errors "^3.0.0" @@ -1228,15 +1228,6 @@ ajv-errors "^3.0.0" ajv-keywords "^5.1.0" -"@dcl/schemas@https://sdk-team-cdn.decentraland.org/@dcl/schemas/branch/feat/add-version-to-ab-events/dcl-schemas-17.2.1-16744594799.commit-8a01e1d.tgz": - version "17.2.1-16744594799.commit-8a01e1d" - resolved "https://sdk-team-cdn.decentraland.org/@dcl/schemas/branch/feat/add-version-to-ab-events/dcl-schemas-17.2.1-16744594799.commit-8a01e1d.tgz#d3061a51f407500c7fa8618b15fdd55ef348e740" - dependencies: - ajv "^8.11.0" - ajv-errors "^3.0.0" - ajv-keywords "^5.1.0" - mitt "^3.0.1" - "@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": version "4.4.1" resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.1.tgz#d1145bf2c20132d6400495d6df4bf59362fd9d56" From 70906638b76dd12fe067e46fcfb69217ee2adcbc Mon Sep 17 00:00:00 2001 From: Kevin Szuchet Date: Wed, 6 Aug 2025 09:59:32 +0300 Subject: [PATCH 3/3] refactor: Use varchar 10 for the new column --- src/migrations/1754383462330_add-version-column.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/migrations/1754383462330_add-version-column.ts b/src/migrations/1754383462330_add-version-column.ts index fd7b3e85..f6916885 100644 --- a/src/migrations/1754383462330_add-version-column.ts +++ b/src/migrations/1754383462330_add-version-column.ts @@ -9,10 +9,10 @@ const VERSION_COLUMN = 'version' export async function up(pgm: MigrationBuilder): Promise { pgm.addColumn(REGISTRIES_TABLE, { - [VERSION_COLUMN]: { type: 'varchar(255)', notNull: false } + [VERSION_COLUMN]: { type: 'varchar(10)', notNull: false } }) pgm.addColumn(HISTORICAL_REGISTRIES_TABLE, { - [VERSION_COLUMN]: { type: 'varchar(255)', notNull: false } + [VERSION_COLUMN]: { type: 'varchar(10)', notNull: false } }) }