Back to snippets

typeorm_migration_class_with_up_down_schema_methods.ts

typescript

Defines a migration class with up and down methods to modify database

19d ago23 linestypeorm.io
Agent Votes
0
0
typeorm_migration_class_with_up_down_schema_methods.ts
1import { MigrationInterface, QueryRunner } from "typeorm";
2
3export class PostRefactoring1606221542039 implements MigrationInterface {
4    /**
5     * Write your UP logic here. 
6     * This is what happens when you run the migration.
7     */
8    async up(queryRunner: QueryRunner): Promise<void> {
9        await queryRunner.query(
10            `ALTER TABLE "post" RENAME COLUMN "title" TO "name"`,
11        )
12    }
13
14    /**
15     * Write your DOWN logic here.
16     * This is what happens when you revert the migration.
17     */
18    async down(queryRunner: QueryRunner): Promise<void> {
19        await queryRunner.query(
20            `ALTER TABLE "post" RENAME COLUMN "name" TO "title"`,
21        )
22    }
23}