Skip to content

Commit

Permalink
Merge pull request #3046 from owid/assing-type-to-all-gdoc-documents
Browse files Browse the repository at this point in the history
🐛 fix missing type field in some posts_gdocs rows
  • Loading branch information
danyx23 authored Dec 28, 2023
2 parents 8334052 + 3bd1d7b commit 8a99b1e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions db/migration/1703777475319-FixGdocPostsWithoutType.ts
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
}
}

0 comments on commit 8a99b1e

Please sign in to comment.