1690900526061-delete_privileges.ts 838 B

123456789101112131415161718192021
  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.manager.query(`DELETE FROM items WHERE content_type = "SN|Privileges" LIMIT ${batchSize}`)
  12. }
  13. }
  14. public async down(): Promise<void> {
  15. return
  16. }
  17. }