2020-09-16 22:42:25 +03:00
|
|
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
|
|
import { decrypt, encrypt } from "../utils/crypt";
|
|
|
|
|
|
|
|
export class EncryptArchives1600285077890 implements MigrationInterface {
|
|
|
|
public async up(queryRunner: QueryRunner): Promise<any> {
|
|
|
|
const archives = await queryRunner.query("SELECT id, body FROM archives");
|
|
|
|
for (const archive of archives) {
|
2021-10-09 14:21:23 +03:00
|
|
|
const encryptedBody = await encrypt(archive.body);
|
2020-09-16 22:42:25 +03:00
|
|
|
await queryRunner.query("UPDATE archives SET body = ? WHERE id = ?", [encryptedBody, archive.id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<any> {
|
|
|
|
const archives = await queryRunner.query("SELECT id, body FROM archives");
|
|
|
|
for (const archive of archives) {
|
2021-10-09 14:21:23 +03:00
|
|
|
const decryptedBody = await decrypt(archive.body);
|
2020-09-16 22:42:25 +03:00
|
|
|
await queryRunner.query("UPDATE archives SET body = ? WHERE id = ?", [decryptedBody, archive.id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|