CREATE TABLE `events` (
	`created` integer NOT NULL,
	`updated` integer,
	`ts` text PRIMARY KEY NOT NULL,
	`status` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `assets` (
	`id` integer PRIMARY KEY NOT NULL,
	`message_id` text NOT NULL,
	`mimetype` text NOT NULL,
	`filename` text NOT NULL,
	`format` text NOT NULL,
	`url` text,
	`size` integer,
	`image_url` text,
	`image_bytes` integer,
	`image_height` integer,
	`image_width` integer,
	`external_reference` text,
	`audio_duration_ms` integer
);
--> statement-breakpoint
CREATE TABLE `conversations` (
	`id` text PRIMARY KEY NOT NULL,
	`created` integer NOT NULL,
	`updated` integer,
	`user_id` integer,
	`latest_message_id` text,
	`last_read_id` text,
	`unread_count_display` text,
	`is_im` integer DEFAULT true,
	`is_user_deleted` integer DEFAULT false,
	`priority` integer DEFAULT 0,
	`unread_count` integer DEFAULT 0,
	`is_private` integer DEFAULT true,
	`num_members` integer DEFAULT 0,
	`is_channel` integer DEFAULT false,
	`picture_url` text,
	`name` text,
	`creator_id` text,
	`version` integer DEFAULT -1,
	`description` text,
	`mentioned` integer DEFAULT false
);
--> statement-breakpoint
CREATE TABLE `group_memberships` (
	`user_id` integer NOT NULL,
	`conversation_id` text NOT NULL,
	`is_active` integer DEFAULT true,
	`is_admin` integer DEFAULT false,
	`version` integer DEFAULT -1,
	PRIMARY KEY(`user_id`, `conversation_id`),
	FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
	FOREIGN KEY (`conversation_id`) REFERENCES `conversations`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `messages` (
	`id` text PRIMARY KEY NOT NULL,
	`created` integer NOT NULL,
	`updated` integer,
	`conversation_id` text NOT NULL,
	`user` integer NOT NULL,
	`text` text,
	`ts` text NOT NULL,
	`latest_event_ts` text,
	`message_ts` text,
	`status` text,
	`sender_name` text NOT NULL,
	`sender_profile_picture` text,
	`blocks` text,
	`version` integer DEFAULT -1,
	`position` integer DEFAULT 0 NOT NULL,
	`height` integer DEFAULT -1,
	`edited` integer DEFAULT false,
	`hidden` integer DEFAULT false,
	`highlighted_spans` text,
	`formatted_text` text
);
--> statement-breakpoint
CREATE TABLE `reactions` (
	`message_id` text NOT NULL,
	`user_id` integer NOT NULL,
	`name` text NOT NULL,
	`ts` text NOT NULL
);
--> statement-breakpoint
CREATE INDEX `reactions_message_id_idx` ON `reactions` (`message_id`);--> statement-breakpoint
CREATE INDEX `reactions_user_id_idx` ON `reactions` (`user_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `reactions_unique_idx` ON `reactions` (`message_id`,`user_id`,`name`);--> statement-breakpoint
CREATE TABLE `users` (
	`id` integer PRIMARY KEY NOT NULL,
	`name` text NOT NULL,
	`tz` text DEFAULT 'UTC' NOT NULL,
	`first_name` text NOT NULL,
	`last_name` text NOT NULL,
	`email` text,
	`employee_internal_id` text,
	`picture_url` text,
	`status` text DEFAULT 'ACTIVE',
	`deleted_at` integer,
	`version` integer DEFAULT -1,
	`created` integer NOT NULL,
	`updated` integer
);
