migrate database to accept null on all parseInt fields on elopageBuys

This commit is contained in:
Ulf Gebhardt 2022-02-13 12:40:37 +01:00
parent c4942799b8
commit 65f76f82ed
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
3 changed files with 28 additions and 3 deletions

View File

@ -5,8 +5,8 @@ export class LoginElopageBuys extends BaseEntity {
@PrimaryGeneratedColumn('increment', { unsigned: true }) @PrimaryGeneratedColumn('increment', { unsigned: true })
id: number id: number
@Column({ name: 'elopage_user_id', nullable: false }) @Column({ type: 'int', width: 11, name: 'elopage_user_id', nullable: true, default: null })
elopageUserId: number elopageUserId: number | null
@Column({ name: 'affiliate_program_id', nullable: false }) @Column({ name: 'affiliate_program_id', nullable: false })
affiliateProgramId: number affiliateProgramId: number

View File

@ -1 +1 @@
export { LoginElopageBuys } from './0003-login_server_tables/LoginElopageBuys' export { LoginElopageBuys } from './0021-elopagebuys_fields_nullable/LoginElopageBuys'

View File

@ -0,0 +1,25 @@
/* MIGRATION TO ALLOW NULL FIELDS ON ELOPAGEBUYS
*
* This migration allows null on `affiliate_program_id`,
* `publisher_id`, `order_id`. `product_id`.
*/
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(
'ALTER TABLE `login_elopage_buys` MODIFY COLUMN `affiliate_program_id` int(11) DEFAULT NULL;',
)
await queryFn(
'ALTER TABLE `login_elopage_buys` MODIFY COLUMN `publisher_id` int(11) DEFAULT NULL;',
)
await queryFn('ALTER TABLE `login_elopage_buys` MODIFY COLUMN `order_id` int(11) DEFAULT NULL;')
await queryFn('ALTER TABLE `login_elopage_buys` MODIFY COLUMN `product_id` int(11) DEFAULT NULL;')
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(
'ALTER TABLE `login_elopage_buys` MODIFY COLUMN `affiliate_program_id` int(11) NOT NULL;',
)
await queryFn('ALTER TABLE `login_elopage_buys` MODIFY COLUMN `publisher_id` int(11) NOT NULL;')
await queryFn('ALTER TABLE `login_elopage_buys` MODIFY COLUMN `order_id` int(11) NOT NULL;')
await queryFn('ALTER TABLE `login_elopage_buys` MODIFY COLUMN `product_id` int(11) NOT NULL;')
}