From 65f53df9390fb617313bba246468875dc7013d85 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 20:34:37 +0200 Subject: [PATCH] added new column to event protocol dabatase table to keep message id --- .../EventProtocol.ts | 42 +++++++++++++++++++ .../0050-add_messageId_to_event_protocol.ts | 12 ++++++ 2 files changed, 54 insertions(+) create mode 100644 database/entity/0050-add_messageId_to_event_protocol/EventProtocol.ts create mode 100644 database/migrations/0050-add_messageId_to_event_protocol.ts diff --git a/database/entity/0050-add_messageId_to_event_protocol/EventProtocol.ts b/database/entity/0050-add_messageId_to_event_protocol/EventProtocol.ts new file mode 100644 index 000000000..d4dbc526f --- /dev/null +++ b/database/entity/0050-add_messageId_to_event_protocol/EventProtocol.ts @@ -0,0 +1,42 @@ +import Decimal from 'decimal.js-light' +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm' +import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' + +@Entity('event_protocol') +export class EventProtocol extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' }) + type: string + + @Column({ name: 'created_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) + createdAt: Date + + @Column({ name: 'user_id', unsigned: true, nullable: false }) + userId: number + + @Column({ name: 'x_user_id', unsigned: true, nullable: true }) + xUserId: number + + @Column({ name: 'x_community_id', unsigned: true, nullable: true }) + xCommunityId: number + + @Column({ name: 'transaction_id', unsigned: true, nullable: true }) + transactionId: number + + @Column({ name: 'contribution_id', unsigned: true, nullable: true }) + contributionId: number + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: true, + transformer: DecimalTransformer, + }) + amount: Decimal + + @Column({ name: 'message_id', unsigned: true, nullable: true }) + messageId: number +} diff --git a/database/migrations/0050-add_messageId_to_event_protocol.ts b/database/migrations/0050-add_messageId_to_event_protocol.ts new file mode 100644 index 000000000..ccef98688 --- /dev/null +++ b/database/migrations/0050-add_messageId_to_event_protocol.ts @@ -0,0 +1,12 @@ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn( + `ALTER TABLE \`event_protocol\` ADD COLUMN \`message_id\` int(10) unsigned NULL DEFAULT NULL;`, + ) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(`ALTER TABLE \`event_protocol\` DROP COLUMN \`message_id\`;`) +}