SPB Git forge

spb/rareindex

Public
54commits 1branches 0releases
7.1 MBsize
maindefault branch
10 days agolast push
TypeScript 61.9% HTML 37.2% SQL 0.7%
9.7 KB · 215 lines sql
Raw Blame History
1CREATE TABLE "ai_quotas" (2	"key" text NOT NULL,3	"feature" text NOT NULL,4	"date" text NOT NULL,5	"count" integer DEFAULT 0 NOT NULL6);7--> statement-breakpoint8CREATE TABLE "research_messages" (9	"id" text PRIMARY KEY NOT NULL,10	"session_id" text NOT NULL,11	"role" text NOT NULL,12	"content" text NOT NULL,13	"tool_calls" jsonb DEFAULT '[]'::jsonb NOT NULL,14	"usage" jsonb DEFAULT '{}'::jsonb NOT NULL,15	"usd_est" real DEFAULT 0 NOT NULL,16	"model" text,17	"created_at" timestamp with time zone DEFAULT now() NOT NULL18);19--> statement-breakpoint20CREATE TABLE "research_sessions" (21	"id" text PRIMARY KEY NOT NULL,22	"user_id" text,23	"anon_id" text,24	"title" text,25	"model" text,26	"message_count" integer DEFAULT 0 NOT NULL,27	"usd_est" real DEFAULT 0 NOT NULL,28	"archived" boolean DEFAULT false NOT NULL,29	"created_at" timestamp with time zone DEFAULT now() NOT NULL,30	"updated_at" timestamp with time zone DEFAULT now() NOT NULL31);32--> statement-breakpoint33CREATE TABLE "scanner_sessions" (34	"id" text PRIMARY KEY NOT NULL,35	"user_id" text,36	"anon_id" text,37	"ip_hash" text,38	"mode" text NOT NULL,39	"input_url" text,40	"input_text" text,41	"image_count" integer DEFAULT 0 NOT NULL,42	"thumbnails" jsonb DEFAULT '[]'::jsonb NOT NULL,43	"guess" jsonb DEFAULT '{}'::jsonb NOT NULL,44	"guess_confidence" real,45	"candidates" jsonb DEFAULT '[]'::jsonb NOT NULL,46	"chosen_asset_id" text,47	"listing" jsonb DEFAULT '{}'::jsonb NOT NULL,48	"model" text,49	"usd_est" real DEFAULT 0 NOT NULL,50	"duration_ms" integer,51	"error" text,52	"created_at" timestamp with time zone DEFAULT now() NOT NULL,53	"chosen_at" timestamp with time zone54);55--> statement-breakpoint56CREATE TABLE "auth_codes" (57	"id" text PRIMARY KEY NOT NULL,58	"user_id" text,59	"email" text NOT NULL,60	"purpose" text NOT NULL,61	"code_hash" text NOT NULL,62	"expires_at" timestamp with time zone NOT NULL,63	"attempts" integer DEFAULT 0 NOT NULL,64	"consumed_at" timestamp with time zone,65	"payload" jsonb DEFAULT '{}'::jsonb NOT NULL,66	"created_at" timestamp with time zone DEFAULT now() NOT NULL67);68--> statement-breakpoint69CREATE TABLE "login_events" (70	"id" text PRIMARY KEY NOT NULL,71	"user_id" text,72	"email" text,73	"ip" text,74	"user_agent" text,75	"outcome" text NOT NULL,76	"method" text,77	"created_at" timestamp with time zone DEFAULT now() NOT NULL78);79--> statement-breakpoint80CREATE TABLE "notifications" (81	"id" text PRIMARY KEY NOT NULL,82	"user_id" text NOT NULL,83	"kind" text NOT NULL,84	"title" text NOT NULL,85	"body" text,86	"href" text,87	"payload" jsonb DEFAULT '{}'::jsonb NOT NULL,88	"read_at" timestamp with time zone,89	"emailed_at" timestamp with time zone,90	"created_at" timestamp with time zone DEFAULT now() NOT NULL91);92--> statement-breakpoint93CREATE TABLE "price_targets" (94	"id" text PRIMARY KEY NOT NULL,95	"user_id" text NOT NULL,96	"asset_id" text NOT NULL,97	"variant_id" text,98	"direction" text DEFAULT 'above' NOT NULL,99	"target_usd" numeric(18, 4) NOT NULL,100	"baseline_usd" numeric(18, 4),101	"note" text,102	"hit_at" timestamp with time zone,103	"notified_at" timestamp with time zone,104	"created_at" timestamp with time zone DEFAULT now() NOT NULL105);106--> statement-breakpoint107CREATE TABLE "rate_limits" (108	"key" text PRIMARY KEY NOT NULL,109	"count" integer DEFAULT 0 NOT NULL,110	"reset_at" timestamp with time zone NOT NULL111);112--> statement-breakpoint113CREATE TABLE "recovery_codes" (114	"id" text PRIMARY KEY NOT NULL,115	"user_id" text NOT NULL,116	"code_hash" text NOT NULL,117	"used_at" timestamp with time zone,118	"created_at" timestamp with time zone DEFAULT now() NOT NULL119);120--> statement-breakpoint121CREATE TABLE "saved_searches" (122	"id" text PRIMARY KEY NOT NULL,123	"user_id" text NOT NULL,124	"name" text NOT NULL,125	"url" text NOT NULL,126	"params" jsonb DEFAULT '{}'::jsonb NOT NULL,127	"notify" boolean DEFAULT false NOT NULL,128	"last_run_at" timestamp with time zone,129	"last_count" integer,130	"created_at" timestamp with time zone DEFAULT now() NOT NULL131);132--> statement-breakpoint133CREATE TABLE "trusted_devices" (134	"id" text PRIMARY KEY NOT NULL,135	"user_id" text NOT NULL,136	"token_hash" text NOT NULL,137	"label" text,138	"user_agent" text,139	"ip" text,140	"created_at" timestamp with time zone DEFAULT now() NOT NULL,141	"last_used_at" timestamp with time zone,142	"expires_at" timestamp with time zone NOT NULL,143	"revoked_at" timestamp with time zone144);145--> statement-breakpoint146CREATE TABLE "uploads" (147	"id" text PRIMARY KEY NOT NULL,148	"user_id" text NOT NULL,149	"kind" text NOT NULL,150	"path" text NOT NULL,151	"mime" text NOT NULL,152	"bytes" integer NOT NULL,153	"width" integer,154	"height" integer,155	"created_at" timestamp with time zone DEFAULT now() NOT NULL156);157--> statement-breakpoint158CREATE TABLE "user_badges" (159	"user_id" text NOT NULL,160	"badge" text NOT NULL,161	"evidence" jsonb DEFAULT '{}'::jsonb NOT NULL,162	"created_at" timestamp with time zone DEFAULT now() NOT NULL163);164--> statement-breakpoint165DROP INDEX "normalized_records_raw_uq";--> statement-breakpoint166ALTER TABLE "normalized_records" ADD COLUMN "seq" integer DEFAULT 0 NOT NULL;--> statement-breakpoint167ALTER TABLE "alerts" ADD COLUMN "name" text;--> statement-breakpoint168ALTER TABLE "alerts" ADD COLUMN "cooldown_minutes" integer DEFAULT 1440 NOT NULL;--> statement-breakpoint169ALTER TABLE "alerts" ADD COLUMN "trigger_count" integer DEFAULT 0 NOT NULL;--> statement-breakpoint170ALTER TABLE "collection_items" ADD COLUMN "tags" jsonb DEFAULT '[]'::jsonb NOT NULL;--> statement-breakpoint171ALTER TABLE "collection_items" ADD COLUMN "condition" text;--> statement-breakpoint172ALTER TABLE "collection_items" ADD COLUMN "manual_value_usd" numeric(18, 4);--> statement-breakpoint173ALTER TABLE "collection_items" ADD COLUMN "sold_at" date;--> statement-breakpoint174ALTER TABLE "collection_items" ADD COLUMN "sold_price_usd" numeric(18, 4);--> statement-breakpoint175ALTER TABLE "collections" ADD COLUMN "kind" text DEFAULT 'collection' NOT NULL;--> statement-breakpoint176ALTER TABLE "collections" ADD COLUMN "budget_usd" numeric(18, 4);--> statement-breakpoint177ALTER TABLE "collections" ADD COLUMN "color" text;--> statement-breakpoint178ALTER TABLE "sessions" ADD COLUMN "ip" text;--> statement-breakpoint179ALTER TABLE "sessions" ADD COLUMN "last_seen_at" timestamp with time zone;--> statement-breakpoint180ALTER TABLE "sessions" ADD COLUMN "revoked_at" timestamp with time zone;--> statement-breakpoint181ALTER TABLE "users" ADD COLUMN "handle" text;--> statement-breakpoint182ALTER TABLE "users" ADD COLUMN "avatar_url" text;--> statement-breakpoint183ALTER TABLE "users" ADD COLUMN "bio" text;--> statement-breakpoint184ALTER TABLE "users" ADD COLUMN "mfa_enabled" boolean DEFAULT false NOT NULL;--> statement-breakpoint185ALTER TABLE "users" ADD COLUMN "totp_secret_enc" text;--> statement-breakpoint186ALTER TABLE "users" ADD COLUMN "always_ask_code" boolean DEFAULT true NOT NULL;--> statement-breakpoint187ALTER TABLE "users" ADD COLUMN "password_changed_at" timestamp with time zone;--> statement-breakpoint188ALTER TABLE "users" ADD COLUMN "pending_email" text;--> statement-breakpoint189ALTER TABLE "users" ADD COLUMN "deleted_at" timestamp with time zone;--> statement-breakpoint190ALTER TABLE "users" ADD COLUMN "purge_after" timestamp with time zone;--> statement-breakpoint191ALTER TABLE "watchlist_items" ADD COLUMN "label" text;--> statement-breakpoint192ALTER TABLE "watchlist_items" ADD COLUMN "note" text;--> statement-breakpoint193ALTER TABLE "watchlist_items" ADD COLUMN "target_price_usd" numeric(18, 4);--> statement-breakpoint194ALTER TABLE "watchlist_items" ADD COLUMN "baseline_usd" numeric(18, 4);--> statement-breakpoint195CREATE INDEX "ai_quotas_uq" ON "ai_quotas" USING btree ("key","feature","date");--> statement-breakpoint196CREATE INDEX "research_messages_session_idx" ON "research_messages" USING btree ("session_id","created_at");--> statement-breakpoint197CREATE INDEX "research_sessions_anon_idx" ON "research_sessions" USING btree ("anon_id","updated_at");--> statement-breakpoint198CREATE INDEX "research_sessions_user_idx" ON "research_sessions" USING btree ("user_id","updated_at");--> statement-breakpoint199CREATE INDEX "scanner_sessions_created_idx" ON "scanner_sessions" USING btree ("created_at");--> statement-breakpoint200CREATE INDEX "scanner_sessions_ip_idx" ON "scanner_sessions" USING btree ("ip_hash","created_at");--> statement-breakpoint201CREATE INDEX "scanner_sessions_user_idx" ON "scanner_sessions" USING btree ("user_id");--> statement-breakpoint202CREATE INDEX "auth_codes_lookup_idx" ON "auth_codes" USING btree ("email","purpose","created_at");--> statement-breakpoint203CREATE INDEX "login_events_user_idx" ON "login_events" USING btree ("user_id","created_at");--> statement-breakpoint204CREATE INDEX "notifications_user_idx" ON "notifications" USING btree ("user_id","created_at");--> statement-breakpoint205CREATE INDEX "notifications_unread_idx" ON "notifications" USING btree ("user_id","read_at");--> statement-breakpoint206CREATE INDEX "price_targets_user_idx" ON "price_targets" USING btree ("user_id");--> statement-breakpoint207CREATE INDEX "price_targets_asset_idx" ON "price_targets" USING btree ("asset_id","hit_at");--> statement-breakpoint208CREATE INDEX "recovery_codes_user_idx" ON "recovery_codes" USING btree ("user_id");--> statement-breakpoint209CREATE INDEX "saved_searches_user_idx" ON "saved_searches" USING btree ("user_id");--> statement-breakpoint210CREATE INDEX "trusted_devices_user_idx" ON "trusted_devices" USING btree ("user_id");--> statement-breakpoint211CREATE UNIQUE INDEX "trusted_devices_token_uq" ON "trusted_devices" USING btree ("token_hash");--> statement-breakpoint212CREATE INDEX "uploads_user_idx" ON "uploads" USING btree ("user_id");--> statement-breakpoint213CREATE UNIQUE INDEX "user_badges_uq" ON "user_badges" USING btree ("user_id","badge");--> statement-breakpoint214CREATE UNIQUE INDEX "normalized_records_raw_uq" ON "normalized_records" USING btree ("raw_record_id","kind","seq");--> statement-breakpoint215ALTER TABLE "users" ADD CONSTRAINT "users_handle_unique" UNIQUE("handle");