-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from johanbook/blog-migrations
Add migration for blogs posts
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
services/api/src/core/database/infrastructure/migrations/1681138092600-SetupTypeorm.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> {} | ||
} |
18 changes: 18 additions & 0 deletions
18
services/api/src/features/blogs/infrastructure/migrations/1691523079628-AddBlogPost.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"`); | ||
} | ||
|
||
} |