typeorm#MigrationInterface TypeScript Examples

The following examples show how to use typeorm#MigrationInterface. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: 1614784355565-MCA2020seeding.ts    From Corsace with MIT License 6 votes vote down vote up
export class MCA2020seeding1614784355565 implements MigrationInterface {

    public async up (queryRunner: QueryRunner): Promise<void> {
        const bigSql = await streamToString(createReadStream(resolve(__dirname, "1614784355565-MCA2020seeding.sql.gz")).pipe(createGunzip()));
        const sqlInstructions = bigSql.split("\n").filter(sql => sql.trim().length !== 0);
        for(const sqlInstruction of sqlInstructions)
            if(sqlInstruction.trim().length !== 0)
                await queryRunner.query(sqlInstruction);
    }

    public async down (queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query("TRUNCATE username_change;");
        await queryRunner.query("TRUNCATE mca_eligibility;");
        await queryRunner.query("TRUNCATE beatmap;");
        await queryRunner.query("TRUNCATE beatmapset;");
        await queryRunner.query("TRUNCATE user;");
        await queryRunner.query("TRUNCATE mode_division;");
    }

}
Example #2
Source File: 1586818064869-AddAvatarFieldToUsers.ts    From gobarber-api with MIT License 6 votes vote down vote up
export default class AddAvatarFieldToUsers1586818064869
  implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.addColumn(
      'users',
      new TableColumn({
        name: 'avatar',
        type: 'varchar',
        isNullable: true,
      }),
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropColumn('users', 'avatar');
  }
}
Example #3
Source File: 1602355203224-create_images.ts    From happy with MIT License 6 votes vote down vote up
export class createImages1602355203224 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.createTable(new Table({
      name: 'images',
      columns: [
        {
          name: 'id',
          type: 'integer',
          unsigned: true,
          isPrimary: true,
          isGenerated: true,
          generationStrategy: 'increment',
        },
        {
          name: 'path',
          type: 'varchar',
        },
        {
          name: 'orphanage_id',
          type: 'integer',
        },
      ],
      foreignKeys: [
        {
          name: 'ImageOrphanage',
          columnNames: ['orphanage_id'],
          referencedTableName: 'orphanages',
          referencedColumnNames: ['id'],
          onUpdate: 'CASCADE',
          onDelete: 'CASCADE',
        }
      ],
    }))
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropTable('images');
  }
}
Example #4
Source File: 1586825793555-CreateCategories.ts    From rocketseat-gostack-11-desafios with MIT License 6 votes vote down vote up
export default class CreateCategories1586825793555
  implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.createTable(
      new Table({
        name: 'categories',
        columns: [
          {
            name: 'id',
            type: 'uuid',
            isPrimary: true,
            generationStrategy: 'uuid',
            default: 'uuid_generate_v4()',
          },
          {
            name: 'title',
            type: 'varchar',
          },
          {
            name: 'created_at',
            type: 'timestamp',
            default: 'now()',
          },
          {
            name: 'updated_at',
            type: 'timestamp',
            default: 'now()',
          },
        ],
      }),
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropTable('categories');
  }
}
Example #5
Source File: 1605314140309-user.ts    From nestjs-api-example with MIT License 6 votes vote down vote up
export class createUser1605314140309 implements MigrationInterface {
  name = 'createUser1605314140309';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      'CREATE TABLE `user` (`id` int NOT NULL AUTO_INCREMENT, `firstName` varchar(50) NOT NULL, `lastName` varchar(50) NOT NULL, `isActive` tinyint NOT NULL DEFAULT 1, PRIMARY KEY (`id`)) ENGINE=InnoDB',
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query('DROP TABLE `user`');
  }
}
Example #6
Source File: 1589508329414-Appointment.ts    From hotseat-api with MIT License 6 votes vote down vote up
export default class Appointment1589508329414 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.createTable(
      new Table({
        name: 'appointments',
        columns: [
          {
            name: 'id',
            type: 'varchar',
            generationStrategy: 'uuid',
            default: 'uuid_generate_v4()',
            isPrimary: true,
          },
          {
            name: 'provider',
            type: 'varchar',
            isNullable: false,
          },
          {
            name: 'date',
            type: 'timestamp with time zone',
            isNullable: false,
          },
        ],
      }),
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropTable('appointments');
  }
}
Example #7
Source File: 1561306152476-Projects.ts    From barista with Apache License 2.0 6 votes vote down vote up
export class Projects1561306152476 implements MigrationInterface {
  connection = getConnection('demo-seed');

  public async down(queryRunner: QueryRunner): Promise<any> {
    await this.connection.getRepository(Project).delete({});
  }

  public async up(queryRunner: QueryRunner): Promise<any> {
    await this.connection.getRepository(Project).save(ProjectSeed);
  }
}