Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix: migration:generate issue with onUpdate using mariadb 10.4 (#6714)
* Update MysqlQueryRunner.ts In Mariadb the extra information of a DDL is in upper case and in javascript String.indexOf() function is case sensitive, because of that when you generate a new migrations in mariadb it always create a line to update "onUpdate" lines. example: ```sql CREATE TABLE `test` ( `test_id` int(11) NOT NULL AUTO_INCREMENT, `test_update` timestamp() NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`test_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ``` When you try to generate a new migration always create the next migration file: ```ts import { MigrationInterface, QueryRunner } from 'typeorm'; export class test261600082802966 implements MigrationInterface { name = 'test261600082802966'; public async up(queryRunner: QueryRunner): Promise<void> { await queryRunner.query( 'ALTER TABLE `test` CHANGE `test_update` `test_update` timestamp() NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP()' ); } public async down(queryRunner: QueryRunner): Promise<void> { await queryRunner.query( 'ALTER TABLE `test` CHANGE `test_update` `test_update` timestamp() NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE current_timestamp()' ); } } ``` Entity file test.ts ```ts import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; @entity() export class test extends BaseEntity { @PrimaryGeneratedColumn({}) test_id: number; @column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP()', onUpdate: 'CURRENT_TIMESTAMP()', nullable: false, }) test_update: Date; } ``` * Update MysqlQueryRunner.ts * add test to issue 6714 * Update MysqlQueryRunner.ts * Update issue-6714.ts Co-authored-by: jesusegado <j.fernandez@lionline.de>
- Loading branch information