mattermost-mobile-upstream/app/database/schema/server/index.ts
Guillermo Vayá 354e956f43 feat(drafts): Phase 1 synchronized-drafts storage foundation
Adds the durable storage foundation for synchronized drafts (mobile-only,
no network behavior yet):

- Fix draft batch dedup in handleDraft to key by the composite
  (channel_id, root_id) instead of channel_id alone, so a channel draft
  and its thread reply drafts in the same batch no longer collapse.
- Add Draft columns: server_update_at (nullable ancestry hint, not a
  revision), props (JSON), file_ids (JSON portable server attachment IDs).
- Add the DraftOutbox table (one durable pending op per draft key) with
  operation/status const objects, generation, keep_local, retry fields,
  and a deleted_fingerprint column for delete-vs-newer-write disambiguation.
- Add buildDraftOutboxId, the serialized mutateDraftAndOutbox writer
  primitive (enters database.write before querying both tables, commits one
  batch), and deterministic repairDuplicateDrafts.
- Bump server schema 20 -> 21 with addColumns + createTable migration;
  register schema/model in the database managers, mocks, types, and docs.

Tests: composite-key survival, concurrent-mutation serialization, batch
failure atomicity, duplicate repair winner, model round-trip / migration
compatibility, and migration definition.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 16:18:48 +02:00

104 lines
2.7 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {BoardViewSchema} from '@boards/database/schema';
import {type AppSchema, appSchema} from '@nozbe/watermelondb';
import {AiBotSchema, AiThreadSchema} from '@agents/database/schema';
import {PlaybookRunSchema, PlaybookChecklistSchema, PlaybookChecklistItemSchema, PlaybookRunAttributeSchema, PlaybookRunAttributeValueSchema} from '@playbooks/database/schema';
import {
CategorySchema,
CategoryChannelSchema,
ChannelSchema,
ChannelBookmarkSchema,
ChannelInfoSchema,
ChannelMembershipSchema,
ConfigSchema,
CustomEmojiSchema,
CustomProfileFieldSchema,
CustomProfileAttributeSchema,
DraftSchema,
DraftOutboxSchema,
FileSchema,
GroupSchema,
GroupChannelSchema,
GroupMembershipSchema,
GroupTeamSchema,
MyChannelSchema,
MyChannelSettingsSchema,
MyTeamSchema,
PostInThreadSchema,
PostSchema,
PostsInChannelSchema,
PreferenceSchema,
PropertyFieldSchema,
PropertyValueSchema,
ReactionSchema,
RoleSchema,
ScheduledPostSchema,
SystemSchema,
TeamChannelHistorySchema,
TeamMembershipSchema,
TeamSchema,
TeamSearchHistorySchema,
ThreadSchema,
ThreadInTeamSchema,
ThreadParticipantSchema,
TeamThreadsSyncSchema,
UserSchema,
} from './table_schemas';
export const serverSchema: AppSchema = appSchema({
version: 21,
tables: [
AiBotSchema,
AiThreadSchema,
CategorySchema,
CategoryChannelSchema,
ChannelSchema,
ChannelBookmarkSchema,
ChannelInfoSchema,
ChannelMembershipSchema,
ConfigSchema,
CustomEmojiSchema,
CustomProfileFieldSchema,
CustomProfileAttributeSchema,
DraftSchema,
DraftOutboxSchema,
FileSchema,
GroupSchema,
GroupChannelSchema,
GroupMembershipSchema,
GroupTeamSchema,
MyChannelSchema,
MyChannelSettingsSchema,
MyTeamSchema,
PlaybookRunSchema,
PlaybookChecklistSchema,
PlaybookChecklistItemSchema,
PlaybookRunAttributeSchema,
PlaybookRunAttributeValueSchema,
PostInThreadSchema,
PostSchema,
PostsInChannelSchema,
PreferenceSchema,
PropertyFieldSchema,
PropertyValueSchema,
ReactionSchema,
RoleSchema,
ScheduledPostSchema,
SystemSchema,
TeamChannelHistorySchema,
TeamMembershipSchema,
TeamSchema,
TeamSearchHistorySchema,
TeamThreadsSyncSchema,
ThreadSchema,
ThreadInTeamSchema,
ThreadParticipantSchema,
UserSchema,
BoardViewSchema,
],
});