Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new translation column to Post #2584

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __tests__/workers/__snapshots__/postUpdated.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Object {
"title": "Title",
"titleHtml": null,
"toc": null,
"translation": Object {},
"trending": null,
"type": "article",
"upvotes": 0,
Expand Down
8 changes: 8 additions & 0 deletions src/entity/posts/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { PostKeyword } from '../PostKeyword';
import { User } from '../user';
import { PostRelation } from './PostRelation';
import type { PostCodeSnippet } from './PostCodeSnippet';
import type { I18nRecord } from '../../types';

export enum PostType {
Article = 'article',
Expand Down Expand Up @@ -52,6 +53,10 @@ export type PostContentQuality = Partial<{
manual_clickbait_probability: number;
}>;

export type PostTranslation = Partial<{
title: I18nRecord;
}>;

@Entity()
@Index('IDX_post_id_sourceid', ['id', 'sourceId'])
@Index('IDX_post_deleted_visible_type_views', [
Expand Down Expand Up @@ -266,6 +271,9 @@ export class Post {
@Column({ type: 'jsonb', default: {} })
contentQuality: PostContentQuality;

@Column({ type: 'jsonb', default: {} })
translation: PostTranslation;

@OneToMany(
'PostCodeSnippet',
(postCodeSnippet: PostCodeSnippet) => postCodeSnippet.post,
Expand Down
13 changes: 13 additions & 0 deletions src/migration/1736519518183-PostTranslations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class PostTranslations1736519518183 implements MigrationInterface {
name = 'PostTranslations1736519518183'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "post" ADD "translation" jsonb NOT NULL DEFAULT '{}'`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "post" DROP COLUMN "translation"`);
}
}
Loading