Skip to content

Commit

Permalink
Merge pull request #238 from johanbook/blog-migrations
Browse files Browse the repository at this point in the history
Add migration for blogs posts
  • Loading branch information
johanbook authored Aug 8, 2023
2 parents 1859765 + 64e4c3f commit 4d88091
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";

// See https://github.com/typeorm/typeorm/issues/4923#issuecomment-629135120
export class SetupTypeorm1681018318437 implements MigrationInterface {
name = "SetupTypeorm1681018318437";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE IF NOT EXISTS typeorm_metadata (
"type" varchar(255) NOT NULL,
"database" varchar(255) DEFAULT NULL,
"schema" varchar(255) DEFAULT NULL,
"table" varchar(255) DEFAULT NULL,
"name" varchar(255) DEFAULT NULL,
"value" text
)`);
}

public async down(queryRunner: QueryRunner): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class AddBlogPost1691523079628 implements MigrationInterface {
name = 'AddBlogPost1691523079628'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "blog_post" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "content" character varying(2048) NOT NULL DEFAULT '', "organizationId" integer NOT NULL, "profileId" integer NOT NULL, CONSTRAINT "PK_694e842ad1c2b33f5939de6fede" PRIMARY KEY ("id"))`);
await queryRunner.query(`ALTER TABLE "blog_post" ADD CONSTRAINT "FK_5e268dc00df2ba14bfb0381dc99" FOREIGN KEY ("organizationId") REFERENCES "organization"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "blog_post" ADD CONSTRAINT "FK_5fc410996103f64f5d16c423918" FOREIGN KEY ("profileId") REFERENCES "profile"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "blog_post" DROP CONSTRAINT "FK_5fc410996103f64f5d16c423918"`);
await queryRunner.query(`ALTER TABLE "blog_post" DROP CONSTRAINT "FK_5e268dc00df2ba14bfb0381dc99"`);
await queryRunner.query(`DROP TABLE "blog_post"`);
}

}

0 comments on commit 4d88091

Please sign in to comment.