-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2577983
commit 14b578e
Showing
5 changed files
with
68 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm' | ||
import { Key } from 'daf-core' | ||
import { SecretBox } from 'daf-libsodium' | ||
|
||
export class SecretBox1588075773000 implements MigrationInterface { | ||
async up(queryRunner: QueryRunner): Promise<void> { | ||
const exists = await queryRunner.hasTable('key') | ||
if (exists) { | ||
const secretBox = new SecretBox(process.env.DAF_SECRET_KEY) | ||
const keys = await queryRunner.connection.getRepository(Key).find() | ||
for (const key of keys) { | ||
key.privateKeyHex = await secretBox.encrypt(key.privateKeyHex) | ||
await key.save() | ||
} | ||
} | ||
} | ||
|
||
async down(queryRunner: QueryRunner): Promise<void> { | ||
const exists = await queryRunner.hasTable('key') | ||
if (exists) { | ||
const secretBox = new SecretBox(process.env.DAF_SECRET_KEY) | ||
const keys = await queryRunner.connection.getRepository(Key).find() | ||
for (const key of keys) { | ||
key.privateKeyHex = await secretBox.decrypt(key.privateKeyHex) | ||
await key.save() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { SecretBox1588075773000 } from './SecretBox1588075773000' | ||
|
||
export const migrations = [SecretBox1588075773000] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 16 additions & 8 deletions
24
packages/daf-core/src/migrations/CredentialStatus1587985317000.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
import {MigrationInterface, QueryRunner } from "typeorm"; | ||
import { MigrationInterface, QueryRunner } from 'typeorm' | ||
|
||
export class CredentialStatus1587985317000 implements MigrationInterface { | ||
|
||
async up(queryRunner: QueryRunner): Promise<void> { | ||
if (!queryRunner.hasColumn('credential', 'credentialStatus')) { | ||
await queryRunner.query('ALTER TABLE credential ADD credentialStatus TEXT NULL') | ||
const tableExists = await queryRunner.hasTable('credential') | ||
if (tableExists) { | ||
const columnExists = await queryRunner.hasColumn('credential', 'credentialStatus') | ||
if (!columnExists) { | ||
await queryRunner.query('ALTER TABLE credential ADD credentialStatus TEXT NULL') | ||
} | ||
} | ||
} | ||
|
||
async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query('ALTER TABLE credential DROP credentialStatus') | ||
const tableExists = await queryRunner.hasTable('credential') | ||
if (tableExists) { | ||
const columnExists = await queryRunner.hasColumn('credential', 'credentialStatus') | ||
if (columnExists) { | ||
await queryRunner.query('ALTER TABLE credential DROP credentialStatus') | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { CredentialStatus1587985317000 } from './CredentialStatus1587985317000' | ||
|
||
export const migrations = [ | ||
CredentialStatus1587985317000 | ||
] | ||
export const migrations = [CredentialStatus1587985317000] |