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

Migration to limit body length to 2000 #9667

Merged
merged 10 commits into from
Dec 5, 2024
10 changes: 8 additions & 2 deletions libs/model/src/models/comment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { stats } from '@hicommonwealth/core';
import { Comment } from '@hicommonwealth/schemas';
import { getDecodedString } from '@hicommonwealth/shared';
import {
getDecodedString,
MAX_TRUNCATED_CONTENT_LENGTH,
} from '@hicommonwealth/shared';
import Sequelize from 'sequelize';
import { z } from 'zod';
import type {
Expand Down Expand Up @@ -37,7 +40,10 @@ export default (
parent_id: { type: Sequelize.STRING, allowNull: true },
address_id: { type: Sequelize.INTEGER, allowNull: true },
created_by: { type: Sequelize.STRING, allowNull: true },
body: { type: Sequelize.TEXT, allowNull: false },
body: {
type: Sequelize.STRING(MAX_TRUNCATED_CONTENT_LENGTH),
allowNull: false,
},

// canvas-related columns
canvas_signed_data: { type: Sequelize.JSONB, allowNull: true },
Expand Down
6 changes: 5 additions & 1 deletion libs/model/src/models/comment_version_history.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CommentVersionHistory } from '@hicommonwealth/schemas';
import { MAX_TRUNCATED_CONTENT_LENGTH } from '@hicommonwealth/shared';
import Sequelize from 'sequelize';
import { z } from 'zod';
import { CommentAttributes } from './comment';
Expand All @@ -23,7 +24,10 @@ export default (
{
id: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true },
comment_id: { type: Sequelize.INTEGER, allowNull: false },
body: { type: Sequelize.TEXT, allowNull: false },
body: {
type: Sequelize.STRING(MAX_TRUNCATED_CONTENT_LENGTH),
allowNull: false,
},
timestamp: { type: Sequelize.DATE, allowNull: false },
content_url: { type: Sequelize.STRING, allowNull: true },
},
Expand Down
10 changes: 8 additions & 2 deletions libs/model/src/models/thread.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { EventNames } from '@hicommonwealth/core';
import { Thread } from '@hicommonwealth/schemas';
import { getDecodedString } from '@hicommonwealth/shared';
import {
getDecodedString,
MAX_TRUNCATED_CONTENT_LENGTH,
} from '@hicommonwealth/shared';
import Sequelize from 'sequelize';
import { z } from 'zod';
import { emitEvent, getThreadContestManagers } from '../utils/utils';
Expand All @@ -27,7 +30,10 @@ export default (
address_id: { type: Sequelize.INTEGER, allowNull: true },
created_by: { type: Sequelize.STRING, allowNull: true },
title: { type: Sequelize.TEXT, allowNull: false },
body: { type: Sequelize.TEXT, allowNull: false },
body: {
type: Sequelize.STRING(MAX_TRUNCATED_CONTENT_LENGTH),
allowNull: false,
},
kind: { type: Sequelize.STRING, allowNull: false },
stage: {
type: Sequelize.TEXT,
Expand Down
6 changes: 5 additions & 1 deletion libs/model/src/models/thread_version_history.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ThreadVersionHistory } from '@hicommonwealth/schemas';
import { MAX_TRUNCATED_CONTENT_LENGTH } from '@hicommonwealth/shared';
import Sequelize from 'sequelize';
import { z } from 'zod';
import { ThreadAttributes } from './thread';
Expand All @@ -24,7 +25,10 @@ export default (
id: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true },
thread_id: { type: Sequelize.INTEGER, allowNull: false },
address: { type: Sequelize.STRING, allowNull: false },
body: { type: Sequelize.TEXT, allowNull: false },
body: {
type: Sequelize.STRING(MAX_TRUNCATED_CONTENT_LENGTH),
allowNull: false,
},
timestamp: { type: Sequelize.DATE, allowNull: false },
content_url: { type: Sequelize.STRING, allowNull: true },
},
Expand Down
4 changes: 2 additions & 2 deletions libs/shared/test/checkIconSize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('checkIconSize', () => {
// TODO: make this test not require a remote HTTP request?
test('should return the image size', async () => {
const fileSizeBytes = await getFileSizeBytes(
'https://commonwealth-uploads.s3.us-east-2.amazonaws.com/bebbda6b-6b10-4cbd-8839-4fa8d2a0b266.jpg',
'https://assets.commonwealth.im/39115039-f3dc-4723-8813-f8a09107ca27.jpeg',
);
expect(fileSizeBytes).to.equal(14296);
expect(fileSizeBytes).to.equal(155407);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.changeColumn('Threads', 'body', {
type: Sequelize.STRING(2000),
allowNull: false,
transaction,
});
await queryInterface.changeColumn('Comments', 'body', {
type: Sequelize.STRING(2000),
allowNull: false,
transaction,
});
await queryInterface.changeColumn('ThreadVersionHistories', 'body', {
type: Sequelize.STRING(2000),
allowNull: false,
transaction,
});
await queryInterface.changeColumn('CommentVersionHistories', 'body', {
type: Sequelize.STRING(2000),
allowNull: false,
transaction,
});
});
},

async down(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.changeColumn('Threads', 'body', {
type: Sequelize.TEXT,
allowNull: true,
transaction,
});
await queryInterface.changeColumn('Comments', 'body', {
type: Sequelize.TEXT,
transaction,
});
await queryInterface.changeColumn('ThreadVersionHistories', 'body', {
type: Sequelize.TEXT,
transaction,
});
await queryInterface.changeColumn('CommentVersionHistories', 'body', {
type: Sequelize.TEXT,
transaction,
});
});
},
};
Loading