CREATE TABLE `project_members` (
	`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
	`project_id` integer NOT NULL,
	`user_id` integer NOT NULL,
	`role` text DEFAULT 'editor' NOT NULL,
	`added_at` integer NOT NULL,
	FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade,
	FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE INDEX `project_members_project_user_unique` ON `project_members` (`project_id`,`user_id`);--> statement-breakpoint
CREATE INDEX `idx_project_members_user` ON `project_members` (`user_id`);--> statement-breakpoint
CREATE TABLE `team_members` (
	`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
	`team_id` text NOT NULL,
	`user_id` integer NOT NULL,
	`role` text DEFAULT 'editor' NOT NULL,
	`joined_at` integer NOT NULL,
	FOREIGN KEY (`team_id`) REFERENCES `teams`(`id`) ON UPDATE no action ON DELETE cascade,
	FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE INDEX `team_members_team_user_unique` ON `team_members` (`team_id`,`user_id`);--> statement-breakpoint
CREATE INDEX `idx_team_members_user` ON `team_members` (`user_id`);--> statement-breakpoint
CREATE TABLE `teams` (
	`id` text PRIMARY KEY NOT NULL,
	`name` text NOT NULL,
	`owner_id` integer NOT NULL,
	`created_at` integer NOT NULL,
	`updated_at` integer NOT NULL,
	FOREIGN KEY (`owner_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE INDEX `idx_teams_owner` ON `teams` (`owner_id`);--> statement-breakpoint
DROP INDEX "character_relationships_unique_pair";--> statement-breakpoint
DROP INDEX "project_members_project_user_unique";--> statement-breakpoint
DROP INDEX "idx_project_members_user";--> statement-breakpoint
DROP INDEX "revision_changes_revision_idx";--> statement-breakpoint
DROP INDEX "revision_changes_type_idx";--> statement-breakpoint
DROP INDEX "revisions_script_version_idx";--> statement-breakpoint
DROP INDEX "revisions_script_branch_idx";--> statement-breakpoint
DROP INDEX "revisions_author_idx";--> statement-breakpoint
DROP INDEX "team_members_team_user_unique";--> statement-breakpoint
DROP INDEX "idx_team_members_user";--> statement-breakpoint
DROP INDEX "idx_teams_owner";--> statement-breakpoint
DROP INDEX "users_email_unique";--> statement-breakpoint
DROP INDEX "users_username_unique";--> statement-breakpoint
DROP INDEX "waitlist_signups_email_unique";--> statement-breakpoint
ALTER TABLE `alert_rules` ALTER COLUMN "created_at" TO "created_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.161Z"';--> statement-breakpoint
CREATE UNIQUE INDEX `character_relationships_unique_pair` ON `character_relationships` (`character_a_id`,`character_b_id`);--> statement-breakpoint
CREATE INDEX `revision_changes_revision_idx` ON `revision_changes` (`revision_id`);--> statement-breakpoint
CREATE INDEX `revision_changes_type_idx` ON `revision_changes` (`change_type`);--> statement-breakpoint
CREATE INDEX `revisions_script_version_idx` ON `revisions` (`script_id`,`version_number`);--> statement-breakpoint
CREATE INDEX `revisions_script_branch_idx` ON `revisions` (`script_id`,`branch_name`);--> statement-breakpoint
CREATE INDEX `revisions_author_idx` ON `revisions` (`author_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_username_unique` ON `users` (`username`);--> statement-breakpoint
CREATE UNIQUE INDEX `waitlist_signups_email_unique` ON `waitlist_signups` (`email`);--> statement-breakpoint
ALTER TABLE `alert_rules` ALTER COLUMN "updated_at" TO "updated_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.161Z"';--> statement-breakpoint
ALTER TABLE `alerts` ALTER COLUMN "created_at" TO "created_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.165Z"';--> statement-breakpoint
ALTER TABLE `alerts` ALTER COLUMN "acknowledged_by" TO "acknowledged_by" integer REFERENCES users(id) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `cohort_members` ALTER COLUMN "joined_at" TO "joined_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.174Z"';--> statement-breakpoint
ALTER TABLE `cohort_members` ALTER COLUMN "user_id" TO "user_id" integer NOT NULL REFERENCES users(id) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `cohorts` ALTER COLUMN "created_at" TO "created_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.174Z"';--> statement-breakpoint
ALTER TABLE `cohorts` ALTER COLUMN "updated_at" TO "updated_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.174Z"';--> statement-breakpoint
ALTER TABLE `kpi_snapshots` ALTER COLUMN "created_at" TO "created_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.158Z"';--> statement-breakpoint
ALTER TABLE `nps_responses` ALTER COLUMN "created_at" TO "created_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.171Z"';--> statement-breakpoint
ALTER TABLE `projects` ALTER COLUMN "created_at" TO "created_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.134Z"';--> statement-breakpoint
ALTER TABLE `projects` ALTER COLUMN "updated_at" TO "updated_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.134Z"';--> statement-breakpoint
ALTER TABLE `scheduled_reports` ALTER COLUMN "created_at" TO "created_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.168Z"';--> statement-breakpoint
ALTER TABLE `scheduled_reports` ALTER COLUMN "updated_at" TO "updated_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.168Z"';--> statement-breakpoint
ALTER TABLE `scripts` ALTER COLUMN "created_at" TO "created_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.141Z"';--> statement-breakpoint
ALTER TABLE `scripts` ALTER COLUMN "updated_at" TO "updated_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.141Z"';--> statement-breakpoint
ALTER TABLE `users` ALTER COLUMN "created_at" TO "created_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.126Z"';--> statement-breakpoint
ALTER TABLE `users` ALTER COLUMN "updated_at" TO "updated_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.126Z"';--> statement-breakpoint
ALTER TABLE `waitlist_events` ALTER COLUMN "created_at" TO "created_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.178Z"';--> statement-breakpoint
ALTER TABLE `waitlist_signups` ALTER COLUMN "created_at" TO "created_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.178Z"';--> statement-breakpoint
ALTER TABLE `waitlist_signups` ALTER COLUMN "updated_at" TO "updated_at" integer NOT NULL DEFAULT '"2026-04-26T22:14:11.178Z"';