CREATE TABLE `guilds` (
	`id` text PRIMARY KEY NOT NULL,
	`name` text
);
--> statement-breakpoint
CREATE TABLE `membership` (
	`user_id` text,
	`guild_id` text
);
--> statement-breakpoint
CREATE TABLE `memories` (
	`id` text PRIMARY KEY NOT NULL,
	`content` text,
	`timestamp` text DEFAULT (current_timestamp),
	`user_id` integer,
	`guild_id` integer,
	FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
	FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `messages` (
	`id` text PRIMARY KEY NOT NULL,
	`content` text,
	`timestamp` text DEFAULT (current_timestamp),
	`channel_id` text,
	`user_id` text,
	`guild_id` text,
	FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
	FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `users` (
	`id` text PRIMARY KEY NOT NULL,
	`name` text,
	`opt_out` integer
);
--> statement-breakpoint
CREATE INDEX `user_guild_idx` ON `membership` (`user_id`,`guild_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `user_guild_unique` ON `membership` (`user_id`,`guild_id`);--> statement-breakpoint
CREATE INDEX `user_timestamp_idx` ON `memories` (`user_id`,`timestamp`);--> statement-breakpoint
CREATE INDEX `channel_timestamp_idx` ON `messages` (`channel_id`,`timestamp`);