Skip to content

Commit 3edc6c5

Browse files
Database changes for autotranslations (#9495) (#9499)
(cherry picked from commit 61f1031) Co-authored-by: Daniel Espino García <larkox@gmail.com>
1 parent 95d5012 commit 3edc6c5

File tree

16 files changed

+64
-5
lines changed

16 files changed

+64
-5
lines changed

app/database/migration/server/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ const {
2525
const {PLAYBOOK_RUN, PLAYBOOK_CHECKLIST, PLAYBOOK_CHECKLIST_ITEM, PLAYBOOK_RUN_ATTRIBUTE, PLAYBOOK_RUN_ATTRIBUTE_VALUE} = PLAYBOOK_TABLES;
2626

2727
export default schemaMigrations({migrations: [
28+
{
29+
toVersion: 18,
30+
steps: [
31+
addColumns({
32+
table: MY_CHANNEL,
33+
columns: [
34+
{name: 'autotranslation_disabled', type: 'boolean'},
35+
],
36+
}),
37+
addColumns({
38+
table: CHANNEL,
39+
columns: [
40+
{name: 'autotranslation', type: 'boolean'},
41+
],
42+
}),
43+
],
44+
},
2845
{
2946
toVersion: 17,
3047
steps: [

app/database/models/server/channel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ export default class ChannelModel extends Model implements ChannelModelInterface
155155
/** categoryChannel : Query returning the membership data for the current user if it belongs to this channel */
156156
@immutableRelation(CATEGORY_CHANNEL, 'channel_id') categoryChannel!: Relation<CategoryChannelModel>;
157157

158+
/** autotranslation : Whether the channel has automatic translation enabled */
159+
@field('autotranslation') autotranslation!: boolean;
160+
158161
toApi = (): Channel => {
159162
return {
160163
id: this.id,
@@ -176,6 +179,7 @@ export default class ChannelModel extends Model implements ChannelModelInterface
176179
shared: this.shared,
177180
banner_info: this.bannerInfo,
178181
policy_enforced: this.abacPolicyEnforced,
182+
autotranslation: this.autotranslation,
179183
};
180184
};
181185
}

app/database/models/server/my_channel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export default class MyChannelModel extends Model implements MyChannelModelInter
5656
/** last_playbook_runs_fetch_at : The timestamp of the last successful fetch of playbook runs for this channel, used as the "since" parameter for incremental updates */
5757
@field('last_playbook_runs_fetch_at') lastPlaybookRunsFetchAt!: number;
5858

59+
/* autotranslation: Determines if the channel has automatic translation enabled for this user*/
60+
@field('autotranslation_disabled') autotranslationDisabled!: boolean;
61+
5962
/** channel : The relation pointing to the CHANNEL table */
6063
@immutableRelation(CHANNEL, 'id') channel!: Relation<ChannelModel>;
6164

app/database/operator/server_data_operator/transformers/channel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const transformChannelRecord = ({action, database, value}: TransformerArg
5353
channel.type = raw.type;
5454
channel.bannerInfo = raw.banner_info;
5555
channel.abacPolicyEnforced = Boolean(raw.policy_enforced);
56+
channel.autotranslation = Boolean(raw.autotranslation);
5657
};
5758

5859
return prepareBaseRecord({
@@ -156,6 +157,7 @@ export const transformMyChannelRecord = async ({action, database, value}: Transf
156157
myChannel.viewedAt = record?.viewedAt || 0;
157158
myChannel.lastFetchedAt = record?.lastFetchedAt || 0;
158159
myChannel.lastPlaybookRunsFetchAt = record?.lastPlaybookRunsFetchAt || 0;
160+
myChannel.autotranslationDisabled = Boolean(raw.autotranslation_disabled);
159161
};
160162

161163
return prepareBaseRecord({

app/database/schema/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
} from './table_schemas';
4646

4747
export const serverSchema: AppSchema = appSchema({
48-
version: 17,
48+
version: 18,
4949
tables: [
5050
CategorySchema,
5151
CategoryChannelSchema,

app/database/schema/server/table_schemas/channel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ export default tableSchema({
2222
{name: 'update_at', type: 'number'},
2323
{name: 'banner_info', type: 'string', isOptional: true},
2424
{name: 'abac_policy_enforced', type: 'boolean', isOptional: true},
25+
{name: 'autotranslation', type: 'boolean', isOptional: true},
2526
],
2627
});

app/database/schema/server/table_schemas/my_channel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default tableSchema({
2020
{name: 'viewed_at', type: 'number'},
2121
{name: 'last_fetched_at', type: 'number', isIndexed: true},
2222
{name: 'last_playbook_runs_fetch_at', type: 'number'},
23+
{name: 'autotranslation_disabled', type: 'boolean', isOptional: true},
2324
],
2425
});
2526

app/database/schema/server/test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const {PLAYBOOK_RUN, PLAYBOOK_CHECKLIST, PLAYBOOK_CHECKLIST_ITEM, PLAYBOOK_RUN_A
5252
describe('*** Test schema for SERVER database ***', () => {
5353
it('=> The SERVER SCHEMA should strictly match', () => {
5454
expect(serverSchema).toEqual({
55-
version: 17,
55+
version: 18,
5656
unsafeSql: undefined,
5757
tables: {
5858
[CATEGORY]: {
@@ -130,6 +130,7 @@ describe('*** Test schema for SERVER database ***', () => {
130130
update_at: {name: 'update_at', type: 'number'},
131131
banner_info: {name: 'banner_info', type: 'string', isOptional: true},
132132
abac_policy_enforced: {name: 'abac_policy_enforced', type: 'boolean', isOptional: true},
133+
autotranslation: {name: 'autotranslation', type: 'boolean', isOptional: true},
133134
},
134135
columnArray: [
135136
{name: 'create_at', type: 'number'},
@@ -144,6 +145,7 @@ describe('*** Test schema for SERVER database ***', () => {
144145
{name: 'update_at', type: 'number'},
145146
{name: 'banner_info', type: 'string', isOptional: true},
146147
{name: 'abac_policy_enforced', type: 'boolean', isOptional: true},
148+
{name: 'autotranslation', type: 'boolean', isOptional: true},
147149
],
148150
},
149151
[CHANNEL_BOOKMARK]: {
@@ -269,6 +271,7 @@ describe('*** Test schema for SERVER database ***', () => {
269271
viewed_at: {name: 'viewed_at', type: 'number'},
270272
last_fetched_at: {name: 'last_fetched_at', type: 'number', isIndexed: true},
271273
last_playbook_runs_fetch_at: {name: 'last_playbook_runs_fetch_at', type: 'number'},
274+
autotranslation_disabled: {name: 'autotranslation_disabled', type: 'boolean', isOptional: true},
272275
},
273276
columnArray: [
274277
{name: 'is_unread', type: 'boolean'},
@@ -281,6 +284,7 @@ describe('*** Test schema for SERVER database ***', () => {
281284
{name: 'viewed_at', type: 'number'},
282285
{name: 'last_fetched_at', type: 'number', isIndexed: true},
283286
{name: 'last_playbook_runs_fetch_at', type: 'number'},
287+
{name: 'autotranslation_disabled', type: 'boolean', isOptional: true},
284288
],
285289
},
286290
[MY_CHANNEL_SETTINGS]: {

docs/database/server/server-v5.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
1+
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
22
-- Link to schema: https://app.quickdatabasediagrams.com/#/d/7cAwTM
33
-- NOTE! If you have used non-SQL datatypes in your design, you will have to change these here.
44

5-
-- Server Database - Schema Version 2
5+
-- Server Database - Schema Version 18
66
-- Please bump the version by 1, any time the schema changes.
77
-- Also, include the migration plan under app/database/migration/server,
88
-- update all models, relationships and types.
@@ -56,6 +56,7 @@ CREATE TABLE [Channel] (
5656
[update_at] number NOT NULL ,
5757
[banner_info] string,
5858
[abac_policy_enforced] boolean NOT NULL ,
59+
[autotranslation] boolean NULL ,
5960
CONSTRAINT [PK_Channel] PRIMARY KEY CLUSTERED (
6061
[id] ASC
6162
)
@@ -193,6 +194,7 @@ CREATE TABLE [MyChannel] (
193194
[message_count] number NOT NULL ,
194195
[roles] string NOT NULL ,
195196
[viewed_at] number NOT NULL ,
197+
[autotranslation_disabled] boolean NULL ,
196198
CONSTRAINT [PK_MyChannel] PRIMARY KEY CLUSTERED (
197199
[id] ASC
198200
)

docs/database/server/server.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Server Database - Schema Version 14
1+
# Server Database - Schema Version 18
22
# Please bump the version by 1, any time the schema changes.
33
# Also, include the migration plan under app/database/migration/server,
44
# update all models, relationships and types.
@@ -41,6 +41,7 @@ type string
4141
update_at number
4242
banner_info string
4343
abac_policy_enforced boolean
44+
autotranslation boolean
4445

4546

4647
ChannelInfo
@@ -178,6 +179,7 @@ mentions_count number
178179
message_count number
179180
roles string
180181
viewed_at number
182+
autotranslation_disabled boolean
181183

182184

183185
MyChannelSettings

0 commit comments

Comments
 (0)