mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
started event refactoring on database level
This commit is contained in:
parent
8611c53bc6
commit
0d6fb2a427
82
database/entity/0061-event_refactoring/Event.ts
Normal file
82
database/entity/0061-event_refactoring/Event.ts
Normal file
@ -0,0 +1,82 @@
|
||||
import { Contribution } from '@entity/Contribution'
|
||||
import { ContributionMessage } from '@entity/ContributionMessage'
|
||||
import { User } from '@entity/User'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, Transaction } from 'typeorm'
|
||||
import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer'
|
||||
|
||||
@Entity('event')
|
||||
// TODO tablename event_protocol
|
||||
export class Event extends BaseEntity {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@Column({ length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' })
|
||||
type: string
|
||||
|
||||
// TODO proper field type
|
||||
@Column({ name: 'created_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
|
||||
createdAt: Date
|
||||
|
||||
// TODO field name user_id
|
||||
// @Column({ name: 'affected_user_id', unsigned: true, nullable: false })
|
||||
// affectedUserId: number
|
||||
|
||||
@ManyToOne(() => User)
|
||||
@JoinColumn({ name: 'affected_user_id', referencedColumnName: 'id' })
|
||||
affectedUser: User | null
|
||||
|
||||
// TODO new column
|
||||
// TODO potentially save actingRole aswell
|
||||
// @Column({ name: 'acting_user_id', unsigned: true, nullable: false })
|
||||
// actingUserId: number
|
||||
|
||||
@ManyToOne(() => User)
|
||||
@JoinColumn({ name: 'acting_user_id', referencedColumnName: 'id' })
|
||||
actingUser: User | null
|
||||
|
||||
// TODO rename column x_user_id
|
||||
// @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
|
||||
|
||||
// TODO drop column xCommunityId
|
||||
|
||||
// TODO rename column transaction_id
|
||||
// @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
|
||||
|
||||
// TODO rename column contribution_id
|
||||
// @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
|
||||
|
||||
// TODO move column
|
||||
// TODO rename column message_id
|
||||
// TEST do we need the Id field definition?
|
||||
// @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({
|
||||
type: 'decimal',
|
||||
precision: 40,
|
||||
scale: 20,
|
||||
nullable: true,
|
||||
transformer: DecimalTransformer,
|
||||
})
|
||||
amount: Decimal | null
|
||||
}
|
||||
1
database/entity/Event.ts
Normal file
1
database/entity/Event.ts
Normal file
@ -0,0 +1 @@
|
||||
export { Event } from './0061-event_refactoring/Event'
|
||||
@ -1 +0,0 @@
|
||||
export { EventProtocol } from './0050-add_messageId_to_event_protocol/EventProtocol'
|
||||
@ -7,21 +7,21 @@ import { TransactionLink } from './TransactionLink'
|
||||
import { User } from './User'
|
||||
import { UserContact } from './UserContact'
|
||||
import { Contribution } from './Contribution'
|
||||
import { EventProtocol } from './EventProtocol'
|
||||
import { Event } from './Event'
|
||||
import { ContributionMessage } from './ContributionMessage'
|
||||
import { Community } from './Community'
|
||||
|
||||
export const entities = [
|
||||
Community,
|
||||
Contribution,
|
||||
ContributionLink,
|
||||
ContributionMessage,
|
||||
Event,
|
||||
LoginElopageBuys,
|
||||
LoginEmailOptIn,
|
||||
Migration,
|
||||
Transaction,
|
||||
TransactionLink,
|
||||
User,
|
||||
EventProtocol,
|
||||
ContributionMessage,
|
||||
UserContact,
|
||||
Community,
|
||||
]
|
||||
|
||||
33
database/migrations/0061-event_refactoring.ts
Normal file
33
database/migrations/0061-event_refactoring.ts
Normal file
@ -0,0 +1,33 @@
|
||||
/* MIGRATION TO REFACTOR THE EVENT_PROTOCOL TABLE
|
||||
*
|
||||
* This migration refactors the `event_protocol` table.
|
||||
* It renames the table to `event`, introduces new fields and renames others.
|
||||
*/
|
||||
|
||||
/* 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 `communities` MODIFY COLUMN `last_announced_at` datetime(3) AFTER `end_point`;',
|
||||
)
|
||||
await queryFn(
|
||||
'ALTER TABLE `communities` ADD COLUMN `foreign` tinyint(4) NOT NULL DEFAULT 1 AFTER `id`;',
|
||||
)
|
||||
await queryFn(
|
||||
'ALTER TABLE `communities` ADD COLUMN `verified_at` datetime(3) AFTER `last_announced_at`;',
|
||||
)
|
||||
await queryFn(
|
||||
'ALTER TABLE `communities` ADD COLUMN `last_error_at` datetime(3) AFTER `verified_at`;',
|
||||
)
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
// write downgrade logic as parameter of queryFn
|
||||
await queryFn(
|
||||
'ALTER TABLE `communities` MODIFY COLUMN `last_announced_at` datetime(3) NOT NULL AFTER `end_point`;',
|
||||
)
|
||||
await queryFn('ALTER TABLE `communities` DROP COLUMN `foreign`;')
|
||||
await queryFn('ALTER TABLE `communities` DROP COLUMN `verified_at`;')
|
||||
await queryFn('ALTER TABLE `communities` DROP COLUMN `last_error_at`;')
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user