make type nullable
This commit is contained in:
parent
b8039917d0
commit
e6e3ab0374
@ -24,6 +24,6 @@ export class PushSubscription extends BaseClass {
|
|||||||
@Column({ type: "varchar", nullable: true })
|
@Column({ type: "varchar", nullable: true })
|
||||||
p256dh?: string;
|
p256dh?: string;
|
||||||
|
|
||||||
@Column({ type: "varchar", nullable: false })
|
@Column({ type: "varchar", nullable: true })
|
||||||
type: "webpush" | "basic" = "webpush";
|
type: "webpush" | "basic" = "webpush";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,69 +1,49 @@
|
|||||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
export class MakeKeysNullable1766283926503 implements MigrationInterface {
|
export class MakeKeysNullable1766283926503 implements MigrationInterface {
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(`
|
|
||||||
CREATE TABLE "temporary_push_subscriptions" (
|
|
||||||
"id" varchar PRIMARY KEY NOT NULL,
|
|
||||||
"user_id" varchar,
|
|
||||||
"endpoint" varchar NOT NULL,
|
|
||||||
"expiration_time" bigint,
|
|
||||||
"auth" varchar,
|
|
||||||
"p256dh" varchar,
|
|
||||||
"type" text NOT NULL DEFAULT 'webpush',
|
|
||||||
CONSTRAINT "UQ_push_subscriptions_endpoint" UNIQUE ("endpoint"),
|
|
||||||
CONSTRAINT "FK_push_subscriptions_user"
|
|
||||||
FOREIGN KEY ("user_id") REFERENCES "users"("id")
|
|
||||||
ON DELETE SET NULL ON UPDATE NO ACTION
|
|
||||||
)
|
|
||||||
`);
|
|
||||||
|
|
||||||
await queryRunner.query(`
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
INSERT INTO "temporary_push_subscriptions"("id", "user_id", "endpoint", "expiration_time", "auth", "p256dh", "type")
|
await queryRunner.query(`
|
||||||
SELECT "id", "user_id", "endpoint", "expiration_time", "auth", "p256dh", 'webpush'
|
ALTER TABLE "push_subscriptions"
|
||||||
FROM "push_subscriptions"
|
ALTER COLUMN "auth" DROP NOT NULL;
|
||||||
`);
|
`);
|
||||||
|
|
||||||
await queryRunner.query(`DROP TABLE "push_subscriptions"`);
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "push_subscriptions"
|
||||||
|
ALTER COLUMN "p256dh" DROP NOT NULL;
|
||||||
|
`);
|
||||||
|
|
||||||
await queryRunner.query(`ALTER TABLE "temporary_push_subscriptions" RENAME TO "push_subscriptions"`);
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "push_subscriptions"
|
||||||
|
ADD COLUMN "type" text;
|
||||||
|
`);
|
||||||
|
|
||||||
await queryRunner.query(`
|
await queryRunner.query(`
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS "idx_push_subscriptions_endpoint"
|
UPDATE "push_subscriptions"
|
||||||
ON "push_subscriptions" ("endpoint")
|
SET "type" = 'webpush'
|
||||||
`);
|
WHERE "type" IS NULL;
|
||||||
}
|
`);
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
await queryRunner.query(`
|
||||||
await queryRunner.query(`
|
ALTER TABLE "push_subscriptions"
|
||||||
CREATE TABLE "temporary_push_subscriptions" (
|
ALTER COLUMN "type" SET NOT NULL;
|
||||||
"id" varchar PRIMARY KEY NOT NULL,
|
`);
|
||||||
"user_id" varchar,
|
}
|
||||||
"endpoint" varchar NOT NULL,
|
|
||||||
"expiration_time" bigint,
|
|
||||||
"auth" varchar NOT NULL,
|
|
||||||
"p256dh" varchar NOT NULL,
|
|
||||||
CONSTRAINT "UQ_push_subscriptions_endpoint" UNIQUE ("endpoint"),
|
|
||||||
CONSTRAINT "FK_push_subscriptions_user"
|
|
||||||
FOREIGN KEY ("user_id") REFERENCES "users"("id")
|
|
||||||
ON DELETE SET NULL ON UPDATE NO ACTION
|
|
||||||
)
|
|
||||||
`);
|
|
||||||
|
|
||||||
await queryRunner.query(`
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
INSERT INTO "temporary_push_subscriptions"("id", "user_id", "endpoint", "expiration_time", "auth", "p256dh")
|
await queryRunner.query(`
|
||||||
SELECT "id", "user_id", "endpoint", "expiration_time", "auth", "p256dh"
|
ALTER TABLE "push_subscriptions"
|
||||||
FROM "push_subscriptions"
|
DROP COLUMN "type";
|
||||||
WHERE "auth" IS NOT NULL AND "p256dh" IS NOT NULL
|
`);
|
||||||
`);
|
|
||||||
|
|
||||||
await queryRunner.query(`DROP TABLE "push_subscriptions"`);
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "push_subscriptions"
|
||||||
|
ALTER COLUMN "auth" SET NOT NULL;
|
||||||
|
`);
|
||||||
|
|
||||||
await queryRunner.query(`ALTER TABLE "temporary_push_subscriptions" RENAME TO "push_subscriptions"`);
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "push_subscriptions"
|
||||||
await queryRunner.query(`
|
ALTER COLUMN "p256dh" SET NOT NULL;
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS "idx_push_subscriptions_endpoint"
|
`);
|
||||||
ON "push_subscriptions" ("endpoint")
|
}
|
||||||
`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user