Skip to content

Commit

Permalink
Merge branch 'master' into fix/assets-discovery-worker-reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
b1ff authored Aug 15, 2024
2 parents 0ce6cfb + 4d8a34a commit 984516f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions registry/server/db/versioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ export interface VersionedKnex<TRecord extends {} = any, TResult = any> extends

function selectVersionedRows(knex: VersionedKnex) {
return function (table: string, key: string, entityType: EntityTypes, columns: ColumnDescriptor[]) {
const versionIdQuery = knex
.table(Tables.Versioning)
.max('id')
.as('versionId')
.where('entity_id', knex.raw(`cast(${table}.${key} as char(255))`))
.andWhere('entity_type', entityType);
return knex.select.call(knex, columns.concat([versionIdQuery]));
return knex
.leftJoin(
knex
.select('entity_id')
.from(Tables.Versioning)
.max('id', { as: 'versionId' })
.where({ entity_type: entityType })
.groupBy('entity_id')
.as('v'),
'v.entity_id',
// only such syntax works in all sqlite,mysql,postgresql
knex.raw(`CAST(${table}.${key} AS char(255))`),
)
.select([...columns, 'versionId']);
};
}

Expand Down

0 comments on commit 984516f

Please sign in to comment.