Skip to content

Commit

Permalink
Disable update of coordinates status log (#5369)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored Aug 13, 2024
1 parent 6ca77ad commit 1eb06c2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 50 deletions.
2 changes: 1 addition & 1 deletion integration-tests/tests/api/schema/cleanup-tracker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function fetchCoordinates(db: CommonQueryMethods, target: { id: string })
return result.rows;
}

describe('schema cleanup tracker', () => {
describe.skip('schema cleanup tracker', () => {
test.concurrent('single', async ({ expect }) => {
const { publishSchema, target, createDbConnection } = await prepare();
// This API is soooooooooooo awkward xD
Expand Down
102 changes: 53 additions & 49 deletions packages/services/storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5165,66 +5165,70 @@ async function updateSchemaCoordinateStatus(
const actions: Promise<unknown>[] = [];

if (args.coordinatesDiff.deleted) {
actions.push(
trx.query(sql`/* schema_coordinate_status_deleted */
DELETE FROM schema_coordinate_status
WHERE
target_id = ${args.targetId}
AND
coordinate = ANY(${sql.array(Array.from(args.coordinatesDiff.deleted), 'text')})
AND
created_at <= NOW()
`),
);
console.log('DELETED', JSON.stringify(Array.from(args.coordinatesDiff.deleted)));
// actions.push(
// trx.query(sql`/* schema_coordinate_status_deleted */
// DELETE FROM schema_coordinate_status
// WHERE
// target_id = ${args.targetId}
// AND
// coordinate = ANY(${sql.array(Array.from(args.coordinatesDiff.deleted), 'text')})
// AND
// created_at <= NOW()
// `),
// );
}

if (args.coordinatesDiff.added) {
actions.push(
trx.query(sql`/* schema_coordinate_status_inserted */
INSERT INTO schema_coordinate_status
( target_id, coordinate, created_in_version_id, deprecated_at, deprecated_in_version_id )
SELECT * FROM ${sql.unnest(
Array.from(args.coordinatesDiff.added).map(coordinate => {
const isDeprecatedAsWell = args.coordinatesDiff.deprecated.has(coordinate);
return [
args.targetId,
coordinate,
args.versionId,
// if it's added and deprecated at the same time
isDeprecatedAsWell ? 'NOW()' : null,
isDeprecatedAsWell ? args.versionId : null,
];
}),
['uuid', 'text', 'uuid', 'date', 'uuid'],
)}
`),
);
console.log('ADDED', JSON.stringify(Array.from(args.coordinatesDiff.added)));
// actions.push(
// trx.query(sql`/* schema_coordinate_status_inserted */
// INSERT INTO schema_coordinate_status
// ( target_id, coordinate, created_in_version_id, deprecated_at, deprecated_in_version_id )
// SELECT * FROM ${sql.unnest(
// Array.from(args.coordinatesDiff.added).map(coordinate => {
// const isDeprecatedAsWell = args.coordinatesDiff.deprecated.has(coordinate);
// return [
// args.targetId,
// coordinate,
// args.versionId,
// // if it's added and deprecated at the same time
// isDeprecatedAsWell ? 'NOW()' : null,
// isDeprecatedAsWell ? args.versionId : null,
// ];
// }),
// ['uuid', 'text', 'uuid', 'date', 'uuid'],
// )}
// `),
// );
}

if (args.coordinatesDiff.undeprecated) {
actions.push(
trx.query(sql`/* schema_coordinate_status_undeprecated */
UPDATE schema_coordinate_status
SET deprecated_at = NULL, deprecated_in_version_id = NULL
WHERE
target_id = ${args.targetId}
AND
coordinate = ANY(${sql.array(Array.from(args.coordinatesDiff.undeprecated), 'text')})
`),
);
console.log('UNDEPRECATED', JSON.stringify(Array.from(args.coordinatesDiff.undeprecated)));
// actions.push(
// trx.query(sql`/* schema_coordinate_status_undeprecated */
// UPDATE schema_coordinate_status
// SET deprecated_at = NULL, deprecated_in_version_id = NULL
// WHERE
// target_id = ${args.targetId}
// AND
// coordinate = ANY(${sql.array(Array.from(args.coordinatesDiff.undeprecated), 'text')})
// `),
// );
}

await Promise.all(actions);

if (args.coordinatesDiff.deprecated) {
await trx.query(sql`/* schema_coordinate_status_deprecated */
UPDATE schema_coordinate_status
SET deprecated_at = NOW(), deprecated_in_version_id = ${args.versionId}
WHERE
target_id = ${args.targetId}
AND
coordinate = ANY(${sql.array(Array.from(args.coordinatesDiff.deprecated), 'text')})
`);
console.log('DEPRECATED', JSON.stringify(Array.from(args.coordinatesDiff.deprecated)));
// await trx.query(sql`/* schema_coordinate_status_deprecated */
// UPDATE schema_coordinate_status
// SET deprecated_at = NOW(), deprecated_in_version_id = ${args.versionId}
// WHERE
// target_id = ${args.targetId}
// AND
// coordinate = ANY(${sql.array(Array.from(args.coordinatesDiff.deprecated), 'text')})
// `);
}
}

Expand Down

0 comments on commit 1eb06c2

Please sign in to comment.