diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 7ded1b8f4..37a654f8e 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -12,7 +12,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0087-add_dlt_users_table', + DB_VERSION: '0088-merge_dlt_tables', 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/0087-add_dlt_users_table/DltUser.ts b/database/entity/0087-add_dlt_users_table/DltUser.ts index 483437d58..2b9dccb3f 100644 --- a/database/entity/0087-add_dlt_users_table/DltUser.ts +++ b/database/entity/0087-add_dlt_users_table/DltUser.ts @@ -1,5 +1,6 @@ import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from 'typeorm' -import { User } from '../User' +// this Entity was removed in current code and isn't any longer compatible with user +import { User } from './User' @Entity('dlt_users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' }) export class DltUser extends BaseEntity { diff --git a/database/entity/0088-merge_dlt_tables/DltTransaction.ts b/database/entity/0088-merge_dlt_tables/DltTransaction.ts new file mode 100644 index 000000000..6525c229d --- /dev/null +++ b/database/entity/0088-merge_dlt_tables/DltTransaction.ts @@ -0,0 +1,52 @@ +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from 'typeorm' +import { Transaction } from '../Transaction' +import { User } from '../User' +import { TransactionLink } from '../TransactionLink' + +@Entity('dlt_transactions', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' }) +export class DltTransaction extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ name: 'transaction_id', type: 'int', unsigned: true, nullable: true }) + transactionId?: number | null + + @Column({ name: 'user_id', type: 'int', unsigned: true, nullable: true }) + userId?: number | null + + @Column({ name: 'transaction_link_id', type: 'int', unsigned: true, nullable: true }) + transactionLinkId?: number | null + + @Column({ + name: 'message_id', + length: 64, + nullable: true, + default: null, + collation: 'utf8mb4_unicode_ci', + }) + messageId: string + + @Column({ name: 'verified', type: 'bool', nullable: false, default: false }) + verified: boolean + + @Column({ name: 'created_at', default: () => 'CURRENT_TIMESTAMP(3)', nullable: false }) + createdAt: Date + + @Column({ name: 'verified_at', nullable: true, default: null, type: 'datetime' }) + verifiedAt: Date | null + + @Column({ name: 'error', type: 'text', nullable: true }) + error: string | null + + @OneToOne(() => Transaction, (transaction) => transaction.dltTransaction) + @JoinColumn({ name: 'transaction_id' }) + transaction?: Transaction | null + + @OneToOne(() => User, (user) => user.dltTransaction) + @JoinColumn({ name: 'user_id' }) + user?: User | null + + @OneToOne(() => TransactionLink, (transactionLink) => transactionLink.dltTransaction) + @JoinColumn({ name: 'transaction_link_id' }) + transactionLink?: TransactionLink | null +} diff --git a/database/entity/0088-merge_dlt_tables/TransactionLink.ts b/database/entity/0088-merge_dlt_tables/TransactionLink.ts new file mode 100644 index 000000000..3258e346f --- /dev/null +++ b/database/entity/0088-merge_dlt_tables/TransactionLink.ts @@ -0,0 +1,74 @@ +import { Decimal } from 'decimal.js-light' +import { + BaseEntity, + Entity, + PrimaryGeneratedColumn, + Column, + DeleteDateColumn, + OneToOne, + JoinColumn, +} from 'typeorm' +import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' +import { DltTransaction } from '../DltTransaction' + +@Entity('transaction_links') +export class TransactionLink extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ unsigned: true, nullable: false }) + userId: number + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: false, + transformer: DecimalTransformer, + }) + amount: Decimal + + @Column({ + type: 'decimal', + name: 'hold_available_amount', + precision: 40, + scale: 20, + nullable: false, + transformer: DecimalTransformer, + }) + holdAvailableAmount: Decimal + + @Column({ length: 255, nullable: false, collation: 'utf8mb4_unicode_ci' }) + memo: string + + @Column({ length: 24, nullable: false, collation: 'utf8mb4_unicode_ci' }) + code: string + + @Column({ + type: 'datetime', + nullable: false, + }) + createdAt: Date + + @DeleteDateColumn() + deletedAt: Date | null + + @Column({ + type: 'datetime', + nullable: false, + }) + validUntil: Date + + @Column({ + type: 'datetime', + nullable: true, + }) + redeemedAt: Date | null + + @Column({ type: 'int', unsigned: true, nullable: true }) + redeemedBy: number | null + + @OneToOne(() => DltTransaction, (dlt) => dlt.transactionLinkId) + @JoinColumn({ name: 'id', referencedColumnName: 'transactionLinkId' }) + dltTransaction?: DltTransaction | null +} diff --git a/database/entity/0088-merge_dlt_tables/User.ts b/database/entity/0088-merge_dlt_tables/User.ts new file mode 100644 index 000000000..d133cdad8 --- /dev/null +++ b/database/entity/0088-merge_dlt_tables/User.ts @@ -0,0 +1,181 @@ +import { + BaseEntity, + Entity, + PrimaryGeneratedColumn, + Column, + DeleteDateColumn, + OneToMany, + JoinColumn, + OneToOne, + Geometry, + ManyToOne, +} from 'typeorm' +import { Contribution } from '../Contribution' +import { ContributionMessage } from '../ContributionMessage' +import { UserContact } from '../UserContact' +import { UserRole } from '../UserRole' +import { GeometryTransformer } from '../../src/typeorm/GeometryTransformer' +import { Community } from '../Community' +import { DltTransaction } from '../DltTransaction' + +@Entity('users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' }) +export class User extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ type: 'bool', default: false }) + foreign: boolean + + @Column({ + name: 'gradido_id', + length: 36, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + gradidoID: string + + @Column({ + name: 'community_uuid', + type: 'char', + length: 36, + nullable: true, + collation: 'utf8mb4_unicode_ci', + }) + communityUuid: string + + @ManyToOne(() => Community, (community) => community.users) + @JoinColumn({ name: 'community_uuid', referencedColumnName: 'communityUuid' }) + community: Community | null + + @Column({ + name: 'alias', + length: 20, + nullable: true, + default: null, + collation: 'utf8mb4_unicode_ci', + }) + alias: string + + @OneToOne(() => UserContact, (emailContact: UserContact) => emailContact.user) + @JoinColumn({ name: 'email_id' }) + emailContact: UserContact + + @Column({ name: 'email_id', type: 'int', unsigned: true, nullable: true, default: null }) + emailId: number | null + + @Column({ + name: 'first_name', + length: 255, + nullable: true, + default: null, + collation: 'utf8mb4_unicode_ci', + }) + firstName: string + + @Column({ + name: 'last_name', + length: 255, + nullable: true, + default: null, + collation: 'utf8mb4_unicode_ci', + }) + lastName: string + + @Column({ name: 'gms_publish_name', type: 'int', unsigned: true, nullable: false, default: 0 }) + gmsPublishName: number + + @Column({ name: 'humhub_publish_name', type: 'int', unsigned: true, nullable: false, default: 0 }) + humhubPublishName: number + + @Column({ name: 'created_at', default: () => 'CURRENT_TIMESTAMP(3)', nullable: false }) + createdAt: Date + + @DeleteDateColumn({ name: 'deleted_at', nullable: true }) + deletedAt: Date | null + + @Column({ type: 'bigint', default: 0, unsigned: true }) + password: BigInt + + @Column({ + name: 'password_encryption_type', + type: 'int', + unsigned: true, + nullable: false, + default: 0, + }) + passwordEncryptionType: number + + @Column({ length: 4, default: 'de', collation: 'utf8mb4_unicode_ci', nullable: false }) + language: string + + @Column({ type: 'bool', default: false }) + hideAmountGDD: boolean + + @Column({ type: 'bool', default: false }) + hideAmountGDT: boolean + + @OneToMany(() => UserRole, (userRole) => userRole.user) + @JoinColumn({ name: 'user_id' }) + userRoles: UserRole[] + + @Column({ name: 'referrer_id', type: 'int', unsigned: true, nullable: true, default: null }) + referrerId?: number | null + + @Column({ + name: 'contribution_link_id', + type: 'int', + unsigned: true, + nullable: true, + default: null, + }) + contributionLinkId?: number | null + + @Column({ name: 'publisher_id', default: 0 }) + publisherId: number + + @Column({ name: 'gms_allowed', type: 'bool', default: true }) + gmsAllowed: boolean + + @Column({ + name: 'location', + type: 'geometry', + default: null, + nullable: true, + transformer: GeometryTransformer, + }) + location: Geometry | null + + @Column({ + name: 'gms_publish_location', + type: 'int', + unsigned: true, + nullable: false, + default: 2, + }) + gmsPublishLocation: number + + @Column({ name: 'gms_registered', type: 'bool', default: false }) + gmsRegistered: boolean + + @Column({ name: 'gms_registered_at', type: 'datetime', default: null, nullable: true }) + gmsRegisteredAt: Date | null + + @Column({ name: 'humhub_allowed', type: 'bool', default: false }) + humhubAllowed: boolean + + @OneToMany(() => Contribution, (contribution) => contribution.user) + @JoinColumn({ name: 'user_id' }) + contributions?: Contribution[] + + @OneToMany(() => ContributionMessage, (message) => message.user) + @JoinColumn({ name: 'user_id' }) + messages?: ContributionMessage[] + + @OneToMany(() => UserContact, (userContact: UserContact) => userContact.user) + @JoinColumn({ name: 'user_id' }) + userContacts?: UserContact[] + + @OneToOne(() => DltTransaction, (dlt) => dlt.userId) + @JoinColumn({ name: 'id', referencedColumnName: 'userId' }) + dltTransaction?: DltTransaction | null +} diff --git a/database/entity/DltTransaction.ts b/database/entity/DltTransaction.ts index 31c21d583..373e5f593 100644 --- a/database/entity/DltTransaction.ts +++ b/database/entity/DltTransaction.ts @@ -1 +1 @@ -export { DltTransaction } from './0087-add_dlt_users_table/DltTransaction' +export { DltTransaction } from './0088-merge_dlt_tables/DltTransaction' diff --git a/database/entity/TransactionLink.ts b/database/entity/TransactionLink.ts index a483f0171..ff69e101f 100644 --- a/database/entity/TransactionLink.ts +++ b/database/entity/TransactionLink.ts @@ -1 +1 @@ -export { TransactionLink } from './0031-remove_sendEmail_from_transaction_link/TransactionLink' +export { TransactionLink } from './0088-merge_dlt_tables/TransactionLink' diff --git a/database/entity/User.ts b/database/entity/User.ts index 5267c24cc..3836c683e 100644 --- a/database/entity/User.ts +++ b/database/entity/User.ts @@ -1 +1 @@ -export { User } from './0087-add_dlt_users_table/User' +export { User } from './0088-merge_dlt_tables/User' diff --git a/database/entity/index.ts b/database/entity/index.ts index a5a988490..3352abdb4 100644 --- a/database/entity/index.ts +++ b/database/entity/index.ts @@ -13,7 +13,6 @@ import { Community } from './Community' import { FederatedCommunity } from './FederatedCommunity' import { UserRole } from './UserRole' import { DltTransaction } from './DltTransaction' -import { DltUser } from './DltUser' import { PendingTransaction } from './0071-add-pending_transactions-table/PendingTransaction' export const entities = [ @@ -22,7 +21,6 @@ export const entities = [ ContributionLink, ContributionMessage, DltTransaction, - DltUser, Event, FederatedCommunity, LoginElopageBuys, diff --git a/database/migrations/0088-merge_dlt_tables.ts b/database/migrations/0088-merge_dlt_tables.ts new file mode 100644 index 000000000..7964ffd94 --- /dev/null +++ b/database/migrations/0088-merge_dlt_tables.ts @@ -0,0 +1,33 @@ +/* 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(`DROP TABLE \`dlt_users\`;`) + await queryFn(` + ALTER TABLE \`dlt_transactions\` + CHANGE \`transaction_id\` \`transaction_id\` INT(10) UNSIGNED NULL DEFAULT NULL, + ADD \`user_id\` INT UNSIGNED NULL DEFAULT NULL AFTER \`transaction_id\`, + ADD \`transaction_link_id\` INT UNSIGNED NULL DEFAULT NULL AFTER \`user_id\`; + `) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(` + CREATE TABLE \`dlt_users\` ( + \`id\` int unsigned NOT NULL AUTO_INCREMENT, + \`user_id\` int(10) unsigned NOT NULL, + \`message_id\` varchar(64) NULL DEFAULT NULL, + \`verified\` tinyint(4) NOT NULL DEFAULT 0, + \`created_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + \`verified_at\` datetime(3), + \`error\` text NULL DEFAULT NULL, + PRIMARY KEY (id) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`) + + await queryFn(` + ALTER TABLE \`dlt_transactions\` + CHANGE \`transaction_id\` \`transaction_id\` INT(10) UNSIGNED NOT NULL, + DROP COLUMN \`user_id\`, + DROP COLUMN \`transaction_link_id\`; + `) +} diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index f2dc456b4..e0e7f094c 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: '0087-add_dlt_users_table', + DB_VERSION: '0088-merge_dlt_tables', 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 4ada82244..61ac3471d 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -10,7 +10,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0087-add_dlt_users_table', + DB_VERSION: '0088-merge_dlt_tables', 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