MM-60705 DB migration: added update_at column to draft table for mobile (#8237)
* MM-60705 DB migration: added update_at column to draft table for mobile * refactor: updated docs * refactor: reverted unwanted changes and updated default value for update_at columns * refactor: changed the condition for excepting 0 value for update_at column
This commit is contained in:
parent
c6583b7f90
commit
647b8c8eb6
18 changed files with 41 additions and 7 deletions
|
|
@ -35,6 +35,7 @@ const draft: Draft = {
|
|||
channel_id: channel.id,
|
||||
message: 'test',
|
||||
root_id: '',
|
||||
update_at: Date.now(),
|
||||
} as Draft;
|
||||
|
||||
beforeEach(async () => {
|
||||
|
|
@ -106,7 +107,7 @@ describe('removeDraftFile', () => {
|
|||
});
|
||||
|
||||
it('remove draft file, no message', async () => {
|
||||
await operator.handleDraft({drafts: [{channel_id: channel.id, files: [fileInfo], root_id: ''}], prepareRecordsOnly: false});
|
||||
await operator.handleDraft({drafts: [{channel_id: channel.id, files: [fileInfo], root_id: '', update_at: Date.now()}], prepareRecordsOnly: false});
|
||||
|
||||
const {draft: draftModel, error} = await removeDraftFile(serverUrl, channelId, '', 'clientid', false);
|
||||
expect(error).toBeUndefined();
|
||||
|
|
@ -152,7 +153,7 @@ describe('updateDraftMessage', () => {
|
|||
});
|
||||
|
||||
it('update draft message, no file', async () => {
|
||||
await operator.handleDraft({drafts: [{channel_id: channel.id, files: [], root_id: ''}], prepareRecordsOnly: false});
|
||||
await operator.handleDraft({drafts: [{channel_id: channel.id, files: [], root_id: '', update_at: Date.now()}], prepareRecordsOnly: false});
|
||||
|
||||
const result = await updateDraftMessage(serverUrl, channelId, '', 'newmessage', false) as {draft: DraftModel; error: unknown};
|
||||
expect(result.error).toBeUndefined();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ export async function updateDraftFile(serverUrl: string, channelId: string, root
|
|||
newFiles[i] = file;
|
||||
draft.prepareUpdate((d) => {
|
||||
d.files = newFiles;
|
||||
d.updateAt = Date.now();
|
||||
});
|
||||
|
||||
if (!prepareRecordsOnly) {
|
||||
|
|
@ -54,6 +55,7 @@ export async function removeDraftFile(serverUrl: string, channelId: string, root
|
|||
} else {
|
||||
draft.prepareUpdate((d) => {
|
||||
d.files = draft.files.filter((v, index) => index !== i);
|
||||
d.updateAt = Date.now();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -81,6 +83,7 @@ export async function updateDraftMessage(serverUrl: string, channelId: string, r
|
|||
channel_id: channelId,
|
||||
root_id: rootId,
|
||||
message,
|
||||
update_at: Date.now(),
|
||||
};
|
||||
|
||||
return operator.handleDraft({drafts: [newDraft], prepareRecordsOnly});
|
||||
|
|
@ -95,6 +98,7 @@ export async function updateDraftMessage(serverUrl: string, channelId: string, r
|
|||
} else {
|
||||
draft.prepareUpdate((d) => {
|
||||
d.message = message;
|
||||
d.updateAt = Date.now();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -119,6 +123,7 @@ export async function addFilesToDraft(serverUrl: string, channelId: string, root
|
|||
root_id: rootId,
|
||||
files,
|
||||
message: '',
|
||||
update_at: Date.now(),
|
||||
};
|
||||
|
||||
return operator.handleDraft({drafts: [newDraft], prepareRecordsOnly});
|
||||
|
|
@ -126,6 +131,7 @@ export async function addFilesToDraft(serverUrl: string, channelId: string, root
|
|||
|
||||
draft.prepareUpdate((d) => {
|
||||
d.files = [...draft.files, ...files];
|
||||
d.updateAt = Date.now();
|
||||
});
|
||||
|
||||
if (!prepareRecordsOnly) {
|
||||
|
|
@ -167,6 +173,7 @@ export async function updateDraftPriority(serverUrl: string, channelId: string,
|
|||
metadata: {
|
||||
priority: postPriority,
|
||||
},
|
||||
update_at: Date.now(),
|
||||
};
|
||||
|
||||
return operator.handleDraft({drafts: [newDraft], prepareRecordsOnly});
|
||||
|
|
@ -177,6 +184,7 @@ export async function updateDraftPriority(serverUrl: string, channelId: string,
|
|||
...d.metadata,
|
||||
priority: postPriority,
|
||||
};
|
||||
d.updateAt = Date.now();
|
||||
});
|
||||
|
||||
if (!prepareRecordsOnly) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,17 @@ import {MM_TABLES} from '@constants/database';
|
|||
const {CHANNEL_BOOKMARK, CHANNEL_INFO, DRAFT, POST} = MM_TABLES.SERVER;
|
||||
|
||||
export default schemaMigrations({migrations: [
|
||||
{
|
||||
toVersion: 5,
|
||||
steps: [
|
||||
addColumns({
|
||||
table: DRAFT,
|
||||
columns: [
|
||||
{name: 'update_at', type: 'number'},
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
{
|
||||
toVersion: 4,
|
||||
steps: [
|
||||
|
|
|
|||
|
|
@ -41,4 +41,7 @@ export default class DraftModel extends Model implements DraftModelInterface {
|
|||
@json('files', safeParseJSON) files!: FileInfo[];
|
||||
|
||||
@json('metadata', identity) metadata?: PostMetadata;
|
||||
|
||||
/** update_at : The timestamp to when this post was last updated on the server */
|
||||
@field('update_at') updateAt!: number;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ describe('*** Operator: Post Handlers tests ***', () => {
|
|||
],
|
||||
message: 'test draft message for post',
|
||||
root_id: '',
|
||||
update_at: Date.now(),
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ describe('*** POST Prepare Records Test ***', () => {
|
|||
message: 'draft message',
|
||||
channel_id: 'channel_idp23232e',
|
||||
files: [],
|
||||
update_at: Date.now(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ export const transformDraftRecord = ({action, database, value}: TransformerArgs)
|
|||
draft.channelId = raw?.channel_id ?? '';
|
||||
draft.files = raw?.files ?? emptyFileInfo;
|
||||
draft.metadata = raw?.metadata ?? emptyPostMetadata;
|
||||
draft.updateAt = raw.update_at ?? Date.now();
|
||||
};
|
||||
|
||||
return prepareBaseRecord({
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import {
|
|||
} from './table_schemas';
|
||||
|
||||
export const serverSchema: AppSchema = appSchema({
|
||||
version: 4,
|
||||
version: 5,
|
||||
tables: [
|
||||
CategorySchema,
|
||||
CategoryChannelSchema,
|
||||
|
|
|
|||
|
|
@ -15,5 +15,6 @@ export default tableSchema({
|
|||
{name: 'message', type: 'string'},
|
||||
{name: 'root_id', type: 'string', isIndexed: true},
|
||||
{name: 'metadata', type: 'string', isOptional: true},
|
||||
{name: 'update_at', type: 'number'},
|
||||
],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ const {
|
|||
describe('*** Test schema for SERVER database ***', () => {
|
||||
it('=> The SERVER SCHEMA should strictly match', () => {
|
||||
expect(serverSchema).toEqual({
|
||||
version: 4,
|
||||
version: 5,
|
||||
unsafeSql: undefined,
|
||||
tables: {
|
||||
[CATEGORY]: {
|
||||
|
|
@ -265,6 +265,7 @@ describe('*** Test schema for SERVER database ***', () => {
|
|||
message: {name: 'message', type: 'string'},
|
||||
root_id: {name: 'root_id', type: 'string', isIndexed: true},
|
||||
metadata: {name: 'metadata', type: 'string', isOptional: true},
|
||||
update_at: {name: 'update_at', type: 'number'},
|
||||
},
|
||||
columnArray: [
|
||||
{name: 'channel_id', type: 'string', isIndexed: true},
|
||||
|
|
@ -272,6 +273,7 @@ describe('*** Test schema for SERVER database ***', () => {
|
|||
{name: 'message', type: 'string'},
|
||||
{name: 'root_id', type: 'string', isIndexed: true},
|
||||
{name: 'metadata', type: 'string', isOptional: true},
|
||||
{name: 'update_at', type: 'number'},
|
||||
],
|
||||
},
|
||||
[FILE]: {
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 636 KiB |
Binary file not shown.
BIN
docs/database/server/server-v3.png
Normal file
BIN
docs/database/server/server-v3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 580 KiB |
File diff suppressed because one or more lines are too long
|
|
@ -1,5 +1,5 @@
|
|||
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
|
||||
-- Link to schema: https://app.quickdatabasediagrams.com/#/d/6OtugI
|
||||
-- Link to schema: https://app.quickdatabasediagrams.com/#/d/PITc8R
|
||||
-- NOTE! If you have used non-SQL datatypes in your design, you will have to change these here.
|
||||
|
||||
-- Server Database - Schema Version 2
|
||||
|
|
@ -101,6 +101,7 @@ CREATE TABLE [Draft] (
|
|||
[files] string NOT NULL ,
|
||||
[message] string NOT NULL ,
|
||||
[root_id] string NULL ,
|
||||
[update_at] number NOT NULL ,
|
||||
CONSTRAINT [PK_Draft] PRIMARY KEY CLUSTERED (
|
||||
[id] ASC
|
||||
)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# Server Database - Schema Version 2
|
||||
# Server Database - Schema Version 3
|
||||
# Please bump the version by 1, any time the schema changes.
|
||||
# Also, include the migration plan under app/database/migration/server,
|
||||
# update all models, relationships and types.
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ declare class DraftModel extends Model {
|
|||
files: FileInfo[];
|
||||
|
||||
metadata?: PostMetadata;
|
||||
|
||||
/** update_at : The timestamp to when this post was last updated on the server */
|
||||
updateAt: number;
|
||||
}
|
||||
|
||||
export default DraftModel;
|
||||
|
|
|
|||
1
types/database/raw_values.d.ts
vendored
1
types/database/raw_values.d.ts
vendored
|
|
@ -23,6 +23,7 @@ type Draft = {
|
|||
message?: string;
|
||||
root_id: string;
|
||||
metadata?: PostMetadata;
|
||||
update_at: number;
|
||||
};
|
||||
|
||||
type MyTeam = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue