1690900526061-delete_privileges.ts 925 B

1234567891011121314151617181920212223
  1. import { MigrationInterface, QueryRunner } from 'typeorm'
  2. export class DeletePrivileges1690900526061 implements MigrationInterface {
  3. public async up(queryRunner: QueryRunner): Promise<void> {
  4. const itemsWithPrivilegesContentTypeQueryResult = await queryRunner.manager.query(
  5. 'SELECT COUNT(*) as count FROM items i WHERE i.content_type = "SN|Privileges"',
  6. )
  7. const itemsWithPrivilegesContentTypeCount = +itemsWithPrivilegesContentTypeQueryResult[0].count
  8. const batchSize = 1_000
  9. const batchCount = Math.ceil(itemsWithPrivilegesContentTypeCount / batchSize)
  10. for (let batchIndex = 0; batchIndex < batchCount; batchIndex++) {
  11. await queryRunner.startTransaction()
  12. await queryRunner.manager.query(`DELETE FROM items WHERE content_type = "SN|Privileges" LIMIT ${batchSize}`)
  13. await queryRunner.commitTransaction()
  14. }
  15. }
  16. public async down(): Promise<void> {
  17. return
  18. }
  19. }