Przeglądaj źródła

feat(syncing-server): remove legacy privileges items (#679)

Co-authored-by: Karol Sójko <karolsojko@proton.me>
Karol Sójko 1 rok temu
rodzic
commit
e9bba6fd3a

+ 21 - 0
packages/syncing-server/migrations/mysql/1690900526061-delete_privileges.ts

@@ -0,0 +1,21 @@
+import { MigrationInterface, QueryRunner } from 'typeorm'
+
+export class DeletePrivileges1690900526061 implements MigrationInterface {
+  public async up(queryRunner: QueryRunner): Promise<void> {
+    const itemsWithPrivilegesContentTypeQueryResult = await queryRunner.manager.query(
+      'SELECT COUNT(*) as count FROM items i WHERE i.content_type = "SN|Privileges"',
+    )
+    const itemsWithPrivilegesContentTypeCount = +itemsWithPrivilegesContentTypeQueryResult[0].count
+
+    const batchSize = 1_000
+    const batchCount = Math.ceil(itemsWithPrivilegesContentTypeCount / batchSize)
+
+    for (let batchIndex = 0; batchIndex < batchCount; batchIndex++) {
+      await queryRunner.manager.query(`DELETE FROM items WHERE content_type = "SN|Privileges" LIMIT ${batchSize}`)
+    }
+  }
+
+  public async down(): Promise<void> {
+    return
+  }
+}

+ 21 - 0
packages/syncing-server/migrations/sqlite/1690901030484-delete_privileges.ts

@@ -0,0 +1,21 @@
+import { MigrationInterface, QueryRunner } from 'typeorm'
+
+export class DeletePrivileges1690901030484 implements MigrationInterface {
+  public async up(queryRunner: QueryRunner): Promise<void> {
+    const itemsWithPrivilegesContentTypeQueryResult = await queryRunner.manager.query(
+      'SELECT COUNT(*) as count FROM items i WHERE i.content_type = "SN|Privileges"',
+    )
+    const itemsWithPrivilegesContentTypeCount = +itemsWithPrivilegesContentTypeQueryResult[0].count
+
+    const batchSize = 1_000
+    const batchCount = Math.ceil(itemsWithPrivilegesContentTypeCount / batchSize)
+
+    for (let batchIndex = 0; batchIndex < batchCount; batchIndex++) {
+      await queryRunner.manager.query(`DELETE FROM items WHERE content_type = "SN|Privileges" LIMIT ${batchSize}`)
+    }
+  }
+
+  public async down(): Promise<void> {
+    return
+  }
+}