channel banner DB migration (#8733)

* channel banner DB migration

* Updated database docs
This commit is contained in:
Harshil Sharma 2025-04-04 12:24:17 +05:30 committed by GitHub
parent 6c51f3948c
commit 6480fe52aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 38 additions and 680 deletions

View file

@ -8,9 +8,20 @@ import {addColumns, createTable, schemaMigrations, unsafeExecuteSql} from '@nozb
import {MM_TABLES} from '@constants/database';
const {CHANNEL_BOOKMARK, CHANNEL_INFO, DRAFT, POST} = MM_TABLES.SERVER;
const {CHANNEL_BOOKMARK, CHANNEL_INFO, DRAFT, POST, CHANNEL} = MM_TABLES.SERVER;
export default schemaMigrations({migrations: [
{
toVersion: 7,
steps: [
addColumns({
table: CHANNEL,
columns: [
{name: 'banner_info', type: 'string', isOptional: true},
],
}),
],
},
{
toVersion: 6,
steps: [

View file

@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {children, field, immutableRelation} from '@nozbe/watermelondb/decorators';
import {children, field, immutableRelation, json} from '@nozbe/watermelondb/decorators';
import Model, {type Associations} from '@nozbe/watermelondb/Model';
import {MM_TABLES} from '@constants/database';
import {safeParseJSON} from '@utils/helpers';
import type {Query, Relation} from '@nozbe/watermelondb';
import type CategoryChannelModel from '@typings/database/models/servers/category_channel';
@ -108,6 +109,9 @@ export default class ChannelModel extends Model implements ChannelModelInterface
/** type : The type of the channel ( e.g. G: group messages, D: direct messages, P: private channel and O: public channel) */
@field('type') type!: ChannelType;
/** bannerInfo : The banner information for the channel */
@json('banner_info', safeParseJSON) bannerInfo?: ChannelBannerInfo;
/** members : Users belonging to this channel */
@children(CHANNEL_MEMBERSHIP) members!: Query<ChannelMembershipModel>;
@ -158,6 +162,7 @@ export default class ChannelModel extends Model implements ChannelModelInterface
scheme_id: null,
group_constrained: null,
shared: this.shared,
banner_info: this.bannerInfo,
};
};
}

View file

@ -51,6 +51,7 @@ export const transformChannelRecord = ({action, database, value}: TransformerArg
channel.shared = Boolean(raw.shared);
channel.teamId = raw.team_id;
channel.type = raw.type;
channel.bannerInfo = raw.banner_info;
};
return prepareBaseRecord({

View file

@ -40,7 +40,7 @@ import {
} from './table_schemas';
export const serverSchema: AppSchema = appSchema({
version: 6,
version: 7,
tables: [
CategorySchema,
CategoryChannelSchema,

View file

@ -20,5 +20,6 @@ export default tableSchema({
{name: 'team_id', type: 'string', isIndexed: true},
{name: 'type', type: 'string'},
{name: 'update_at', type: 'number'},
{name: 'banner_info', type: 'string', isOptional: true},
],
});

View file

@ -46,7 +46,7 @@ const {
describe('*** Test schema for SERVER database ***', () => {
it('=> The SERVER SCHEMA should strictly match', () => {
expect(serverSchema).toEqual({
version: 6,
version: 7,
unsafeSql: undefined,
tables: {
[CATEGORY]: {
@ -122,6 +122,7 @@ describe('*** Test schema for SERVER database ***', () => {
team_id: {name: 'team_id', type: 'string', isIndexed: true},
type: {name: 'type', type: 'string'},
update_at: {name: 'update_at', type: 'number'},
banner_info: {name: 'banner_info', type: 'string', isOptional: true},
},
columnArray: [
@ -135,6 +136,7 @@ describe('*** Test schema for SERVER database ***', () => {
{name: 'team_id', type: 'string', isIndexed: true},
{name: 'type', type: 'string'},
{name: 'update_at', type: 'number'},
{name: 'banner_info', type: 'string', isOptional: true},
],
},
[CHANNEL_BOOKMARK]: {

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 KiB

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,5 @@
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
-- Link to schema: https://app.quickdatabasediagrams.com/#/d/PITc8R
-- Link to schema: https://app.quickdatabasediagrams.com/#/d/y8OBmj
-- NOTE! If you have used non-SQL datatypes in your design, you will have to change these here.
-- Server Database - Schema Version 2
@ -54,6 +54,7 @@ CREATE TABLE [Channel] (
[team_id] string NOT NULL ,
[type] string NOT NULL ,
[update_at] number NOT NULL ,
[banner_info] string,
CONSTRAINT [PK_Channel] PRIMARY KEY CLUSTERED (
[id] ASC
)

View file

@ -1,4 +1,4 @@
# Server Database - Schema Version 3
# Server Database - Schema Version 4
# 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.
@ -39,6 +39,7 @@ shared bool
team_id string INDEX FK >- Team.id
type string
update_at number
banner_info string
ChannelInfo

View file

@ -44,6 +44,7 @@ type Channel = {
fake?: boolean;
group_constrained: boolean|null;
shared: boolean;
banner_info?: ChannelBannerInfo;
};
type ChannelPatch = {
name?: string;
@ -163,3 +164,9 @@ type UpdateChannelBookmarkResponse = {
updated: ChannelBookmarkWithFileInfo;
deleted?: ChannelBookmarkWithFileInfo;
}
type ChannelBannerInfo = {
enabled?: boolean;
text?: string;
background_color?: string;
}

View file

@ -54,6 +54,8 @@ declare class ChannelModel extends Model {
/** type : The type of the channel ( e.g. G: group messages, D: direct messages, P: private channel and O: public channel) */
type: ChannelType;
bannerInfo?: ChannelBannerInfo;
/** members : Users belonging to this channel */
members: Query<ChannelMembershipModel>;