From 6dbe7b8c4b9dc9638fd5dddec6fe703b1f2b9c61 Mon Sep 17 00:00:00 2001 From: Claus-Peter Huebner Date: Tue, 22 Aug 2023 01:29:17 +0200 Subject: [PATCH] add pending_trtansactions table --- .../PendingTransaction.ts | 140 ++++++++++++++++++ database/entity/PendingTransaction.ts | 1 + database/entity/index.ts | 2 + .../0071-add-pending_transactions-table.ts | 34 +++++ 4 files changed, 177 insertions(+) create mode 100644 database/entity/0071-add-pending_transactions-table/PendingTransaction.ts create mode 100644 database/entity/PendingTransaction.ts create mode 100644 database/migrations/0071-add-pending_transactions-table.ts diff --git a/database/entity/0071-add-pending_transactions-table/PendingTransaction.ts b/database/entity/0071-add-pending_transactions-table/PendingTransaction.ts new file mode 100644 index 000000000..2cd67f2e3 --- /dev/null +++ b/database/entity/0071-add-pending_transactions-table/PendingTransaction.ts @@ -0,0 +1,140 @@ +/* eslint-disable no-use-before-define */ +import { Decimal } from 'decimal.js-light' +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from 'typeorm' +import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' +import { Contribution } from '../Contribution' + +@Entity('pending_transactions') +export class PendingTransaction extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ type: 'int', unsigned: true, unique: true, nullable: true, default: null }) + previous: number | null + + @Column({ name: 'type_id', unsigned: true, nullable: false }) + typeId: number + + @Column({ + name: 'transaction_link_id', + type: 'int', + unsigned: true, + nullable: true, + default: null, + }) + transactionLinkId?: number | null + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: false, + transformer: DecimalTransformer, + }) + amount: Decimal + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: false, + transformer: DecimalTransformer, + }) + balance: Decimal + + @Column({ + name: 'balance_date', + type: 'datetime', + default: () => 'CURRENT_TIMESTAMP', + nullable: false, + }) + balanceDate: Date + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: false, + transformer: DecimalTransformer, + }) + decay: Decimal + + @Column({ + name: 'decay_start', + type: 'datetime', + nullable: true, + default: null, + }) + decayStart: Date | null + + @Column({ length: 255, nullable: false, collation: 'utf8mb4_unicode_ci' }) + memo: string + + @Column({ name: 'creation_date', type: 'datetime', nullable: true, default: null }) + creationDate: Date | null + + @Column({ name: 'user_id', unsigned: true, nullable: false }) + userId: number + + @Column({ + name: 'user_gradido_id', + type: 'varchar', + length: 36, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + userGradidoID: string + + @Column({ + name: 'user_name', + type: 'varchar', + length: 512, + nullable: true, + collation: 'utf8mb4_unicode_ci', + }) + userName: string | null + + @Column({ + name: 'linked_user_id', + type: 'int', + unsigned: true, + nullable: true, + default: null, + }) + linkedUserId?: number | null + + @Column({ + name: 'linked_user_gradido_id', + type: 'varchar', + length: 36, + nullable: true, + collation: 'utf8mb4_unicode_ci', + }) + linkedUserGradidoID: string | null + + @Column({ + name: 'linked_user_name', + type: 'varchar', + length: 512, + nullable: true, + collation: 'utf8mb4_unicode_ci', + }) + linkedUserName: string | null + + @Column({ + name: 'linked_transaction_id', + type: 'int', + unsigned: true, + nullable: true, + default: null, + }) + linkedTransactionId?: number | null + + @OneToOne(() => Contribution, (contribution) => contribution.transaction) + @JoinColumn({ name: 'id', referencedColumnName: 'transactionId' }) + contribution?: Contribution | null + + @OneToOne(() => PendingTransaction) + @JoinColumn({ name: 'previous' }) + previousPendingTransaction?: PendingTransaction | null +} diff --git a/database/entity/PendingTransaction.ts b/database/entity/PendingTransaction.ts new file mode 100644 index 000000000..5ae28c2cd --- /dev/null +++ b/database/entity/PendingTransaction.ts @@ -0,0 +1 @@ +export { Transaction } from './0071-add-pending_transactions-table/PendingTransaction' diff --git a/database/entity/index.ts b/database/entity/index.ts index a5c37efa9..3352abdb4 100644 --- a/database/entity/index.ts +++ b/database/entity/index.ts @@ -13,6 +13,7 @@ import { Community } from './Community' import { FederatedCommunity } from './FederatedCommunity' import { UserRole } from './UserRole' import { DltTransaction } from './DltTransaction' +import { PendingTransaction } from './0071-add-pending_transactions-table/PendingTransaction' export const entities = [ Community, @@ -25,6 +26,7 @@ export const entities = [ LoginElopageBuys, LoginEmailOptIn, Migration, + PendingTransaction, Transaction, TransactionLink, User, diff --git a/database/migrations/0071-add-pending_transactions-table.ts b/database/migrations/0071-add-pending_transactions-table.ts new file mode 100644 index 000000000..2ad2a6ca2 --- /dev/null +++ b/database/migrations/0071-add-pending_transactions-table.ts @@ -0,0 +1,34 @@ +/* MIGRATION TO add new pending_transactions table */ + +/* 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(` + CREATE TABLE pending_transactions ( + id int unsigned NOT NULL AUTO_INCREMENT, + previous int(10) unsigned DEFAULT NULL NULL, + type_id int(10) DEFAULT NULL NULL, + transaction_link_id int(10) unsigned DEFAULT NULL NULL, + amount decimal(40,20) DEFAULT NULL NULL, + balance decimal(40,20) DEFAULT NULL NULL, + balance_date datetime(3) DEFAULT current_timestamp(3) NOT NULL, + decay decimal(40,20) DEFAULT NULL NULL, + decay_start datetime(3) DEFAULT NULL NULL, + memo varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + creation_date datetime(3) DEFAULT NULL NULL, + user_id int(10) unsigned NOT NULL, + user_gradido_id char(36) NOT NULL, + user_name varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL NULL, + linked_user_id int(10) unsigned DEFAULT NULL NULL, + linked_user_gradido_id char(36) NOT NULL, + linked_user_name varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL NULL, + linked_transaction_id int(10) DEFAULT NULL NULL, + state int(10) DEFAULT NULL NULL, + PRIMARY KEY (id) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(`DROP TABLE pending_transactions;`) +}