-
-
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 #3046 from owid/assing-type-to-all-gdoc-documents
🐛 fix missing type field in some posts_gdocs rows
- Loading branch information
Showing
1 changed file
with
22 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,22 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm" | ||
|
||
export class FixGdocPostsWithoutType1703777475319 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
// This migration makes sure that all posts_gdocs have the type field | ||
// set in the content JSON blob. 'article' is not necessarily correct | ||
// but the next time this article is opened it will be updated to the | ||
// actual type in the gdoc. Because of the current code being too strict, | ||
// the same does not happen when opening a gdoc in the admin if the type | ||
// is missing, so this is a next-best workaround. | ||
await queryRunner.query(`-- sql | ||
update posts_gdocs | ||
set content = json_insert(content, '$.type', 'article') | ||
where content->>'$.type' is null;`) | ||
} | ||
|
||
public async down(_queryRunner: QueryRunner): Promise<void> { | ||
return | ||
} | ||
} |