From c5c073bff412a7d0969e6ed008b4ba75d986e96a Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Sun, 17 Dec 2023 16:31:54 +0100 Subject: [PATCH] db update --- .../0003-refactor_transaction_recipe/Account.ts | 4 ++-- .../InvalidTransaction.ts | 2 +- .../migrations/0003-refactor_transaction_recipe.ts | 11 +++++------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dlt-database/entity/0003-refactor_transaction_recipe/Account.ts b/dlt-database/entity/0003-refactor_transaction_recipe/Account.ts index a6e8a8b7e..b8beea8ff 100644 --- a/dlt-database/entity/0003-refactor_transaction_recipe/Account.ts +++ b/dlt-database/entity/0003-refactor_transaction_recipe/Account.ts @@ -26,8 +26,8 @@ export class Account extends BaseEntity { @Column({ name: 'user_id', type: 'int', unsigned: true, nullable: true }) userId?: number - @Column({ name: 'derivation_index', type: 'int', unsigned: true, nullable: true }) - derivationIndex?: number + @Column({ name: 'derivation_index', type: 'int', unsigned: true }) + derivationIndex: number @Column({ name: 'derive2_pubkey', type: 'binary', length: 32, unique: true }) derive2Pubkey: Buffer diff --git a/dlt-database/entity/0003-refactor_transaction_recipe/InvalidTransaction.ts b/dlt-database/entity/0003-refactor_transaction_recipe/InvalidTransaction.ts index e103e253f..a34823dbd 100644 --- a/dlt-database/entity/0003-refactor_transaction_recipe/InvalidTransaction.ts +++ b/dlt-database/entity/0003-refactor_transaction_recipe/InvalidTransaction.ts @@ -5,7 +5,7 @@ export class InvalidTransaction extends BaseEntity { @PrimaryGeneratedColumn('increment', { unsigned: true, type: 'bigint' }) id: number - @Column({ name: 'iota_message_id', type: 'binary', length: 32 }) + @Column({ name: 'iota_message_id', type: 'binary', length: 32, unique: true }) iotaMessageId: Buffer @Column({ name: 'error_message', type: 'varchar', length: 255 }) diff --git a/dlt-database/migrations/0003-refactor_transaction_recipe.ts b/dlt-database/migrations/0003-refactor_transaction_recipe.ts index 2d3d92a23..882f2db00 100644 --- a/dlt-database/migrations/0003-refactor_transaction_recipe.ts +++ b/dlt-database/migrations/0003-refactor_transaction_recipe.ts @@ -13,9 +13,6 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis ; `) - await queryFn( - `ALTER TABLE \`accounts\` MODIFY COLUMN \`derivation_index\` int(10) unsigned NULL DEFAULT NULL;`, - ) await queryFn( `ALTER TABLE \`accounts\` ADD COLUMN \`balance_created_at\` decimal(40,20) NOT NULL DEFAULT 0 AFTER \`balance_confirmed_at_date\`;`, ) @@ -30,6 +27,9 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis `ALTER TABLE \`invalid_transactions\` ADD COLUMN \`error_message\` varchar(255) NOT NULL;`, ) + await queryFn(`ALTER TABLE \`invalid_transactions\` DROP INDEX \`iota_message_id\`;`) + await queryFn(`ALTER TABLE \`invalid_transactions\` ADD UNIQUE(\`iota_message_id\`);`) + await queryFn( `CREATE TABLE \`transactions\` ( \`id\` bigint unsigned NOT NULL AUTO_INCREMENT, @@ -120,12 +120,11 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom ; `) - await queryFn( - `ALTER TABLE \`accounts\` MODIFY COLUMN \`derivation_index\` int(10) unsigned NOT NULL;`, - ) await queryFn(`ALTER TABLE \`accounts\` DROP COLUMN \`balance_created_at\`;`) await queryFn(`ALTER TABLE \`accounts\` DROP COLUMN \`balance_created_at_date\`;`) await queryFn(`ALTER TABLE \`invalid_transactions\` DROP COLUMN \`error_message\`;`) + await queryFn(`ALTER TABLE \`invalid_transactions\` DROP INDEX \`iota_message_id\`;`) + await queryFn(`ALTER TABLE \`invalid_transactions\` ADD INDEX(\`iota_message_id\`); `) await queryFn(`DROP TABLE \`transactions\`;`) await queryFn(