create migration and entity for new contribution_links table

This commit is contained in:
Claus-Peter Hübner 2022-06-01 01:19:44 +02:00
parent 84c0c6f10b
commit 2444c94af9
3 changed files with 37 additions and 2 deletions

View File

@ -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 })

View File

@ -1 +1 @@
export { ContributionLinks } from './0038-add_contribution_links_table/ContributionLinks'
export { ContributionLinks } from './0037-add_contribution_links_table/ContributionLinks'

View File

@ -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<Array<any>>) {
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<Array<any>>) {
// write downgrade logic as parameter of queryFn
await queryFn(`DROP TABLE IF EXISTS \`contribution_links\`;`)
}