-
-
Notifications
You must be signed in to change notification settings - Fork 229
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 #4274 from owid/cloudflare-images-prep
🎉 cloudflare images DB setup
- Loading branch information
Showing
4 changed files
with
525 additions
and
0 deletions.
There are no files selected for viewing
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,39 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm" | ||
|
||
export class CloudflareImages1731360326761 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`-- sql | ||
ALTER TABLE images | ||
ADD COLUMN cloudflareId CHAR(36) NULL, | ||
ADD CONSTRAINT images_cloudflareId_unique UNIQUE (cloudflareId), | ||
ADD COLUMN hash VARCHAR(255) NULL, | ||
MODIFY COLUMN googleId VARCHAR(255) NULL, | ||
MODIFY COLUMN defaultAlt VARCHAR(1600) NULL;`) | ||
|
||
// One-way migration 👋 | ||
await queryRunner.query(`-- sql | ||
UPDATE images | ||
SET defaultAlt = NULL | ||
WHERE defaultAlt = 'legacy-wordpress-upload'; | ||
`) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`-- sql | ||
ALTER TABLE images | ||
DROP COLUMN cloudflareId, | ||
DROP COLUMN hash | ||
`) | ||
|
||
await queryRunner.query(`-- sql | ||
UPDATE images | ||
SET googleId = 'cloudflare_image' | ||
WHERE googleId IS NULL | ||
`) | ||
|
||
await queryRunner.query(`-- sql | ||
ALTER TABLE images | ||
MODIFY COLUMN googleId VARCHAR(255) NOT NULL | ||
`) | ||
} | ||
} |
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,23 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm" | ||
|
||
export class CloudflareImagesAddUserId1732994843041 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`-- sql | ||
ALTER TABLE images | ||
ADD COLUMN userId INTEGER, | ||
ADD CONSTRAINT fk_user_images | ||
FOREIGN KEY (userId) REFERENCES users(id) | ||
ON DELETE SET NULL; | ||
`) | ||
} | ||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`-- sql | ||
ALTER TABLE images DROP CONSTRAINT fk_user_images; | ||
`) | ||
await queryRunner.query(`-- sql | ||
ALTER TABLE images DROP COLUMN userId; | ||
`) | ||
} | ||
} |
Oops, something went wrong.