-- This file was generated by DatabaseSchemaCreatorTest on 2026-06-18T06:27:23.471694229Z. --
-- If you intentionally made changes to the schema, delete or clear this file and rerun the test to generate a new one, then verify and commit the changes. --

CREATE TABLE `contacts` (`identity` VARCHAR ,`publicKey` BLOB ,`firstName` VARCHAR ,`lastName` VARCHAR ,`publicNickName` VARCHAR ,`verificationLevel` INTEGER ,`state` VARCHAR DEFAULT 'ACTIVE' NOT NULL ,`androidContactId` VARCHAR ,`featureLevel` INTEGER DEFAULT 0 NOT NULL ,`idColorIndex` INTEGER ,`avatarExpires` BIGINT,`isWork` TINYINT DEFAULT 0,`type` INT DEFAULT 0,`profilePicBlobID` BLOB DEFAULT NULL,`dateCreated` BIGINT DEFAULT 0,`lastUpdateAt` INTEGER,`acquaintanceLevel` TINYINT DEFAULT 0 NOT NULL,`isRestored` TINYINT DEFAULT 0,`conversationVisibility` INTEGER DEFAULT 0 NOT NULL,`readReceipts` TINYINT DEFAULT 0,`typingIndicators` TINYINT DEFAULT 0,`forwardSecurityState` TINYINT DEFAULT 0,`syncState` INTEGER NOT NULL DEFAULT 0,`jobTitle` VARCHAR DEFAULT NULL,`department` VARCHAR DEFAULT NULL,`notificationTriggerPolicyOverridePolicy` INTEGER DEFAULT NULL,`notificationTriggerPolicyOverrideExpiresAt` BIGINT DEFAULT NULL,`workLastFullSyncAt` DATETIME DEFAULT NULL,PRIMARY KEY (`identity`) );
CREATE TABLE `message`(`id` INTEGER PRIMARY KEY AUTOINCREMENT , `uid` VARCHAR , `apiMessageId` VARCHAR , `identity` VARCHAR , `outbox` SMALLINT , `type` INTEGER , `body` VARCHAR , `correlationId` VARCHAR , `caption` VARCHAR , `isRead` SMALLINT , `isSaved` SMALLINT , `isQueued` TINYINT , `state` VARCHAR , `postedAtUtc` BIGINT , `createdAtUtc` BIGINT , `modifiedAtUtc` BIGINT , `isStatusMessage` SMALLINT ,`quotedMessageId` VARCHAR ,`messageContentsType` TINYINT ,`messageFlags` INT ,`deliveredAtUtc` DATETIME ,`readAtUtc` DATETIME ,`forwardSecurityMode` TINYINT DEFAULT 0 ,`displayTags` TINYINT DEFAULT 0 ,`editedAtUtc` DATETIME ,`deletedAtUtc` DATETIME );
CREATE INDEX `contact_message_uid_idx` ON `message` ( `uid` );
CREATE INDEX `message_identity_idx` ON `message` ( `identity` );
CREATE INDEX `messageApiMessageIdIdx` ON `message` ( `apiMessageId` );
CREATE INDEX `message_outbox_idx` ON `message` ( `outbox` );
CREATE INDEX `messageCorrelationIdIx` ON `message` ( `correlationId` );
CREATE INDEX `message_count_idx` ON `message`(`identity`, `outbox`, `isSaved`, `isRead`, `isStatusMessage`);
CREATE INDEX `message_state_idx` ON `message`(`type`, `state`, `outbox`);
CREATE TABLE `m_group` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `apiGroupId` VARCHAR , `name` VARCHAR , `creatorIdentity` VARCHAR , `createdAt` BIGINT , `lastUpdateAt` INTEGER, `synchronizedAt` BIGINT , `conversationVisibility` INTEGER DEFAULT 0 NOT NULL, `groupDesc` VARCHAR DEFAULT NULL, `changedGroupDescTimestamp` BIGINT DEFAULT NULL, `colorIndex` INTEGER DEFAULT 0 NOT NULL, `userState` INTEGER DEFAULT 0 NOT NULL, `notificationTriggerPolicyOverridePolicy` INTEGER DEFAULT NULL, `notificationTriggerPolicyOverrideExpiresAt` BIGINT DEFAULT NULL );
CREATE UNIQUE INDEX `apiGroupIdAndCreator` ON `m_group` ( `apiGroupId`, `creatorIdentity` );
CREATE TABLE `group_member` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `identity` VARCHAR , `groupId` INTEGER);
CREATE TABLE `m_group_message`(`id` INTEGER PRIMARY KEY AUTOINCREMENT , `uid` VARCHAR , `apiMessageId` VARCHAR , `groupId` INTEGER NOT NULL , `identity` VARCHAR , `outbox` SMALLINT , `type` INTEGER ,`correlationId` VARCHAR ,`body` VARCHAR ,`caption` VARCHAR ,`isRead` SMALLINT ,`isSaved` SMALLINT ,`isQueued` TINYINT ,`state` VARCHAR , `postedAtUtc` BIGINT , `createdAtUtc` BIGINT , `modifiedAtUtc` BIGINT , `isStatusMessage` SMALLINT ,`quotedMessageId` VARCHAR ,`messageContentsType` TINYINT ,`messageFlags` INT ,`deliveredAtUtc` DATETIME ,`readAtUtc` DATETIME ,`forwardSecurityMode` TINYINT DEFAULT 0 ,`groupMessageStates` VARCHAR ,`displayTags` TINYINT DEFAULT 0 ,`editedAtUtc` DATETIME ,`deletedAtUtc` DATETIME );
CREATE INDEX `group_message_uid_idx` ON `m_group_message` ( `uid` );
CREATE INDEX `m_group_message_outbox_idx` ON `m_group_message` ( `outbox` );
CREATE INDEX `m_group_message_identity_idx` ON `m_group_message` ( `identity` );
CREATE INDEX `m_group_message_groupId_idx` ON `m_group_message` ( `groupId` );
CREATE INDEX `groupMessageApiMessageIdIdx` ON `m_group_message` ( `apiMessageId` );
CREATE INDEX `groupMessageCorrelationIdIdx` ON `m_group_message` ( `correlationId` );
CREATE INDEX `group_message_state_idx` ON `m_group_message`(`type`, `state`, `outbox`);
CREATE TABLE `distribution_list` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` VARCHAR, `createdAt` BIGINT, `lastUpdateAt` INTEGER, `conversationVisibility` INTEGER DEFAULT 0 NOT NULL, `isHidden` TINYINT DEFAULT 0 );
CREATE TABLE `distribution_list_member`(`id` INTEGER PRIMARY KEY AUTOINCREMENT , `identity` VARCHAR , `distributionListId` INTEGER , `isActive` SMALLINT NOT NULL);
CREATE INDEX `distribution_list_member_dis_idx` ON `distribution_list_member`(`distributionListId`);
CREATE TABLE `distribution_list_message`(`id` INTEGER PRIMARY KEY AUTOINCREMENT ,`uid` VARCHAR ,`apiMessageId` VARCHAR ,`distributionListId` INTEGER NOT NULL ,`identity` VARCHAR ,`outbox` SMALLINT ,`type` INTEGER ,`correlationId` VARCHAR ,`body` VARCHAR ,`caption` VARCHAR ,`isRead` SMALLINT ,`isSaved` SMALLINT ,`isQueued` TINYINT ,`state` VARCHAR ,`postedAtUtc` BIGINT ,`createdAtUtc` BIGINT ,`modifiedAtUtc` BIGINT ,`isStatusMessage` SMALLINT ,`quotedMessageId` VARCHAR ,`messageContentsType` TINYINT ,`messageFlags` INT ,`deliveredAtUtc` DATETIME ,`readAtUtc` DATETIME ,`forwardSecurityMode` TINYINT DEFAULT 0 ,`displayTags` TINYINT DEFAULT 0 ,`editedAtUtc` DATETIME ,`deletedAtUtc` DATETIME );
CREATE INDEX `distributionListDistributionListIdIdx` ON `distribution_list_message` ( `distributionListId` );
CREATE INDEX `distribution_list_message_outbox_idx` ON `distribution_list_message` ( `outbox` );
CREATE INDEX `distributionListMessageIdIdx` ON `distribution_list_message` ( `apiMessageId` );
CREATE INDEX `distributionListMessageUidIdx` ON `distribution_list_message` ( `uid` );
CREATE INDEX `distribution_list_message_identity_idx` ON `distribution_list_message` ( `identity` );
CREATE INDEX `distributionListCorrelationIdIdx` ON `distribution_list_message` ( `correlationId` );
CREATE INDEX `distribution_list_message_state_idx` ON `distribution_list_message`(`type`, `state`, `outbox`);
CREATE TABLE `m_group_request_sync_log` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `apiGroupId` VARCHAR , `creatorIdentity` VARCHAR , `lastRequestAt` BIGINT );
CREATE UNIQUE INDEX `apiGroupIdAndCreatorGroupRequestSyncLogModel` ON `m_group_request_sync_log` ( `apiGroupId`, `creatorIdentity` );
CREATE TABLE `incoming_group_sync_request_log`(
    `groupId` INTEGER,
    `senderIdentity` VARCHAR,
    `lastHandledRequest` DATETIME,
    PRIMARY KEY (`groupId`, `senderIdentity`),
    FOREIGN KEY(`groupId`) REFERENCES `m_group`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE `ballot` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `apiBallotId` VARCHAR NOT NULL , `creatorIdentity` VARCHAR NOT NULL , `name` VARCHAR , `state` VARCHAR NOT NULL , `assessment` VARCHAR NOT NULL , `type` VARCHAR NOT NULL , `choiceType` VARCHAR NOT NULL , `displayType` VARCHAR , `createdAt` BIGINT NOT NULL , `modifiedAt` BIGINT NOT NULL , `lastViewedAt` BIGINT );
CREATE UNIQUE INDEX `apiBallotIdAndCreator` ON `ballot` ( `apiBallotId`, `creatorIdentity` );
CREATE TABLE `ballot_choice` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `ballotId` INTEGER , `apiBallotChoiceId` INTEGER , `type` VARCHAR , `name` VARCHAR , `voteCount` INTEGER , `order` INTEGER NOT NULL , `createdAt` BIGINT , `modifiedAt` BIGINT );
CREATE UNIQUE INDEX `apiBallotChoiceId` ON `ballot_choice` ( `ballotId`, `apiBallotChoiceId` );
CREATE TABLE `ballot_vote` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `ballotId` INTEGER NOT NULL , `ballotChoiceId` INTEGER NOT NULL , `votingIdentity` VARCHAR NOT NULL , `choice` INTEGER , `createdAt` BIGINT NOT NULL , `modifiedAt` BIGINT NOT NULL );
CREATE INDEX `ballotVotingCount` ON `ballot_vote` ( `ballotChoiceId`, `choice` );
CREATE UNIQUE INDEX `ballotVoteIdentity` ON `ballot_vote` ( `ballotId`, `ballotChoiceId`, `votingIdentity` );
CREATE TABLE `identity_ballot` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `identity` VARCHAR NOT NULL , `ballotId` INTEGER NOT NULL );
CREATE UNIQUE INDEX `identityBallotId` ON `identity_ballot` ( `identity`, `ballotId` );
CREATE TABLE `group_ballot` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `groupId` INTEGER NOT NULL , `ballotId` INTEGER NOT NULL );
CREATE UNIQUE INDEX `groupBallotId` ON `group_ballot` ( `groupId`, `ballotId` );
CREATE TABLE `wc_session` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `key` BLOB NULL,`key256` VARCHAR NULL,`private_key` BLOB NULL,`created` BIGINT NULL,`last_connection` BIGINT NULL,`client` VARCHAR, `state` VARCHAR NOT NULL, `is_persistent` TINYINT NOT NULL DEFAULT 0,`label` VARCHAR NULL,`self_hosted` TINYINT NOT NULL DEFAULT 0,`protocol_version` INT NOT NULL,`salty_host` VARCHAR NOT NULL,`salty_port` INT NOT NULL,`server_key` BLOB NULL,`push_token` VARCHAR(255) NULL);
CREATE UNIQUE INDEX `webClientSessionKey` ON `wc_session` ( `key` );
CREATE UNIQUE INDEX `webClientSessionKey256` ON `wc_session` ( `key256` );
CREATE TABLE IF NOT EXISTS `conversation_tag` (`conversationUid` VARCHAR NOT NULL, `tag` BLOB NULL,`createdAt` BIGINT, PRIMARY KEY (`conversationUid`, `tag`) );
CREATE UNIQUE INDEX IF NOT EXISTS `conversationTagKeyConversationTag` ON `conversation_tag` ( `conversationUid`, `tag` );
CREATE INDEX IF NOT EXISTS `conversationTagConversation` ON `conversation_tag` ( `conversationUid` );
CREATE INDEX IF NOT EXISTS`conversationTagTag` ON `conversation_tag` ( `tag` );
CREATE TABLE `group_call` (`callId` TEXT PRIMARY KEY NOT NULL, `groupId` INTEGER NOT NULL, `sfuBaseUrl` TEXT NOT NULL, `gck` TEXT NOT NULL, `protocolVersion` INTEGER DEFAULT 0,`startedAt` BIGINT NOT NULL,`processedAt` BIGINT NOT NULL);
CREATE TABLE `server_messages` (`message` VARCHAR PRIMARY KEY ON CONFLICT REPLACE,`type` INTEGER);
CREATE TABLE `tasks` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `task` STRING NOT NULL);
CREATE TABLE `app_tasks` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `appTaskData` TEXT NOT NULL);
CREATE TABLE `rejected_group_messages` (`messageId` INTEGER NOT NULL, `rejectedIdentity` VARCHAR NOT NULL, `groupId` INTEGER NOT NULL, PRIMARY KEY (`messageId`, `rejectedIdentity`, `groupId`) ON CONFLICT IGNORE );
CREATE TABLE IF NOT EXISTS `contact_edit_history_entries` (`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `messageUid` VARCHAR NOT NULL, `messageId` INTEGER NOT NULL, `text` VARCHAR DEFAULT NULL, `editedAt` DATETIME NOT NULL, CONSTRAINT fk_contact_message_id_new FOREIGN KEY(messageId) REFERENCES message (id) ON UPDATE CASCADE ON DELETE CASCADE );
CREATE TABLE IF NOT EXISTS `group_edit_history_entries` (`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `messageUid` VARCHAR NOT NULL, `messageId` INTEGER NOT NULL, `text` VARCHAR DEFAULT NULL, `editedAt` DATETIME NOT NULL, CONSTRAINT fk_group_message_id_new FOREIGN KEY(messageId) REFERENCES m_group_message (id) ON UPDATE CASCADE ON DELETE CASCADE );
CREATE TABLE IF NOT EXISTS `contact_reactions` (`messageId` INTEGER NOT NULL, `senderIdentity` VARCHAR NOT NULL, `emojiSequence` VARCHAR NOT NULL, `reactedAt` DATETIME NOT NULL, UNIQUE(`messageId`,`senderIdentity`,`emojiSequence`) ON CONFLICT REPLACE, CONSTRAINT `fk_contact_message_id` FOREIGN KEY(`messageId`) REFERENCES `message` (`id`) ON UPDATE CASCADE ON DELETE CASCADE );
CREATE INDEX `contact_reactions_idx` ON `contact_reactions` (`messageId`);
CREATE TABLE IF NOT EXISTS `group_reactions` (`messageId` INTEGER NOT NULL, `senderIdentity` VARCHAR NOT NULL, `emojiSequence` VARCHAR NOT NULL, `reactedAt` DATETIME NOT NULL, UNIQUE(`messageId`,`senderIdentity`,`emojiSequence`) ON CONFLICT REPLACE, CONSTRAINT `fk_group_message_id` FOREIGN KEY(`messageId`) REFERENCES `m_group_message` (`id`) ON UPDATE CASCADE ON DELETE CASCADE );
CREATE INDEX `group_reactions_idx` ON `group_reactions` (`messageId`);
CREATE TABLE `contact_availability_status` (
    `identity` VARCHAR NOT NULL PRIMARY KEY,
    `category` INTEGER NOT NULL,
    `description` TEXT NOT NULL,
    CONSTRAINT `fk_contacts_identity`
        FOREIGN KEY(`identity`)
        REFERENCES `contacts` (`identity`)
        ON UPDATE CASCADE
        ON DELETE CASCADE
);