Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration:generate issue with onUpdate using mariadb 10.4 #6714

Merged
merged 5 commits into from Sep 17, 2020

Commits on Sep 14, 2020

  1. 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;
    }
    ```
    jesussegado committed Sep 14, 2020
    Copy the full SHA
    c2a2e6f View commit details
    Browse the repository at this point in the history

Commits on Sep 16, 2020

  1. Copy the full SHA
    e8ddcec View commit details
    Browse the repository at this point in the history
  2. add test to issue 6714

    jesusegado committed Sep 16, 2020
    Copy the full SHA
    48da377 View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    2520bed View commit details
    Browse the repository at this point in the history
  4. Update issue-6714.ts

    jesussegado committed Sep 16, 2020
    Copy the full SHA
    eda54aa View commit details
    Browse the repository at this point in the history