diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 4dc092c86..6f03d21b9 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -12,7 +12,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0077-add_resubmission_date_contribution_message', + DB_VERSION: '0078-move_resubmission_date', 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 diff --git a/database/entity/0078-move_resubmission_date/Contribution.ts b/database/entity/0078-move_resubmission_date/Contribution.ts new file mode 100644 index 000000000..70e8960c8 --- /dev/null +++ b/database/entity/0078-move_resubmission_date/Contribution.ts @@ -0,0 +1,107 @@ +import { Decimal } from 'decimal.js-light' +import { + BaseEntity, + Column, + Entity, + PrimaryGeneratedColumn, + DeleteDateColumn, + JoinColumn, + ManyToOne, + OneToMany, + OneToOne, +} from 'typeorm' +import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' +import { User } from '../User' +import { ContributionMessage } from '../ContributionMessage' +import { Transaction } from '../Transaction' + +@Entity('contributions') +export class Contribution extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ unsigned: true, nullable: false, name: 'user_id' }) + userId: number + + @ManyToOne(() => User, (user) => user.contributions) + @JoinColumn({ name: 'user_id' }) + user: User + + @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP', name: 'created_at' }) + createdAt: Date + + @Column({ type: 'datetime', name: 'resubmission_at', default: null, nullable: true }) + resubmissionAt: Date | null + + @Column({ type: 'datetime', nullable: false, name: 'contribution_date' }) + contributionDate: Date + + @Column({ length: 255, nullable: false, collation: 'utf8mb4_unicode_ci' }) + memo: string + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: false, + transformer: DecimalTransformer, + }) + amount: Decimal + + @Column({ unsigned: true, nullable: true, name: 'moderator_id' }) + moderatorId: number + + @Column({ unsigned: true, nullable: true, name: 'contribution_link_id' }) + contributionLinkId: number + + @Column({ unsigned: true, nullable: true, name: 'confirmed_by' }) + confirmedBy: number + + @Column({ nullable: true, name: 'confirmed_at' }) + confirmedAt: Date + + @Column({ unsigned: true, nullable: true, name: 'denied_by' }) + deniedBy: number + + @Column({ nullable: true, name: 'denied_at' }) + deniedAt: Date + + @Column({ + name: 'contribution_type', + length: 12, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + contributionType: string + + @Column({ + name: 'contribution_status', + length: 12, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + contributionStatus: string + + @Column({ unsigned: true, nullable: true, name: 'transaction_id' }) + transactionId: number + + @Column({ nullable: true, name: 'updated_at' }) + updatedAt: Date + + @Column({ nullable: true, unsigned: true, name: 'updated_by', type: 'int' }) + updatedBy: number | null + + @DeleteDateColumn({ name: 'deleted_at' }) + deletedAt: Date | null + + @DeleteDateColumn({ unsigned: true, nullable: true, name: 'deleted_by' }) + deletedBy: number + + @OneToMany(() => ContributionMessage, (message) => message.contribution) + @JoinColumn({ name: 'contribution_id' }) + messages?: ContributionMessage[] + + @OneToOne(() => Transaction, (transaction) => transaction.contribution) + @JoinColumn({ name: 'transaction_id' }) + transaction?: Transaction | null +} diff --git a/database/entity/0078-move_resubmission_date/ContributionMessage.ts b/database/entity/0078-move_resubmission_date/ContributionMessage.ts new file mode 100644 index 000000000..93bcce4ed --- /dev/null +++ b/database/entity/0078-move_resubmission_date/ContributionMessage.ts @@ -0,0 +1,60 @@ +import { + BaseEntity, + Column, + CreateDateColumn, + DeleteDateColumn, + Entity, + Index, + JoinColumn, + ManyToOne, + PrimaryGeneratedColumn, + UpdateDateColumn, +} from 'typeorm' +import { Contribution } from '../Contribution' +import { User } from '../User' + +@Entity('contribution_messages', { + engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci', +}) +export class ContributionMessage extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Index() + @Column({ name: 'contribution_id', unsigned: true, nullable: false }) + contributionId: number + + @ManyToOne(() => Contribution, (contribution) => contribution.messages) + @JoinColumn({ name: 'contribution_id' }) + contribution: Contribution + + @Column({ name: 'user_id', unsigned: true, nullable: false }) + userId: number + + @ManyToOne(() => User, (user) => user.messages) + @JoinColumn({ name: 'user_id' }) + user: User + + @Column({ length: 2000, nullable: false, collation: 'utf8mb4_unicode_ci' }) + message: string + + @CreateDateColumn() + @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP', name: 'created_at' }) + createdAt: Date + + @UpdateDateColumn() + @Column({ type: 'datetime', default: null, nullable: true, name: 'updated_at' }) + updatedAt: Date + + @DeleteDateColumn({ name: 'deleted_at' }) + deletedAt: Date | null + + @Column({ name: 'deleted_by', default: null, unsigned: true, nullable: true }) + deletedBy: number + + @Column({ length: 12, nullable: false, collation: 'utf8mb4_unicode_ci' }) + type: string + + @Column({ name: 'is_moderator', type: 'bool', nullable: false, default: false }) + isModerator: boolean +} diff --git a/database/entity/Contribution.ts b/database/entity/Contribution.ts index 2a2e89cfa..82715c0c6 100644 --- a/database/entity/Contribution.ts +++ b/database/entity/Contribution.ts @@ -1 +1 @@ -export { Contribution } from './0076-add_updated_by_contribution/Contribution' +export { Contribution } from './0078-move_resubmission_date/Contribution' diff --git a/database/entity/ContributionMessage.ts b/database/entity/ContributionMessage.ts index d1512863b..b4b1180da 100644 --- a/database/entity/ContributionMessage.ts +++ b/database/entity/ContributionMessage.ts @@ -1 +1 @@ -export { ContributionMessage } from './0077-add_resubmission_date_contribution_message/ContributionMessage' +export { ContributionMessage } from './0078-move_resubmission_date/ContributionMessage' diff --git a/database/migrations/0078-move_resubmission_date.ts b/database/migrations/0078-move_resubmission_date.ts new file mode 100644 index 000000000..3cc49b240 --- /dev/null +++ b/database/migrations/0078-move_resubmission_date.ts @@ -0,0 +1,16 @@ +/* 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 \`contribution_messages\` DROP COLUMN \`resubmission_at\`;`) + await queryFn( + `ALTER TABLE \`contributions\` ADD COLUMN \`resubmission_at\` datetime NULL DEFAULT NULL AFTER \`created_at \`;`, + ) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn( + `ALTER TABLE \`contribution_messages\` ADD COLUMN \`resubmission_at\` datetime NULL DEFAULT NULL AFTER \`deleted_by\`;`, + ) + await queryFn(`ALTER TABLE \`contributions\` DROP COLUMN \`resubmission_at\`;`) +} diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index 49660e856..2548166f4 100644 --- a/dht-node/src/config/index.ts +++ b/dht-node/src/config/index.ts @@ -4,7 +4,7 @@ import dotenv from 'dotenv' dotenv.config() const constants = { - DB_VERSION: '0077-add_resubmission_date_contribution_message', + DB_VERSION: '0078-move_resubmission_date', LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info LOG_LEVEL: process.env.LOG_LEVEL || 'info', diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index a4acbd1cf..036ce67ee 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -10,7 +10,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0077-add_resubmission_date_contribution_message', + DB_VERSION: '0078-move_resubmission_date', 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