diff --git a/db/model/Gdoc/GdocBase.ts b/db/model/Gdoc/GdocBase.ts index c754e627155..99759a3941e 100644 --- a/db/model/Gdoc/GdocBase.ts +++ b/db/model/Gdoc/GdocBase.ts @@ -65,45 +65,19 @@ import { getVariableOfDatapageIfApplicable, } from "../Variable.js" -@Entity("tags") -export class Tag extends BaseEntity implements TagInterface { - static table = "tags" - @PrimaryColumn() id!: number - @Column() name!: string - @Column() createdAt!: Date - @Column({ nullable: true }) updatedAt!: Date - @Column({ nullable: true }) parentId!: number - @Column() isBulkImport!: boolean - @Column({ type: "varchar", nullable: true }) slug!: string | null - @Column() specialType!: string - @ManyToMany(() => GdocBase, (gdoc) => gdoc.tags) - gdocs!: GdocBase[] -} - -@Entity("posts_gdocs") -export class GdocBase extends BaseEntity implements OwidGdocBaseInterface { - @PrimaryColumn() id!: string - @Column() slug: string = "" - @Column({ default: "{}", type: "json" }) content!: Record - @Column() published: boolean = false - @Column() createdAt: Date = new Date() - @Column({ type: Date, nullable: true }) publishedAt: Date | null = null - @UpdateDateColumn({ nullable: true }) updatedAt: Date | null = null - @Column({ type: String, nullable: true }) revisionId: string | null = null - @Column({ type: String, nullable: true }) markdown: string | null = null - @Column() publicationContext: OwidGdocPublicationContext = +export class GdocBase implements OwidGdocBaseInterface { + id: string + slug: string = "" + content!: Record + published: boolean = false + createdAt: Date = new Date() + publishedAt: Date | null = null + updatedAt: Date | null = null + revisionId: string | null = null + markdown: string | null = null + publicationContext: OwidGdocPublicationContext = OwidGdocPublicationContext.unlisted - @Column({ type: "json", nullable: true }) breadcrumbs: - | BreadcrumbItem[] - | null = null - @ManyToMany(() => Tag, { cascade: true }) - @JoinTable({ - name: "posts_gdocs_x_tags", - joinColumn: { name: "gdocId", referencedColumnName: "id" }, - inverseJoinColumn: { name: "tagId", referencedColumnName: "id" }, - }) - tags!: Tag[] - + breadcrumbs: BreadcrumbItem[] | null = null errors: OwidGdocErrorMessage[] = [] imageMetadata: Record = {} linkedCharts: Record = {} @@ -123,7 +97,6 @@ export class GdocBase extends BaseEntity implements OwidGdocBaseInterface { _loadSubclassAttachments: () => Promise = async () => undefined constructor(id?: string) { - super() if (id) { this.id = id } @@ -139,8 +112,6 @@ export class GdocBase extends BaseEntity implements OwidGdocBaseInterface { return enrichedBlockSources } - @BeforeUpdate() - @BeforeInsert() updateMarkdown(): void { try { this.markdown = diff --git a/db/model/Gdoc/GdocDataInsight.ts b/db/model/Gdoc/GdocDataInsight.ts index 96563dd7b3d..21036b8a266 100644 --- a/db/model/Gdoc/GdocDataInsight.ts +++ b/db/model/Gdoc/GdocDataInsight.ts @@ -12,12 +12,10 @@ import { import { GdocBase } from "./GdocBase.js" import * as db from "../../../db/db.js" -@Entity("posts_gdocs") export class GdocDataInsight extends GdocBase implements OwidGdocDataInsightInterface { - @Column({ default: "{}", type: "json" }) content!: OwidGdocDataInsightContent constructor(id?: string) { diff --git a/db/model/Gdoc/GdocFaq.ts b/db/model/Gdoc/GdocFaq.ts index dec1800af41..a1c7d0f3bce 100644 --- a/db/model/Gdoc/GdocFaq.ts +++ b/db/model/Gdoc/GdocFaq.ts @@ -21,10 +21,9 @@ interface InterfaceGdocFaq { * instead of using the same endpoint for both posts and faqs. * For now, we'll just use the GdocPost class. */ -@Entity("posts_gdocs") export class GdocFaq extends GdocBase { static table = "posts_gdocs" - @Column({ default: "{}", type: "json" }) content!: InterfaceGdocFaq + content!: InterfaceGdocFaq constructor(id?: string) { super() diff --git a/db/model/Gdoc/GdocHomepage.ts b/db/model/Gdoc/GdocHomepage.ts index 165ef32bafa..c501ecec304 100644 --- a/db/model/Gdoc/GdocHomepage.ts +++ b/db/model/Gdoc/GdocHomepage.ts @@ -12,12 +12,10 @@ import * as db from "../../db.js" import { OwidGdocHomepageMetadata } from "@ourworldindata/types" import { UNIQUE_TOPIC_COUNT } from "../../../site/SiteNavigation.js" -@Entity("posts_gdocs") export class GdocHomepage extends GdocBase implements OwidGdocHomepageInterface { - @Column({ default: "{}", type: "json" }) content!: OwidGdocHomepageContent constructor(id?: string) { diff --git a/db/model/Gdoc/GdocPost.ts b/db/model/Gdoc/GdocPost.ts index d48172bea96..61fed698387 100644 --- a/db/model/Gdoc/GdocPost.ts +++ b/db/model/Gdoc/GdocPost.ts @@ -25,9 +25,8 @@ import { htmlToEnrichedTextBlock } from "./htmlToEnriched.js" import { GdocBase } from "./GdocBase.js" import { getConnection } from "../../db.js" -@Entity("posts_gdocs") export class GdocPost extends GdocBase implements OwidGdocPostInterface { - @Column({ default: "{}", type: "json" }) content!: OwidGdocPostContent + content!: OwidGdocPostContent constructor(id?: string) { super(id)