AgPerry's picture
Add files using upload-large-folder tool
062a991 verified
Raw History Blame Contribute Delete
12.7 kB
CREATE TABLE `audit_logs` (
`id` text PRIMARY KEY NOT NULL,
`tenant_id` text,
`actor_id` text,
`action` text NOT NULL,
`entity_type` text NOT NULL,
`entity_id` text NOT NULL,
`metadata` text DEFAULT '{}' NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
FOREIGN KEY (`tenant_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE set null,
FOREIGN KEY (`actor_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
CREATE INDEX `audit_logs_tenant_created_idx` ON `audit_logs` (`tenant_id`,`created_at`);--> statement-breakpoint
CREATE TABLE `comments` (
`id` text PRIMARY KEY NOT NULL,
`post_id` text NOT NULL,
`author_id` text NOT NULL,
`content` text NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
FOREIGN KEY (`post_id`) REFERENCES `posts`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`author_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE INDEX `comments_post_idx` ON `comments` (`post_id`,`created_at`);--> statement-breakpoint
CREATE INDEX `comments_author_idx` ON `comments` (`author_id`);--> statement-breakpoint
CREATE TABLE `connections` (
`id` text PRIMARY KEY NOT NULL,
`requester_id` text NOT NULL,
`recipient_id` text NOT NULL,
`status` text DEFAULT 'pending' NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
`responded_at` integer,
FOREIGN KEY (`requester_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`recipient_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE UNIQUE INDEX `connections_pair_unique` ON `connections` (`requester_id`,`recipient_id`);--> statement-breakpoint
CREATE INDEX `connections_recipient_status_idx` ON `connections` (`recipient_id`,`status`);--> statement-breakpoint
CREATE TABLE `conversation_members` (
`conversation_id` text NOT NULL,
`user_id` text NOT NULL,
`last_read_at` integer,
PRIMARY KEY(`conversation_id`, `user_id`),
FOREIGN KEY (`conversation_id`) REFERENCES `conversations`(`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 `conversation_members_user_idx` ON `conversation_members` (`user_id`);--> statement-breakpoint
CREATE TABLE `conversations` (
`id` text PRIMARY KEY NOT NULL,
`tenant_id` text,
`subject` text DEFAULT '' NOT NULL,
`updated_at` integer DEFAULT (unixepoch()) NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
FOREIGN KEY (`tenant_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
CREATE TABLE `email_verification_tokens` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`token_hash` text NOT NULL,
`sent_to_email` text NOT NULL,
`expires_at` integer NOT NULL,
`consumed_at` integer,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE UNIQUE INDEX `email_verification_tokens_hash_unique` ON `email_verification_tokens` (`token_hash`);--> statement-breakpoint
CREATE INDEX `email_verification_tokens_user_idx` ON `email_verification_tokens` (`user_id`);--> statement-breakpoint
CREATE INDEX `email_verification_tokens_expiry_idx` ON `email_verification_tokens` (`expires_at`);--> statement-breakpoint
CREATE TABLE `experiences` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`organization_id` text,
`company_name` text NOT NULL,
`title` text NOT NULL,
`location` text DEFAULT '' NOT NULL,
`description` text DEFAULT '' NOT NULL,
`start_date` text NOT NULL,
`end_date` text,
`current` integer DEFAULT false NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
CREATE INDEX `experiences_user_idx` ON `experiences` (`user_id`);--> statement-breakpoint
CREATE TABLE `job_applications` (
`id` text PRIMARY KEY NOT NULL,
`job_id` text NOT NULL,
`applicant_id` text NOT NULL,
`status` text DEFAULT 'submitted' NOT NULL,
`cover_note` text DEFAULT '' NOT NULL,
`resume_url` text,
`answers` text DEFAULT '{}' NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
`updated_at` integer DEFAULT (unixepoch()) NOT NULL,
FOREIGN KEY (`job_id`) REFERENCES `jobs`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`applicant_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE UNIQUE INDEX `job_applications_job_applicant_unique` ON `job_applications` (`job_id`,`applicant_id`);--> statement-breakpoint
CREATE INDEX `job_applications_applicant_idx` ON `job_applications` (`applicant_id`);--> statement-breakpoint
CREATE TABLE `jobs` (
`id` text PRIMARY KEY NOT NULL,
`organization_id` text NOT NULL,
`created_by` text NOT NULL,
`title` text NOT NULL,
`description` text NOT NULL,
`requirements` text DEFAULT '' NOT NULL,
`location` text NOT NULL,
`workplace_type` text DEFAULT 'Hybrid' NOT NULL,
`employment_type` text DEFAULT 'Full-time' NOT NULL,
`seniority` text DEFAULT 'Mid-Senior level' NOT NULL,
`salary_min` integer,
`salary_max` integer,
`currency` text DEFAULT 'USD' NOT NULL,
`status` text DEFAULT 'published' NOT NULL,
`tenant_visibility` text DEFAULT 'public' NOT NULL,
`published_at` integer DEFAULT (unixepoch()),
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
`updated_at` integer DEFAULT (unixepoch()) NOT NULL,
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`created_by`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE INDEX `jobs_org_status_idx` ON `jobs` (`organization_id`,`status`);--> statement-breakpoint
CREATE INDEX `jobs_location_idx` ON `jobs` (`location`);--> statement-breakpoint
CREATE INDEX `jobs_published_idx` ON `jobs` (`published_at`);--> statement-breakpoint
CREATE TABLE `memberships` (
`organization_id` text NOT NULL,
`user_id` text NOT NULL,
`role` text DEFAULT 'member' NOT NULL,
`title` text DEFAULT '' NOT NULL,
`joined_at` integer DEFAULT (unixepoch()) NOT NULL,
PRIMARY KEY(`organization_id`, `user_id`),
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`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 `memberships_user_idx` ON `memberships` (`user_id`);--> statement-breakpoint
CREATE TABLE `messages` (
`id` text PRIMARY KEY NOT NULL,
`conversation_id` text NOT NULL,
`sender_id` text NOT NULL,
`body` text NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
FOREIGN KEY (`conversation_id`) REFERENCES `conversations`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`sender_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE INDEX `messages_conversation_idx` ON `messages` (`conversation_id`,`created_at`);--> statement-breakpoint
CREATE TABLE `notifications` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`actor_id` text,
`type` text NOT NULL,
`title` text NOT NULL,
`body` text DEFAULT '' NOT NULL,
`href` text DEFAULT '/notifications' NOT NULL,
`read_at` integer,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`actor_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
CREATE INDEX `notifications_user_read_idx` ON `notifications` (`user_id`,`read_at`,`created_at`);--> statement-breakpoint
CREATE TABLE `organizations` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`slug` text NOT NULL,
`tagline` text DEFAULT '' NOT NULL,
`description` text DEFAULT '' NOT NULL,
`industry` text DEFAULT '' NOT NULL,
`website` text,
`location` text DEFAULT '' NOT NULL,
`employee_count` integer DEFAULT 0 NOT NULL,
`logo_url` text,
`settings` text DEFAULT '{"allowMemberPosts":true,"defaultJobVisibility":"public"}' NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
`updated_at` integer DEFAULT (unixepoch()) NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `organizations_slug_unique` ON `organizations` (`slug`);--> statement-breakpoint
CREATE TABLE `post_likes` (
`post_id` text NOT NULL,
`user_id` text NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
PRIMARY KEY(`post_id`, `user_id`),
FOREIGN KEY (`post_id`) REFERENCES `posts`(`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 TABLE `posts` (
`id` text PRIMARY KEY NOT NULL,
`author_id` text NOT NULL,
`organization_id` text,
`content` text NOT NULL,
`media_url` text,
`visibility` text DEFAULT 'network' NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
`updated_at` integer DEFAULT (unixepoch()) NOT NULL,
FOREIGN KEY (`author_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
CREATE INDEX `posts_created_idx` ON `posts` (`created_at`);--> statement-breakpoint
CREATE INDEX `posts_author_idx` ON `posts` (`author_id`);--> statement-breakpoint
CREATE INDEX `posts_org_idx` ON `posts` (`organization_id`);--> statement-breakpoint
CREATE TABLE `saved_jobs` (
`job_id` text NOT NULL,
`user_id` text NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
PRIMARY KEY(`job_id`, `user_id`),
FOREIGN KEY (`job_id`) REFERENCES `jobs`(`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 `saved_jobs_user_idx` ON `saved_jobs` (`user_id`,`created_at`);--> statement-breakpoint
CREATE TABLE `sessions` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`token_hash` text NOT NULL,
`expires_at` integer NOT NULL,
`last_seen_at` integer DEFAULT (unixepoch()) NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE UNIQUE INDEX `sessions_token_hash_unique` ON `sessions` (`token_hash`);--> statement-breakpoint
CREATE INDEX `sessions_user_idx` ON `sessions` (`user_id`);--> statement-breakpoint
CREATE INDEX `sessions_expiry_idx` ON `sessions` (`expires_at`);--> statement-breakpoint
CREATE TABLE `subscriptions` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`stripe_customer_id` text,
`stripe_subscription_id` text,
`stripe_price_id` text NOT NULL,
`status` text DEFAULT 'incomplete' NOT NULL,
`current_period_start` integer,
`current_period_end` integer,
`cancel_at_period_end` integer DEFAULT false NOT NULL,
`checkout_session_id` text,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
`updated_at` integer DEFAULT (unixepoch()) NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE UNIQUE INDEX `subscriptions_user_unique` ON `subscriptions` (`user_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `subscriptions_stripe_customer_unique` ON `subscriptions` (`stripe_customer_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `subscriptions_stripe_subscription_unique` ON `subscriptions` (`stripe_subscription_id`);--> statement-breakpoint
CREATE INDEX `subscriptions_status_idx` ON `subscriptions` (`status`);--> statement-breakpoint
CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL,
`email` text NOT NULL,
`username` text NOT NULL,
`password_hash` text NOT NULL,
`email_verified_at` integer,
`name` text NOT NULL,
`headline` text DEFAULT '' NOT NULL,
`about` text DEFAULT '' NOT NULL,
`location` text DEFAULT '' NOT NULL,
`avatar_url` text,
`cover_url` text,
`open_to_work` integer DEFAULT false NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
`updated_at` integer DEFAULT (unixepoch()) NOT NULL
);
--> 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 INDEX `users_name_idx` ON `users` (`name`);