mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
database update, include contribution & transaction link ids
This commit is contained in:
parent
cbec3384e3
commit
4a9f3e666d
@ -10,7 +10,7 @@ Decimal.set({
|
||||
})
|
||||
|
||||
const constants = {
|
||||
DB_VERSION: '0062-event_contribution_confirm',
|
||||
DB_VERSION: '0063-event_link_fields',
|
||||
DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
|
||||
LOG4JS_CONFIG: 'log4js-config.json',
|
||||
// default log level on production should be info
|
||||
|
||||
99
database/entity/0063-event_link_fields/Event.ts
Normal file
99
database/entity/0063-event_link_fields/Event.ts
Normal file
@ -0,0 +1,99 @@
|
||||
import { Contribution } from '../Contribution'
|
||||
import { ContributionMessage } from '../ContributionMessage'
|
||||
import { User } from '../User'
|
||||
import { Transaction } from '../Transaction'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import {
|
||||
BaseEntity,
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm'
|
||||
import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer'
|
||||
import { TransactionLink } from '../TransactionLink'
|
||||
import { ContributionLink } from '../ContributionLink'
|
||||
|
||||
@Entity('events')
|
||||
export class Event extends BaseEntity {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@Column({ length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' })
|
||||
type: string
|
||||
|
||||
@CreateDateColumn({
|
||||
name: 'created_at',
|
||||
type: 'datetime',
|
||||
default: () => 'CURRENT_TIMESTAMP()',
|
||||
nullable: false,
|
||||
})
|
||||
createdAt: Date
|
||||
|
||||
@Column({ name: 'affected_user_id', unsigned: true, nullable: false })
|
||||
affectedUserId: number
|
||||
|
||||
@ManyToOne(() => User)
|
||||
@JoinColumn({ name: 'affected_user_id', referencedColumnName: 'id' })
|
||||
affectedUser: User
|
||||
|
||||
@Column({ name: 'acting_user_id', unsigned: true, nullable: false })
|
||||
actingUserId: number
|
||||
|
||||
@ManyToOne(() => User)
|
||||
@JoinColumn({ name: 'acting_user_id', referencedColumnName: 'id' })
|
||||
actingUser: User
|
||||
|
||||
@Column({ name: 'involved_user_id', type: 'int', unsigned: true, nullable: true })
|
||||
involvedUserId: number | null
|
||||
|
||||
@ManyToOne(() => User)
|
||||
@JoinColumn({ name: 'involved_user_id', referencedColumnName: 'id' })
|
||||
involvedUser: User | null
|
||||
|
||||
@Column({ name: 'involved_transaction_id', type: 'int', unsigned: true, nullable: true })
|
||||
involvedTransactionId: number | null
|
||||
|
||||
@ManyToOne(() => Transaction)
|
||||
@JoinColumn({ name: 'involved_transaction_id', referencedColumnName: 'id' })
|
||||
involvedTransaction: Transaction | null
|
||||
|
||||
@Column({ name: 'involved_contribution_id', type: 'int', unsigned: true, nullable: true })
|
||||
involvedContributionId: number | null
|
||||
|
||||
@ManyToOne(() => Contribution)
|
||||
@JoinColumn({ name: 'involved_contribution_id', referencedColumnName: 'id' })
|
||||
involvedContribution: Contribution | null
|
||||
|
||||
@Column({ name: 'involved_contribution_message_id', type: 'int', unsigned: true, nullable: true })
|
||||
involvedContributionMessageId: number | null
|
||||
|
||||
@ManyToOne(() => ContributionMessage)
|
||||
@JoinColumn({ name: 'involved_contribution_message_id', referencedColumnName: 'id' })
|
||||
involvedContributionMessage: ContributionMessage | null
|
||||
|
||||
@Column({ name: 'involved_transaction_link_id', type: 'int', unsigned: true, nullable: true })
|
||||
involvedTransactionLinkId: number | null
|
||||
|
||||
@ManyToOne(() => TransactionLink)
|
||||
@JoinColumn({ name: 'involved_transaction_link_id', referencedColumnName: 'id' })
|
||||
involvedTransactionLink: TransactionLink | null
|
||||
|
||||
@Column({ name: 'involved_contribution_link_id', type: 'int', unsigned: true, nullable: true })
|
||||
involvedContributionLinkId: number | null
|
||||
|
||||
@ManyToOne(() => ContributionLink)
|
||||
@JoinColumn({ name: 'involved_contribution_link_id', referencedColumnName: 'id' })
|
||||
involvedContributionLink: ContributionLink | null
|
||||
|
||||
@Column({
|
||||
type: 'decimal',
|
||||
precision: 40,
|
||||
scale: 20,
|
||||
nullable: true,
|
||||
transformer: DecimalTransformer,
|
||||
})
|
||||
amount: Decimal | null
|
||||
}
|
||||
@ -1 +1 @@
|
||||
export { Event } from './0061-event_refactoring/Event'
|
||||
export { Event } from './0063-event_link_fields/Event'
|
||||
|
||||
29
database/migrations/0063-event_link_fields.ts
Normal file
29
database/migrations/0063-event_link_fields.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/* MIGRATION TO ADD LINK ID FIELDS TO EVENT TABLE
|
||||
*
|
||||
* This migration add two fields to store a TransactionLinkId and a ContributionLinkId
|
||||
* in the event table. Furthermore the event `REDEEM_REGISTER` is rewritten to use the
|
||||
* new fields.
|
||||
*/
|
||||
|
||||
/* 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<Array<any>>) {
|
||||
await queryFn(
|
||||
'ALTER TABLE `events` ADD COLUMN `involved_transaction_link_id` int(10) unsigned DEFAULT NULL AFTER `involved_contribution_message_id`;',
|
||||
)
|
||||
await queryFn(
|
||||
'ALTER TABLE `events` ADD COLUMN `involved_contribution_link_id` int(10) unsigned DEFAULT NULL AFTER `involved_transaction_link_id`;',
|
||||
)
|
||||
await queryFn(
|
||||
'UPDATE `events` SET `involved_transaction_link_id` = `involved_transaction_id`, `involved_transaction_id` = NULL, `involved_contribution_link_id` = `involved_contribution_id`, `involved_contribution_id` = NULL WHERE `type` = "REDEEM_REGISTER";',
|
||||
)
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(
|
||||
'UPDATE `events` SET `involved_transaction_id` = `involved_transaction_link_id`, `involved_contribution_id` = `involved_contribution_link_id` WHERE `type` = "REDEEM_REGISTER";',
|
||||
)
|
||||
await queryFn('ALTER TABLE `events` DROP COLUMN `involved_contribution_link_id`;')
|
||||
await queryFn('ALTER TABLE `events` DROP COLUMN `involved_transaction_link_id`;')
|
||||
}
|
||||
@ -3,7 +3,7 @@ import dotenv from 'dotenv'
|
||||
dotenv.config()
|
||||
|
||||
const constants = {
|
||||
DB_VERSION: '0062-event_contribution_confirm',
|
||||
DB_VERSION: '0063-event_link_fields',
|
||||
LOG4JS_CONFIG: 'log4js-config.json',
|
||||
// default log level on production should be info
|
||||
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
|
||||
|
||||
@ -11,7 +11,7 @@ Decimal.set({
|
||||
*/
|
||||
|
||||
const constants = {
|
||||
DB_VERSION: '0062-event_contribution_confirm',
|
||||
DB_VERSION: '0063-event_link_fields',
|
||||
// DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
|
||||
LOG4JS_CONFIG: 'log4js-config.json',
|
||||
// default log level on production should be info
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user