Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "^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",
Expand Down
44 changes: 23 additions & 21 deletions src/adapters/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
async function getSortedRegistriesByOwner(owner: EthAddress): Promise<Registry.DbEntity[]> {
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
Expand All @@ -26,7 +26,7 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
): Promise<Registry.DbEntity[]> {
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
Expand All @@ -52,7 +52,7 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
async function getRegistryById(id: string): Promise<Registry.DbEntity | null> {
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
Expand All @@ -66,7 +66,7 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
async function insertRegistry(registry: Registry.DbEntity): Promise<Registry.DbEntity> {
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},
Expand All @@ -77,7 +77,8 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): 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
Expand All @@ -91,7 +92,8 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
deployer = CASE
WHEN EXCLUDED.deployer != '' THEN EXCLUDED.deployer
ELSE registries.deployer
END
END,
version = EXCLUDED.version
RETURNING
id,
type,
Expand All @@ -101,7 +103,8 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
content,
metadata,
status,
bundles
bundles,
version
`

const result = await pg.query<Registry.DbEntity>(query)
Expand All @@ -124,19 +127,15 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
content,
metadata,
status,
bundles
bundles,
version
`

const result = await pg.query<Registry.DbEntity>(query)
return result.rows || null
}

async function upsertRegistryBundle(
id: string,
platform: string,
lods: boolean,
status: string
): Promise<Registry.DbEntity | null> {
async function upsertRegistryBundle(id: string, platform: string, lods: boolean): Promise<Registry.DbEntity | null> {
const bundleType = lods ? 'lods' : 'assets'
const query: SQLStatement = SQL`
UPDATE registries
Expand All @@ -159,7 +158,7 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
): Promise<Registry.PartialDbEntity[]> {
const query: SQLStatement = SQL`
SELECT
id, pointers, timestamp, status, bundles
id, pointers, timestamp, status, bundles, version
FROM
registries
WHERE
Expand Down Expand Up @@ -196,7 +195,7 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): 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
Expand All @@ -218,7 +217,7 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
async function insertHistoricalRegistry(registry: Registry.DbEntity): Promise<Registry.DbEntity> {
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},
Expand All @@ -230,6 +229,7 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
${JSON.stringify(registry.metadata)}::jsonb,
${registry.status},
${JSON.stringify(registry.bundles)}::jsonb,
${registry.version},
${Date.now()}
)
ON CONFLICT (id) DO UPDATE
Expand All @@ -240,7 +240,8 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
content = EXCLUDED.content,
metadata = EXCLUDED.metadata,
status = EXCLUDED.status,
bundles = EXCLUDED.bundles
bundles = EXCLUDED.bundles,
version = EXCLUDED.version
RETURNING
id,
type,
Expand All @@ -250,7 +251,8 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
content,
metadata,
status,
bundles
bundles,
version
`

const result = await pg.query<Registry.DbEntity>(query)
Expand All @@ -260,7 +262,7 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
async function getSortedHistoricalRegistriesByOwner(owner: EthAddress): Promise<Registry.DbEntity[]> {
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
Expand All @@ -274,7 +276,7 @@ export function createDbAdapter({ pg }: Pick<AppComponents, 'pg'>): DbComponent
async function getHistoricalRegistryById(id: string): Promise<Registry.DbEntity | null> {
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
Expand Down
8 changes: 4 additions & 4 deletions src/logic/handlers/status-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/logic/handlers/textures-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

Expand Down
22 changes: 22 additions & 0 deletions src/migrations/1754383462330_add-version-column.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
pgm.addColumn(REGISTRIES_TABLE, {
[VERSION_COLUMN]: { type: 'varchar(10)', notNull: false }
})
pgm.addColumn(HISTORICAL_REGISTRIES_TABLE, {
[VERSION_COLUMN]: { type: 'varchar(10)', notNull: false }
})
}

export async function down(pgm: MigrationBuilder): Promise<void> {
pgm.dropColumn(REGISTRIES_TABLE, VERSION_COLUMN)
pgm.dropColumn(HISTORICAL_REGISTRIES_TABLE, VERSION_COLUMN)
}
1 change: 1 addition & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export namespace Registry {
export type DbEntity = Omit<Entity, 'version' | 'type'> & { deployer: string; bundles: Bundles } & {
status: Status
type: EntityType | 'world'
version: string | null
}

export type PartialDbEntity = Pick<DbEntity, 'id' | 'pointers' | 'timestamp' | 'status' | 'bundles'>
Expand Down
3 changes: 2 additions & 1 deletion test/unit/logic/handlers/status-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ function createAssetBundleConversionManuallyQueuedEvent(
entityId,
platform,
isLods: false,
isPriority: false
isPriority: false,
version: 'v1'
}
}
}
25 changes: 17 additions & 8 deletions test/unit/logic/handlers/textures-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('textures-handler', () => {
statusCode: ManifestStatusCode.SUCCESS,
isLods: false,
isWorld: false,
version: 'v1',
...overrides.metadata
},
type: Events.Type.ASSET_BUNDLE,
Expand Down Expand Up @@ -142,7 +143,8 @@ describe('textures-handler', () => {
platform: 'windows',
statusCode: ManifestStatusCode.SUCCESS,
isLods: false,
isWorld: true
isWorld: true,
version: 'v1'
}
})
const entity = createEntity()
Expand Down Expand Up @@ -191,7 +193,8 @@ describe('textures-handler', () => {
platform: 'windows',
statusCode: ManifestStatusCode.SUCCESS,
isLods: false,
isWorld: false
isWorld: false,
version: 'v1'
}
})
const entity = createEntity()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -259,7 +263,8 @@ describe('textures-handler', () => {
platform: 'webgl',
statusCode: ManifestStatusCode.ALREADY_CONVERTED,
isLods: false,
isWorld: false
isWorld: false,
version: 'v1'
}
})
const entity = createEntity()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -327,7 +333,8 @@ describe('textures-handler', () => {
platform: 'windows',
statusCode: ManifestStatusCode.SUCCESS,
isLods: true,
isWorld: false
isWorld: false,
version: 'v1'
}
})
const entity = createEntity()
Expand Down Expand Up @@ -374,7 +381,8 @@ describe('textures-handler', () => {
platform: 'windows',
statusCode: ManifestStatusCode.SUCCESS,
isLods: false,
isWorld: false
isWorld: false,
version: 'v1'
}
})
const entity = createEntity()
Expand Down Expand Up @@ -408,7 +416,8 @@ describe('textures-handler', () => {
platform: 'windows',
statusCode: ManifestStatusCode.SUCCESS,
isLods: true,
isWorld: false
isWorld: false,
version: 'v1'
}
})
const entity = createEntity()
Expand Down
1 change: 1 addition & 0 deletions test/unit/logic/registry-orchestrators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('registry orchestrator should', () => {
webgl: Registry.SimplifiedStatus.PENDING
}
},
version: null,
...partial
})

Expand Down
1 change: 1 addition & 0 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export function createRegistryEntity(
timestamp: 0,
content: [],
type: EntityType.SCENE,
version: null,
...overrideProperties
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading