| 1 | CREATE TABLE "build_component" (
|
|---|
| 2 | "build_id" integer NOT NULL,
|
|---|
| 3 | "component_id" integer NOT NULL,
|
|---|
| 4 | "num_components" integer DEFAULT 1 NOT NULL,
|
|---|
| 5 | CONSTRAINT "build_component_build_id_component_id_pk" PRIMARY KEY("build_id","component_id")
|
|---|
| 6 | );
|
|---|
| 7 | --> statement-breakpoint
|
|---|
| 8 | CREATE TABLE "build" (
|
|---|
| 9 | "id" serial PRIMARY KEY NOT NULL,
|
|---|
| 10 | "user_id" integer NOT NULL,
|
|---|
| 11 | "name" text NOT NULL,
|
|---|
| 12 | "created_at" date NOT NULL,
|
|---|
| 13 | "description" text,
|
|---|
| 14 | "total_price" numeric NOT NULL,
|
|---|
| 15 | "is_approved" boolean NOT NULL
|
|---|
| 16 | );
|
|---|
| 17 | --> statement-breakpoint
|
|---|
| 18 | CREATE TABLE "favorite_build" (
|
|---|
| 19 | "build_id" integer NOT NULL,
|
|---|
| 20 | "user_id" integer NOT NULL,
|
|---|
| 21 | CONSTRAINT "favorite_build_build_id_user_id_pk" PRIMARY KEY("build_id","user_id")
|
|---|
| 22 | );
|
|---|
| 23 | --> statement-breakpoint
|
|---|
| 24 | CREATE TABLE "rating_build" (
|
|---|
| 25 | "build_id" integer NOT NULL,
|
|---|
| 26 | "user_id" integer NOT NULL,
|
|---|
| 27 | "value" numeric NOT NULL,
|
|---|
| 28 | CONSTRAINT "rating_build_build_id_user_id_pk" PRIMARY KEY("build_id","user_id"),
|
|---|
| 29 | CONSTRAINT "check_value" CHECK ("rating_build"."value" BETWEEN 1 AND 5)
|
|---|
| 30 | );
|
|---|
| 31 | --> statement-breakpoint
|
|---|
| 32 | CREATE TABLE "review" (
|
|---|
| 33 | "id" serial PRIMARY KEY NOT NULL,
|
|---|
| 34 | "build_id" integer NOT NULL,
|
|---|
| 35 | "user_id" integer NOT NULL,
|
|---|
| 36 | "content" text NOT NULL,
|
|---|
| 37 | "created_at" date NOT NULL,
|
|---|
| 38 | CONSTRAINT "review_build_id_user_id_unique" UNIQUE("build_id","user_id")
|
|---|
| 39 | );
|
|---|
| 40 | --> statement-breakpoint
|
|---|
| 41 | CREATE TABLE "cpu" (
|
|---|
| 42 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 43 | "socket" text NOT NULL,
|
|---|
| 44 | "cores" integer NOT NULL,
|
|---|
| 45 | "threads" integer NOT NULL,
|
|---|
| 46 | "base_clock" numeric NOT NULL,
|
|---|
| 47 | "boost_clock" numeric,
|
|---|
| 48 | "tdp" numeric NOT NULL
|
|---|
| 49 | );
|
|---|
| 50 | --> statement-breakpoint
|
|---|
| 51 | CREATE TABLE "gpu" (
|
|---|
| 52 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 53 | "vram" numeric NOT NULL,
|
|---|
| 54 | "tdp" numeric NOT NULL,
|
|---|
| 55 | "base_clock" numeric,
|
|---|
| 56 | "boost_clock" numeric,
|
|---|
| 57 | "chipset" text NOT NULL,
|
|---|
| 58 | "length" numeric NOT NULL
|
|---|
| 59 | );
|
|---|
| 60 | --> statement-breakpoint
|
|---|
| 61 | CREATE TABLE "cables" (
|
|---|
| 62 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 63 | "length_cm" numeric NOT NULL,
|
|---|
| 64 | "type" text NOT NULL
|
|---|
| 65 | );
|
|---|
| 66 | --> statement-breakpoint
|
|---|
| 67 | CREATE TABLE "case_mobo_form_factors" (
|
|---|
| 68 | "case_id" integer NOT NULL,
|
|---|
| 69 | "form_factor" text NOT NULL,
|
|---|
| 70 | CONSTRAINT "case_mobo_form_factors_case_id_form_factor_pk" PRIMARY KEY("case_id","form_factor")
|
|---|
| 71 | );
|
|---|
| 72 | --> statement-breakpoint
|
|---|
| 73 | CREATE TABLE "case_ps_form_factors" (
|
|---|
| 74 | "case_id" integer NOT NULL,
|
|---|
| 75 | "form_factor" text NOT NULL,
|
|---|
| 76 | CONSTRAINT "case_ps_form_factors_case_id_form_factor_pk" PRIMARY KEY("case_id","form_factor")
|
|---|
| 77 | );
|
|---|
| 78 | --> statement-breakpoint
|
|---|
| 79 | CREATE TABLE "case_storage_form_factors" (
|
|---|
| 80 | "case_id" integer NOT NULL,
|
|---|
| 81 | "form_factor" text NOT NULL,
|
|---|
| 82 | "num_slots" integer NOT NULL,
|
|---|
| 83 | CONSTRAINT "case_storage_form_factors_case_id_form_factor_pk" PRIMARY KEY("case_id","form_factor")
|
|---|
| 84 | );
|
|---|
| 85 | --> statement-breakpoint
|
|---|
| 86 | CREATE TABLE "components" (
|
|---|
| 87 | "id" serial PRIMARY KEY NOT NULL,
|
|---|
| 88 | "name" text NOT NULL,
|
|---|
| 89 | "brand" text NOT NULL,
|
|---|
| 90 | "price" numeric NOT NULL,
|
|---|
| 91 | "img_url" text,
|
|---|
| 92 | "type" text NOT NULL,
|
|---|
| 93 | CONSTRAINT "check_type" CHECK ("components"."type" in
|
|---|
| 94 | ('cpu', 'gpu', 'memory', 'storage', 'power_supply', 'motherboard', 'case', 'cooler', 'memory_card', 'optical_drive', 'sound_card', 'cables', 'network_adapter', 'network_card'))
|
|---|
| 95 | );
|
|---|
| 96 | --> statement-breakpoint
|
|---|
| 97 | CREATE TABLE "cooler_cpu_sockets" (
|
|---|
| 98 | "cooler_id" integer NOT NULL,
|
|---|
| 99 | "socket" text NOT NULL,
|
|---|
| 100 | CONSTRAINT "cooler_cpu_sockets_cooler_id_socket_pk" PRIMARY KEY("cooler_id","socket")
|
|---|
| 101 | );
|
|---|
| 102 | --> statement-breakpoint
|
|---|
| 103 | CREATE TABLE "cooler" (
|
|---|
| 104 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 105 | "type" text NOT NULL,
|
|---|
| 106 | "height" numeric NOT NULL,
|
|---|
| 107 | "max_tdp_supported" numeric NOT NULL
|
|---|
| 108 | );
|
|---|
| 109 | --> statement-breakpoint
|
|---|
| 110 | CREATE TABLE "memory_card" (
|
|---|
| 111 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 112 | "num_slots" integer NOT NULL,
|
|---|
| 113 | "interface" text NOT NULL
|
|---|
| 114 | );
|
|---|
| 115 | --> statement-breakpoint
|
|---|
| 116 | CREATE TABLE "memory" (
|
|---|
| 117 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 118 | "type" text NOT NULL,
|
|---|
| 119 | "speed" numeric NOT NULL,
|
|---|
| 120 | "capacity" numeric NOT NULL,
|
|---|
| 121 | "modules" integer NOT NULL
|
|---|
| 122 | );
|
|---|
| 123 | --> statement-breakpoint
|
|---|
| 124 | CREATE TABLE "motherboard" (
|
|---|
| 125 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 126 | "socket" text NOT NULL,
|
|---|
| 127 | "chipset" text NOT NULL,
|
|---|
| 128 | "form_factor" text NOT NULL,
|
|---|
| 129 | "ram_type" text NOT NULL,
|
|---|
| 130 | "num_ram_slots" integer NOT NULL,
|
|---|
| 131 | "max_ram_capacity" numeric NOT NULL,
|
|---|
| 132 | "pci_express_slots" numeric NOT NULL
|
|---|
| 133 | );
|
|---|
| 134 | --> statement-breakpoint
|
|---|
| 135 | CREATE TABLE "network_adapter" (
|
|---|
| 136 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 137 | "wifi_version" text NOT NULL,
|
|---|
| 138 | "interface" text NOT NULL,
|
|---|
| 139 | "num_antennas" integer NOT NULL
|
|---|
| 140 | );
|
|---|
| 141 | --> statement-breakpoint
|
|---|
| 142 | CREATE TABLE "network_card" (
|
|---|
| 143 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 144 | "num_ports" integer NOT NULL,
|
|---|
| 145 | "speed" numeric NOT NULL,
|
|---|
| 146 | "interface" text NOT NULL
|
|---|
| 147 | );
|
|---|
| 148 | --> statement-breakpoint
|
|---|
| 149 | CREATE TABLE "optical_drive" (
|
|---|
| 150 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 151 | "form_factor" text NOT NULL,
|
|---|
| 152 | "type" text NOT NULL,
|
|---|
| 153 | "interface" text NOT NULL,
|
|---|
| 154 | "write_speed" numeric NOT NULL,
|
|---|
| 155 | "read_speed" numeric NOT NULL
|
|---|
| 156 | );
|
|---|
| 157 | --> statement-breakpoint
|
|---|
| 158 | CREATE TABLE "pc_case" (
|
|---|
| 159 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 160 | "cooler_max_height" numeric NOT NULL,
|
|---|
| 161 | "gpu_max_length" numeric NOT NULL
|
|---|
| 162 | );
|
|---|
| 163 | --> statement-breakpoint
|
|---|
| 164 | CREATE TABLE "power_supply" (
|
|---|
| 165 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 166 | "type" text NOT NULL,
|
|---|
| 167 | "wattage" numeric NOT NULL,
|
|---|
| 168 | "form_factor" text NOT NULL
|
|---|
| 169 | );
|
|---|
| 170 | --> statement-breakpoint
|
|---|
| 171 | CREATE TABLE "sound_card" (
|
|---|
| 172 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 173 | "sample_rate" numeric NOT NULL,
|
|---|
| 174 | "bit_depth" numeric NOT NULL,
|
|---|
| 175 | "chipset" text NOT NULL,
|
|---|
| 176 | "interface" text NOT NULL,
|
|---|
| 177 | "channel" text NOT NULL
|
|---|
| 178 | );
|
|---|
| 179 | --> statement-breakpoint
|
|---|
| 180 | CREATE TABLE "storage" (
|
|---|
| 181 | "component_id" integer PRIMARY KEY NOT NULL,
|
|---|
| 182 | "type" text NOT NULL,
|
|---|
| 183 | "capacity" numeric NOT NULL,
|
|---|
| 184 | "form_factor" text NOT NULL
|
|---|
| 185 | );
|
|---|
| 186 | --> statement-breakpoint
|
|---|
| 187 | CREATE TABLE "admins" (
|
|---|
| 188 | "user_id" integer PRIMARY KEY NOT NULL
|
|---|
| 189 | );
|
|---|
| 190 | --> statement-breakpoint
|
|---|
| 191 | CREATE TABLE "suggestions" (
|
|---|
| 192 | "id" serial PRIMARY KEY NOT NULL,
|
|---|
| 193 | "user_id" integer NOT NULL,
|
|---|
| 194 | "admin_id" integer,
|
|---|
| 195 | "link" text NOT NULL,
|
|---|
| 196 | "admin_comment" text,
|
|---|
| 197 | "description" text,
|
|---|
| 198 | "status" text DEFAULT 'pending' NOT NULL,
|
|---|
| 199 | "component_type" text NOT NULL,
|
|---|
| 200 | CONSTRAINT "check_status" CHECK ("suggestions"."status" in ('pending', 'approved', 'rejected')),
|
|---|
| 201 | CONSTRAINT "check_type" CHECK ("suggestions"."component_type" in
|
|---|
| 202 | ('cpu', 'gpu', 'memory', 'storage', 'power_supply', 'motherboard', 'case', 'cooler', 'memory_card', 'optical_drive', 'sound_card', 'cables', 'network_adapter', 'network_card'))
|
|---|
| 203 | );
|
|---|
| 204 | --> statement-breakpoint
|
|---|
| 205 | CREATE TABLE "users" (
|
|---|
| 206 | "id" serial PRIMARY KEY NOT NULL,
|
|---|
| 207 | "username" text NOT NULL,
|
|---|
| 208 | "password" text NOT NULL,
|
|---|
| 209 | "email" text NOT NULL,
|
|---|
| 210 | CONSTRAINT "users_username_unique" UNIQUE("username"),
|
|---|
| 211 | CONSTRAINT "users_email_unique" UNIQUE("email")
|
|---|
| 212 | );
|
|---|
| 213 | --> statement-breakpoint
|
|---|
| 214 | ALTER TABLE "build_component" ADD CONSTRAINT "build_component_build_id_build_id_fk" FOREIGN KEY ("build_id") REFERENCES "public"."build"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 215 | ALTER TABLE "build_component" ADD CONSTRAINT "build_component_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 216 | ALTER TABLE "build" ADD CONSTRAINT "build_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 217 | ALTER TABLE "favorite_build" ADD CONSTRAINT "favorite_build_build_id_build_id_fk" FOREIGN KEY ("build_id") REFERENCES "public"."build"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 218 | ALTER TABLE "favorite_build" ADD CONSTRAINT "favorite_build_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 219 | ALTER TABLE "rating_build" ADD CONSTRAINT "rating_build_build_id_build_id_fk" FOREIGN KEY ("build_id") REFERENCES "public"."build"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 220 | ALTER TABLE "rating_build" ADD CONSTRAINT "rating_build_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 221 | ALTER TABLE "review" ADD CONSTRAINT "review_build_id_build_id_fk" FOREIGN KEY ("build_id") REFERENCES "public"."build"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 222 | ALTER TABLE "review" ADD CONSTRAINT "review_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 223 | ALTER TABLE "cpu" ADD CONSTRAINT "cpu_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 224 | ALTER TABLE "gpu" ADD CONSTRAINT "gpu_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 225 | ALTER TABLE "cables" ADD CONSTRAINT "cables_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 226 | ALTER TABLE "case_mobo_form_factors" ADD CONSTRAINT "case_mobo_form_factors_case_id_pc_case_component_id_fk" FOREIGN KEY ("case_id") REFERENCES "public"."pc_case"("component_id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 227 | ALTER TABLE "case_ps_form_factors" ADD CONSTRAINT "case_ps_form_factors_case_id_pc_case_component_id_fk" FOREIGN KEY ("case_id") REFERENCES "public"."pc_case"("component_id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 228 | ALTER TABLE "case_storage_form_factors" ADD CONSTRAINT "case_storage_form_factors_case_id_pc_case_component_id_fk" FOREIGN KEY ("case_id") REFERENCES "public"."pc_case"("component_id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 229 | ALTER TABLE "cooler_cpu_sockets" ADD CONSTRAINT "cooler_cpu_sockets_cooler_id_cooler_component_id_fk" FOREIGN KEY ("cooler_id") REFERENCES "public"."cooler"("component_id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 230 | ALTER TABLE "cooler" ADD CONSTRAINT "cooler_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 231 | ALTER TABLE "memory_card" ADD CONSTRAINT "memory_card_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 232 | ALTER TABLE "memory" ADD CONSTRAINT "memory_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 233 | ALTER TABLE "motherboard" ADD CONSTRAINT "motherboard_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 234 | ALTER TABLE "network_adapter" ADD CONSTRAINT "network_adapter_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 235 | ALTER TABLE "network_card" ADD CONSTRAINT "network_card_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 236 | ALTER TABLE "optical_drive" ADD CONSTRAINT "optical_drive_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 237 | ALTER TABLE "pc_case" ADD CONSTRAINT "pc_case_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 238 | ALTER TABLE "power_supply" ADD CONSTRAINT "power_supply_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 239 | ALTER TABLE "sound_card" ADD CONSTRAINT "sound_card_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 240 | ALTER TABLE "storage" ADD CONSTRAINT "storage_component_id_components_id_fk" FOREIGN KEY ("component_id") REFERENCES "public"."components"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 241 | ALTER TABLE "admins" ADD CONSTRAINT "admins_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 242 | ALTER TABLE "suggestions" ADD CONSTRAINT "suggestions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
|
|---|
| 243 | ALTER TABLE "suggestions" ADD CONSTRAINT "suggestions_admin_id_admins_user_id_fk" FOREIGN KEY ("admin_id") REFERENCES "public"."admins"("user_id") ON DELETE set null ON UPDATE cascade; |
|---|