Migrations: queryrunner instead sql statements using TypeORM

Viewed 193

Can I generate a migration file with objects from my Entities? Just like:

export class CreateUsers1613877849611 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.createTable(
      new Table({
        name: 'users',
        columns: [
          {
            name: 'id',
            type: 'int',
            isPrimary: true,
          },

Instead:

await queryRunner.query("CREATE TABLE `users` (`id` int NOT NULL AUTO_INCREMENT, `isDeleted` tinyint NULL DEFAULT 0, `createdAt` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updatedAt` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `name` varchar(255) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB");
0 Answers
Related