From 84c0c6f10b7cc07083f6b4ea439035257a28f68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 26 May 2022 02:56:38 +0200 Subject: [PATCH 1/7] start creating contributionLinks table --- .../ContributionLinks.ts | 108 ++++++++++++++++++ database/entity/ContributionLinks.ts | 1 + 2 files changed, 109 insertions(+) create mode 100644 database/entity/0038-add_contribution_links_table/ContributionLinks.ts create mode 100644 database/entity/ContributionLinks.ts diff --git a/database/entity/0038-add_contribution_links_table/ContributionLinks.ts b/database/entity/0038-add_contribution_links_table/ContributionLinks.ts new file mode 100644 index 000000000..5f78a7450 --- /dev/null +++ b/database/entity/0038-add_contribution_links_table/ContributionLinks.ts @@ -0,0 +1,108 @@ +import Decimal from 'decimal.js-light' +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm' +import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' + +export enum CycleTypes { + ONCE = 1, + HOUR = 2, + TWOHOURS = 3, + FOURHOURS = 4, + EIGHTHOURS = 5, + HALFDAY = 6, + DAY = 7, + TWODAYS = 8, + THREEDAYS = 9, + FOURDAYS = 10, + FIVEDAYS = 11, + SIXDAYS = 12, + WEEK = 13, + TWOWEEKS = 14, + MONTH = 15, + TWOMONTH = 16, + QUARTER = 17, + HALFYEAR = 18, + YEAR = 19, +} + +@Entity('contribution_links') +export class ContributionLinks extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' }) + name: string + + @Column({ length: 255, nullable: false, collation: 'utf8mb4_unicode_ci' }) + description: string + + @Column({ name: 'valid_from', type: 'datetime', nullable: true, default: null }) + validFrom: Date | null + + @Column({ name: 'valid_to', type: 'datetime', nullable: true, default: null }) + validTo: Date | null + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: false, + transformer: DecimalTransformer, + }) + amount: Decimal + + @Column({ name: 'cycle', unsigned: true, nullable: false }) + cycle: number + + @Column({ name: 'max_per_cycle', unsigned: true, nullable: false, default: 1 }) + maxPerCycle: number + + @Column({ + name: 'max_amount_per_month', + type: 'decimal', + precision: 40, + scale: 20, + nullable: true, + default: null, + transformer: DecimalTransformer, + }) + maxAmountPerMonth: Decimal + + @Column({ + name: 'total_max_count_of_contribution', + unsigned: true, + nullable: true, + default: null, + }) + totalMaxCountOfContribution: number | null + + @Column({ + name: 'max_account_balance', + type: 'decimal', + precision: 40, + scale: 20, + nullable: true, + default: null, + transformer: DecimalTransformer, + }) + maxAccountBalance: Decimal + + @Column({ + name: 'min_gap_hours', + unsigned: true, + nullable: true, + default: null, + }) + minGapHours: number | null + + @Column({ name: 'created_at', type: 'datetime', nullable: true, default: null }) + createdAt: Date | null + + @Column({ name: 'deleted_at', type: 'datetime', nullable: true, default: null }) + deletedAt: Date | null + + @Column({ length: 24, nullable: false, collation: 'utf8mb4_unicode_ci' }) + code: string + + @Column({ name: 'link_enabled', type: 'boolean', nullable: true, default: null }) + linkEnabled: boolean | null +} diff --git a/database/entity/ContributionLinks.ts b/database/entity/ContributionLinks.ts new file mode 100644 index 000000000..721dfd2b3 --- /dev/null +++ b/database/entity/ContributionLinks.ts @@ -0,0 +1 @@ +export { ContributionLinks } from './0038-add_contribution_links_table/ContributionLinks' From 2444c94af9f6d3869e65721317ffd58a29a408a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 1 Jun 2022 01:19:44 +0200 Subject: [PATCH 2/7] create migration and entity for new contribution_links table --- .../ContributionLinks.ts | 2 +- database/entity/ContributionLinks.ts | 2 +- .../0037-add_contribution_links_table.ts | 35 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) rename database/entity/{0038-add_contribution_links_table => 0037-add_contribution_links_table}/ContributionLinks.ts (97%) create mode 100644 database/migrations/0037-add_contribution_links_table.ts diff --git a/database/entity/0038-add_contribution_links_table/ContributionLinks.ts b/database/entity/0037-add_contribution_links_table/ContributionLinks.ts similarity index 97% rename from database/entity/0038-add_contribution_links_table/ContributionLinks.ts rename to database/entity/0037-add_contribution_links_table/ContributionLinks.ts index 5f78a7450..2fb4e2801 100644 --- a/database/entity/0038-add_contribution_links_table/ContributionLinks.ts +++ b/database/entity/0037-add_contribution_links_table/ContributionLinks.ts @@ -100,7 +100,7 @@ export class ContributionLinks extends BaseEntity { @Column({ name: 'deleted_at', type: 'datetime', nullable: true, default: null }) deletedAt: Date | null - @Column({ length: 24, nullable: false, collation: 'utf8mb4_unicode_ci' }) + @Column({ length: 24, nullable: true, collation: 'utf8mb4_unicode_ci' }) code: string @Column({ name: 'link_enabled', type: 'boolean', nullable: true, default: null }) diff --git a/database/entity/ContributionLinks.ts b/database/entity/ContributionLinks.ts index 721dfd2b3..de26c1c4a 100644 --- a/database/entity/ContributionLinks.ts +++ b/database/entity/ContributionLinks.ts @@ -1 +1 @@ -export { ContributionLinks } from './0038-add_contribution_links_table/ContributionLinks' +export { ContributionLinks } from './0037-add_contribution_links_table/ContributionLinks' diff --git a/database/migrations/0037-add_contribution_links_table.ts b/database/migrations/0037-add_contribution_links_table.ts new file mode 100644 index 000000000..79bcdf5ce --- /dev/null +++ b/database/migrations/0037-add_contribution_links_table.ts @@ -0,0 +1,35 @@ +/* MIGRATION TO ADD CONTRIBUTION_LINKS + * + * This migration adds the table `contribution_links` in order to store all sorts of contribution_links data + */ + +/* 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 IF NOT EXISTS \`contribution_links\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`name\` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, + \`decsription\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, + \`valid_from\` datetime NULL, + \`valid_to\` datetime NULL, + \`amount\` bigint(20) NOT NULL, + \`cycle\` int(10) unsigned NOT NULL DEFAULT '1', + \`max_per_cycle\` int(10) unsigned NOT NULL DEFAULT '1', + \`max_amount_per_month\` bigint(20) NULL DEFAULT NULL, + \`total_max_count_of_contribution\` int(10) unsigned NULL DEFAULT NULL, + \`max_account_balance\` bigint(20) NULL DEFAULT NULL, + \`min_gap_hours\` int(10) unsigned NULL DEFAULT NULL, + \`created_at\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + \`deleted_at\` datetime NULL DEFAULT NULL, + \`code\` varchar(24) COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL, + \`link_enabled\` tinyint(4) NOT NULL DEFAULT '0', + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + // write downgrade logic as parameter of queryFn + await queryFn(`DROP TABLE IF EXISTS \`contribution_links\`;`) +} From 74bcdaf8c4f11e3f2746c8d2f33e0b1bbd1d0a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 3 Jun 2022 00:06:14 +0200 Subject: [PATCH 3/7] add .project and correct .gitignore --- .gitignore | 2 -- .project | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .project diff --git a/.gitignore b/.gitignore index 08ccd2b30..6ac3a32c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -.dbeaver -.project *.log /node_modules/* messages.pot diff --git a/.project b/.project new file mode 100644 index 000000000..5d9663f32 --- /dev/null +++ b/.project @@ -0,0 +1,18 @@ + + + Gradido + + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.jkiss.dbeaver.DBeaverNature + org.eclipse.wst.jsdt.core.jsNature + + From bb35332e2ed6c0bf66b3cd4ec29b82a679c97db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Jun 2022 22:13:27 +0200 Subject: [PATCH 4/7] change Cycle Type in tabel ContributionLinks --- .dbeaver/.credentials-config.json.bak | 2 ++ .dbeaver/.data-sources.json.bak | 33 +++++++++++++++++++ .dbeaver/credentials-config.json | 3 ++ .dbeaver/data-sources.json | 32 ++++++++++++++++++ .../ContributionLinks.ts | 26 ++------------- .../0037-add_contribution_links_table.ts | 2 +- 6 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 .dbeaver/.credentials-config.json.bak create mode 100644 .dbeaver/.data-sources.json.bak create mode 100644 .dbeaver/credentials-config.json create mode 100644 .dbeaver/data-sources.json diff --git a/.dbeaver/.credentials-config.json.bak b/.dbeaver/.credentials-config.json.bak new file mode 100644 index 000000000..2eca1988d --- /dev/null +++ b/.dbeaver/.credentials-config.json.bak @@ -0,0 +1,2 @@ +'U[V$8%kQN, +`W-T3NvU{ɆHK~,DXpX.g/:?B9|GZn>/ \ No newline at end of file diff --git a/.dbeaver/.data-sources.json.bak b/.dbeaver/.data-sources.json.bak new file mode 100644 index 000000000..7d9528f01 --- /dev/null +++ b/.dbeaver/.data-sources.json.bak @@ -0,0 +1,33 @@ +{ + "folders": {}, + "connections": { + "mariaDB-1813fbbc7bc-107c0b3aeaeb91ab": { + "provider": "mysql", + "driver": "mariaDB", + "name": "gradido", + "save-password": true, + "read-only": false, + "configuration": { + "host": "localhost", + "port": "3306", + "database": "gradido", + "url": "jdbc:mariadb://localhost:3306/gradido", + "home": "mysql_client", + "type": "dev", + "auth-model": "native", + "handlers": {} + } + } + }, + "connection-types": { + "dev": { + "name": "Development", + "color": "255,255,255", + "description": "Regular development database", + "auto-commit": true, + "confirm-execute": false, + "confirm-data-change": false, + "auto-close-transactions": false + } + } +} \ No newline at end of file diff --git a/.dbeaver/credentials-config.json b/.dbeaver/credentials-config.json new file mode 100644 index 000000000..d814bdfcf --- /dev/null +++ b/.dbeaver/credentials-config.json @@ -0,0 +1,3 @@ +4k1,fbAqĬc##s8-1&;"7djM?bljfBq= +my +vV \ No newline at end of file diff --git a/.dbeaver/data-sources.json b/.dbeaver/data-sources.json new file mode 100644 index 000000000..096f0d57e --- /dev/null +++ b/.dbeaver/data-sources.json @@ -0,0 +1,32 @@ +{ + "folders": {}, + "connections": { + "mariaDB-1813fbbc7bc-107c0b3aeaeb91ab": { + "provider": "mysql", + "driver": "mariaDB", + "name": "gradido", + "save-password": true, + "read-only": false, + "configuration": { + "host": "localhost", + "port": "3306", + "url": "jdbc:mariadb://localhost:3306/", + "home": "mysql_client", + "type": "dev", + "auth-model": "native", + "handlers": {} + } + } + }, + "connection-types": { + "dev": { + "name": "Development", + "color": "255,255,255", + "description": "Regular development database", + "auto-commit": true, + "confirm-execute": false, + "confirm-data-change": false, + "auto-close-transactions": false + } + } +} \ No newline at end of file diff --git a/database/entity/0037-add_contribution_links_table/ContributionLinks.ts b/database/entity/0037-add_contribution_links_table/ContributionLinks.ts index 2fb4e2801..0626a5067 100644 --- a/database/entity/0037-add_contribution_links_table/ContributionLinks.ts +++ b/database/entity/0037-add_contribution_links_table/ContributionLinks.ts @@ -2,28 +2,6 @@ import Decimal from 'decimal.js-light' import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm' import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' -export enum CycleTypes { - ONCE = 1, - HOUR = 2, - TWOHOURS = 3, - FOURHOURS = 4, - EIGHTHOURS = 5, - HALFDAY = 6, - DAY = 7, - TWODAYS = 8, - THREEDAYS = 9, - FOURDAYS = 10, - FIVEDAYS = 11, - SIXDAYS = 12, - WEEK = 13, - TWOWEEKS = 14, - MONTH = 15, - TWOMONTH = 16, - QUARTER = 17, - HALFYEAR = 18, - YEAR = 19, -} - @Entity('contribution_links') export class ContributionLinks extends BaseEntity { @PrimaryGeneratedColumn('increment', { unsigned: true }) @@ -50,8 +28,8 @@ export class ContributionLinks extends BaseEntity { }) amount: Decimal - @Column({ name: 'cycle', unsigned: true, nullable: false }) - cycle: number + @Column({ length: 12, nullable: false, collation: 'utf8mb4_unicode_ci' }) + cycle: string @Column({ name: 'max_per_cycle', unsigned: true, nullable: false, default: 1 }) maxPerCycle: number diff --git a/database/migrations/0037-add_contribution_links_table.ts b/database/migrations/0037-add_contribution_links_table.ts index 79bcdf5ce..42f03184b 100644 --- a/database/migrations/0037-add_contribution_links_table.ts +++ b/database/migrations/0037-add_contribution_links_table.ts @@ -15,7 +15,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis \`valid_from\` datetime NULL, \`valid_to\` datetime NULL, \`amount\` bigint(20) NOT NULL, - \`cycle\` int(10) unsigned NOT NULL DEFAULT '1', + \`cycle\` varchar(12) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'NONE', \`max_per_cycle\` int(10) unsigned NOT NULL DEFAULT '1', \`max_amount_per_month\` bigint(20) NULL DEFAULT NULL, \`total_max_count_of_contribution\` int(10) unsigned NULL DEFAULT NULL, From 698f13078e73472186f15651094674e3fef4ff58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Jun 2022 22:14:02 +0200 Subject: [PATCH 5/7] define enum for ContributionLinks cycles --- .../src/graphql/enum/ContributionCycleType.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 backend/src/graphql/enum/ContributionCycleType.ts diff --git a/backend/src/graphql/enum/ContributionCycleType.ts b/backend/src/graphql/enum/ContributionCycleType.ts new file mode 100644 index 000000000..05084a669 --- /dev/null +++ b/backend/src/graphql/enum/ContributionCycleType.ts @@ -0,0 +1,29 @@ +import { registerEnumType } from 'type-graphql' + +export enum ContributionCycleType { + NONE = 'none', + ONCE = 'once', + HOUR = 'hour', + TWO_HOURS = 'two_hours', + FOUR_HOURS = 'four_hours', + EIGHT_HOURS = 'eight_hours', + HALF_DAY = 'half_day', + DAY = 'day', + TWO_DAYS = 'two_days', + THREE_DAYS = 'three_days', + FOUR_DAYS = 'four_days', + FIVE_DAYS = 'five_days', + SIX_DAYS = 'six_days', + WEEK = 'week', + TWO_WEEKS = 'two_weeks', + MONTH = 'month', + TWO_MONTH = 'two_month', + QUARTER = 'quarter', + HALF_YEAR = 'half_year', + YEAR = 'year', +} + +registerEnumType(ContributionCycleType, { + name: 'ContributionCycleType', // this one is mandatory + description: 'Name of the Type of the ContributionCycle', // this one is optional +}) From e71725686c03c2e459081ef90ecd90db5205ffb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Jun 2022 22:21:40 +0200 Subject: [PATCH 6/7] change backend config for db-version 0037 --- backend/src/config/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 28318ed6b..ec469c183 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -10,7 +10,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0036-unique_previous_in_transactions', + DB_VERSION: '0037-add_contribution_links_table/ContributionLinks', 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 From a881103c5f70f0e67c394e447436085808309f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Jun 2022 22:52:08 +0200 Subject: [PATCH 7/7] add softdelete feature to contributionlinks --- .../0037-add_contribution_links_table/ContributionLinks.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/entity/0037-add_contribution_links_table/ContributionLinks.ts b/database/entity/0037-add_contribution_links_table/ContributionLinks.ts index 0626a5067..6539716c6 100644 --- a/database/entity/0037-add_contribution_links_table/ContributionLinks.ts +++ b/database/entity/0037-add_contribution_links_table/ContributionLinks.ts @@ -1,5 +1,5 @@ import Decimal from 'decimal.js-light' -import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm' +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, DeleteDateColumn } from 'typeorm' import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' @Entity('contribution_links') @@ -75,7 +75,7 @@ export class ContributionLinks extends BaseEntity { @Column({ name: 'created_at', type: 'datetime', nullable: true, default: null }) createdAt: Date | null - @Column({ name: 'deleted_at', type: 'datetime', nullable: true, default: null }) + @DeleteDateColumn() deletedAt: Date | null @Column({ length: 24, nullable: true, collation: 'utf8mb4_unicode_ci' })