GitHub Actions commited on
Commit
e02c37d
·
1 Parent(s): c925062

Deploy from GitHub main

Browse files
Files changed (1) hide show
  1. supabase/migrations/public_schema.sql +796 -0
supabase/migrations/public_schema.sql ADDED
@@ -0,0 +1,796 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --
2
+ -- PostgreSQL database dump
3
+ --
4
+
5
+ \restrict mmwJKwqjeA3JVtIaidbJLdgw9PKc68S0JUhcgqBdfGktidQ8SzpvG9rGb4KqLiH
6
+
7
+ -- Dumped from database version 17.6
8
+ -- Dumped by pg_dump version 18.6 (Ubuntu 18.6-0ubuntu0.26.04.1)
9
+
10
+ SET statement_timeout = 0;
11
+ SET lock_timeout = 0;
12
+ SET idle_in_transaction_session_timeout = 0;
13
+ SET transaction_timeout = 0;
14
+ SET client_encoding = 'UTF8';
15
+ SET standard_conforming_strings = on;
16
+ SELECT pg_catalog.set_config('search_path', '', false);
17
+ SET check_function_bodies = false;
18
+ SET xmloption = content;
19
+ SET client_min_messages = warning;
20
+ SET row_security = off;
21
+
22
+ --
23
+ -- Name: public; Type: SCHEMA; Schema: -; Owner: -
24
+ --
25
+
26
+ CREATE SCHEMA public;
27
+
28
+
29
+ --
30
+ -- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: -
31
+ --
32
+
33
+ COMMENT ON SCHEMA public IS 'standard public schema';
34
+
35
+
36
+ --
37
+ -- Name: departure_bucket_clock_time(text); Type: FUNCTION; Schema: public; Owner: -
38
+ --
39
+
40
+ CREATE FUNCTION public.departure_bucket_clock_time(bucket text) RETURNS time without time zone
41
+ LANGUAGE sql IMMUTABLE
42
+ AS $$
43
+ select case bucket
44
+ when 'morning' then time '06:00'
45
+ when 'noon' then time '12:00'
46
+ when 'night' then time '18:00'
47
+ else null
48
+ end;
49
+ $$;
50
+
51
+
52
+ --
53
+ -- Name: match_active_trips(extensions.vector, double precision, integer, text, text, text, date, text, time without time zone, integer, text); Type: FUNCTION; Schema: public; Owner: -
54
+ --
55
+
56
+ CREATE FUNCTION public.match_active_trips(query_embedding extensions.vector, match_threshold double precision DEFAULT 0.0, match_count integer DEFAULT 10, filter_departure text DEFAULT NULL::text, filter_destination text DEFAULT NULL::text, filter_driver_name text DEFAULT NULL::text, filter_departure_date date DEFAULT NULL::date, filter_departure_time text DEFAULT NULL::text, filter_requested_time time without time zone DEFAULT NULL::time without time zone, filter_seats integer DEFAULT 1, filter_vehicle_type text DEFAULT NULL::text) RETURNS TABLE(trip_id uuid, departure text, destination text, departure_date date, departure_time text, available_seats integer, total_seats integer, price numeric, status text, driver_name text, driver_phone_number text, car_type text, chunk_text text, similarity double precision, time_difference_minutes integer, registered boolean)
57
+ LANGUAGE sql STABLE
58
+ AS $$
59
+ WITH ranked AS (
60
+ SELECT
61
+ driver_trips.id AS trip_id,
62
+ driver_trips.departure,
63
+ driver_trips.destination,
64
+ driver_trips.departure_date,
65
+ driver_trips.departure_time,
66
+ driver_trips.available_seats,
67
+ driver_trips.total_seats,
68
+ driver_trips.price,
69
+ driver_trips.status,
70
+ customers.name AS driver_name,
71
+ customers."remoteJid" AS driver_phone_number,
72
+ driver_cars.car_type,
73
+ driver_trip_embeddings.chunk_text,
74
+ COALESCE(customers.registered, false) AS registered,
75
+ 1 - (driver_trip_embeddings.embedding <=> query_embedding) AS similarity,
76
+ driver_trip_embeddings.embedding <=> query_embedding AS vector_distance,
77
+ CASE
78
+ WHEN filter_requested_time IS NULL THEN NULL
79
+ ELSE abs(
80
+ extract(epoch FROM (
81
+ public.departure_bucket_clock_time(driver_trips.departure_time)
82
+ - filter_requested_time
83
+ )) / 60
84
+ )::integer
85
+ END AS time_difference_minutes
86
+ FROM public.driver_trip_embeddings
87
+ JOIN public.driver_trips ON driver_trips.id = driver_trip_embeddings.trip_id
88
+ LEFT JOIN public.drivers ON drivers.id = driver_trips.driver_id
89
+ LEFT JOIN public.customers ON customers.id = drivers.customer_id
90
+ LEFT JOIN public.driver_cars ON driver_cars.id = driver_trips.car_id
91
+ WHERE driver_trips.status = 'active'
92
+ AND (driver_trips.available_seats IS NULL OR driver_trips.available_seats >= COALESCE(filter_seats, 1))
93
+ AND (filter_departure IS NULL OR driver_trips.departure ILIKE '%' || filter_departure || '%')
94
+ AND (filter_destination IS NULL OR driver_trips.destination ILIKE '%' || filter_destination || '%')
95
+ AND (filter_driver_name IS NULL OR customers.name ILIKE '%' || filter_driver_name || '%')
96
+ AND (filter_departure_date IS NULL OR driver_trips.departure_date = filter_departure_date)
97
+ AND (filter_departure_time IS NULL OR driver_trips.departure_time = filter_departure_time)
98
+ AND (filter_vehicle_type IS NULL OR driver_cars.car_type ILIKE '%' || filter_vehicle_type || '%')
99
+ AND (
100
+ driver_trips.departure_date > (NOW() AT TIME ZONE 'Asia/Aden')::date
101
+ OR (
102
+ driver_trips.departure_date = (NOW() AT TIME ZONE 'Asia/Aden')::date
103
+ AND (
104
+ (NOW() AT TIME ZONE 'Asia/Aden')::time < TIME '12:00'
105
+ OR (
106
+ (NOW() AT TIME ZONE 'Asia/Aden')::time < TIME '18:00'
107
+ AND driver_trips.departure_time IN ('noon', 'night')
108
+ )
109
+ OR (
110
+ (NOW() AT TIME ZONE 'Asia/Aden')::time >= TIME '18:00'
111
+ AND driver_trips.departure_time = 'night'
112
+ )
113
+ )
114
+ )
115
+ )
116
+ )
117
+ SELECT
118
+ ranked.trip_id,
119
+ ranked.departure,
120
+ ranked.destination,
121
+ ranked.departure_date,
122
+ ranked.departure_time,
123
+ ranked.available_seats,
124
+ ranked.total_seats,
125
+ ranked.price,
126
+ ranked.status,
127
+ ranked.driver_name,
128
+ ranked.driver_phone_number,
129
+ ranked.car_type,
130
+ ranked.chunk_text,
131
+ ranked.similarity,
132
+ ranked.time_difference_minutes,
133
+ ranked.registered
134
+ FROM ranked
135
+ WHERE ranked.similarity >= match_threshold
136
+ ORDER BY
137
+ ranked.registered DESC,
138
+ ranked.time_difference_minutes NULLS LAST,
139
+ ranked.departure_date,
140
+ ranked.vector_distance
141
+ LIMIT match_count;
142
+ $$;
143
+
144
+
145
+ --
146
+ -- Name: match_falzh_info(extensions.vector, double precision, integer); Type: FUNCTION; Schema: public; Owner: -
147
+ --
148
+
149
+ CREATE FUNCTION public.match_falzh_info(query_embedding extensions.vector, match_threshold double precision DEFAULT 0.0, match_count integer DEFAULT 5) RETURNS TABLE(id text, chunk_text text, source text, similarity double precision)
150
+ LANGUAGE sql STABLE
151
+ AS $$
152
+ select
153
+ falzh_info_chunks.id,
154
+ falzh_info_chunks.chunk_text,
155
+ falzh_info_chunks.source,
156
+ 1 - (falzh_info_chunks.embedding <=> query_embedding) as similarity
157
+ from public.falzh_info_chunks
158
+ where 1 - (falzh_info_chunks.embedding <=> query_embedding) >= match_threshold
159
+ order by falzh_info_chunks.embedding <=> query_embedding
160
+ limit match_count;
161
+ $$;
162
+
163
+
164
+ --
165
+ -- Name: rls_auto_enable(); Type: FUNCTION; Schema: public; Owner: -
166
+ --
167
+
168
+ CREATE FUNCTION public.rls_auto_enable() RETURNS event_trigger
169
+ LANGUAGE plpgsql SECURITY DEFINER
170
+ SET search_path TO 'pg_catalog'
171
+ AS $$
172
+ DECLARE
173
+ cmd record;
174
+ BEGIN
175
+ FOR cmd IN
176
+ SELECT *
177
+ FROM pg_event_trigger_ddl_commands()
178
+ WHERE command_tag IN ('CREATE TABLE', 'CREATE TABLE AS', 'SELECT INTO')
179
+ AND object_type IN ('table','partitioned table')
180
+ LOOP
181
+ IF cmd.schema_name IS NOT NULL AND cmd.schema_name IN ('public') AND cmd.schema_name NOT IN ('pg_catalog','information_schema') AND cmd.schema_name NOT LIKE 'pg_toast%' AND cmd.schema_name NOT LIKE 'pg_temp%' THEN
182
+ BEGIN
183
+ EXECUTE format('alter table if exists %s enable row level security', cmd.object_identity);
184
+ RAISE LOG 'rls_auto_enable: enabled RLS on %', cmd.object_identity;
185
+ EXCEPTION
186
+ WHEN OTHERS THEN
187
+ RAISE LOG 'rls_auto_enable: failed to enable RLS on %', cmd.object_identity;
188
+ END;
189
+ ELSE
190
+ RAISE LOG 'rls_auto_enable: skip % (either system schema or not in enforced list: %.)', cmd.object_identity, cmd.schema_name;
191
+ END IF;
192
+ END LOOP;
193
+ END;
194
+ $$;
195
+
196
+
197
+ --
198
+ -- Name: set_updated_at(); Type: FUNCTION; Schema: public; Owner: -
199
+ --
200
+
201
+ CREATE FUNCTION public.set_updated_at() RETURNS trigger
202
+ LANGUAGE plpgsql
203
+ AS $$
204
+ begin
205
+ new.updated_at = now();
206
+ return new;
207
+ end;
208
+ $$;
209
+
210
+
211
+ SET default_tablespace = '';
212
+
213
+ SET default_table_access_method = heap;
214
+
215
+ --
216
+ -- Name: customers; Type: TABLE; Schema: public; Owner: -
217
+ --
218
+
219
+ CREATE TABLE public.customers (
220
+ id uuid DEFAULT gen_random_uuid() NOT NULL,
221
+ name text,
222
+ "remoteJid" text,
223
+ preferred_language text,
224
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
225
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
226
+ user_mode text,
227
+ phone_number text,
228
+ session_data jsonb DEFAULT '{}'::jsonb NOT NULL,
229
+ registered boolean DEFAULT false NOT NULL,
230
+ CONSTRAINT customers_preferred_language_check CHECK ((preferred_language = ANY (ARRAY['ar'::text, 'en'::text]))),
231
+ CONSTRAINT customers_user_mode_check CHECK ((user_mode = ANY (ARRAY['driver'::text, 'passenger'::text])))
232
+ );
233
+
234
+
235
+ --
236
+ -- Name: driver_cars; Type: TABLE; Schema: public; Owner: -
237
+ --
238
+
239
+ CREATE TABLE public.driver_cars (
240
+ id uuid DEFAULT gen_random_uuid() NOT NULL,
241
+ driver_id uuid NOT NULL,
242
+ car_type text NOT NULL,
243
+ plate_number text,
244
+ seat_count integer,
245
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
246
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
247
+ CONSTRAINT driver_cars_seat_count_check CHECK ((seat_count > 0))
248
+ );
249
+
250
+
251
+ --
252
+ -- Name: driver_trip_embeddings; Type: TABLE; Schema: public; Owner: -
253
+ --
254
+
255
+ CREATE TABLE public.driver_trip_embeddings (
256
+ trip_id uuid NOT NULL,
257
+ chunk_text text NOT NULL,
258
+ embedding extensions.vector(1024) NOT NULL,
259
+ embedding_model text NOT NULL,
260
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
261
+ updated_at timestamp with time zone DEFAULT now() NOT NULL
262
+ );
263
+
264
+
265
+ --
266
+ -- Name: driver_trips; Type: TABLE; Schema: public; Owner: -
267
+ --
268
+
269
+ CREATE TABLE public.driver_trips (
270
+ id uuid DEFAULT gen_random_uuid() NOT NULL,
271
+ driver_id uuid NOT NULL,
272
+ car_id uuid,
273
+ departure text NOT NULL,
274
+ destination text NOT NULL,
275
+ available_seats integer,
276
+ total_seats integer,
277
+ price numeric(12,2) NOT NULL,
278
+ status text DEFAULT 'active'::text NOT NULL,
279
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
280
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
281
+ departure_date date NOT NULL,
282
+ departure_time text NOT NULL,
283
+ driver_message text,
284
+ use_driver_message boolean DEFAULT false NOT NULL,
285
+ CONSTRAINT driver_trips_available_not_over_total CHECK (((available_seats IS NULL) OR (total_seats IS NULL) OR (available_seats <= total_seats))),
286
+ CONSTRAINT driver_trips_available_seats_check CHECK ((available_seats >= 0)),
287
+ CONSTRAINT driver_trips_departure_time_check CHECK ((departure_time = ANY (ARRAY['morning'::text, 'noon'::text, 'night'::text]))),
288
+ CONSTRAINT driver_trips_price_check CHECK ((price >= (0)::numeric)),
289
+ CONSTRAINT driver_trips_status_check CHECK ((status = ANY (ARRAY['active'::text, 'cancelled'::text, 'completed'::text]))),
290
+ CONSTRAINT driver_trips_total_seats_check CHECK ((total_seats > 0))
291
+ );
292
+
293
+
294
+ --
295
+ -- Name: driver_wallet; Type: TABLE; Schema: public; Owner: -
296
+ --
297
+
298
+ CREATE TABLE public.driver_wallet (
299
+ id uuid DEFAULT gen_random_uuid() NOT NULL,
300
+ driver_id uuid NOT NULL,
301
+ balance numeric(12,2) DEFAULT 0 NOT NULL,
302
+ last_updated timestamp with time zone DEFAULT now() NOT NULL
303
+ );
304
+
305
+
306
+ --
307
+ -- Name: drivers; Type: TABLE; Schema: public; Owner: -
308
+ --
309
+
310
+ CREATE TABLE public.drivers (
311
+ id uuid DEFAULT gen_random_uuid() NOT NULL,
312
+ status text DEFAULT 'active'::text NOT NULL,
313
+ rating numeric(3,2),
314
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
315
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
316
+ customer_id uuid NOT NULL,
317
+ CONSTRAINT drivers_status_check CHECK ((status = ANY (ARRAY['active'::text, 'inactive'::text, 'suspended'::text])))
318
+ );
319
+
320
+
321
+ --
322
+ -- Name: falzh_info_chunks; Type: TABLE; Schema: public; Owner: -
323
+ --
324
+
325
+ CREATE TABLE public.falzh_info_chunks (
326
+ id text NOT NULL,
327
+ chunk_text text NOT NULL,
328
+ source text,
329
+ embedding extensions.vector(1024) NOT NULL,
330
+ embedding_model text NOT NULL,
331
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
332
+ updated_at timestamp with time zone DEFAULT now() NOT NULL
333
+ );
334
+
335
+
336
+ --
337
+ -- Name: messages; Type: TABLE; Schema: public; Owner: -
338
+ --
339
+
340
+ CREATE TABLE public.messages (
341
+ id uuid DEFAULT gen_random_uuid() NOT NULL,
342
+ customer_id uuid NOT NULL,
343
+ sender_type text NOT NULL,
344
+ message text NOT NULL,
345
+ whatsapp_message_id text,
346
+ metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
347
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
348
+ CONSTRAINT messages_sender_type_check CHECK ((sender_type = ANY (ARRAY['customer'::text, 'assistant'::text, 'driver'::text, 'system'::text])))
349
+ );
350
+
351
+
352
+ --
353
+ -- Name: trip_selections; Type: TABLE; Schema: public; Owner: -
354
+ --
355
+
356
+ CREATE TABLE public.trip_selections (
357
+ id uuid DEFAULT gen_random_uuid() NOT NULL,
358
+ customer_id uuid NOT NULL,
359
+ trip_id uuid NOT NULL,
360
+ requested_seats integer NOT NULL,
361
+ status text DEFAULT 'pending'::text NOT NULL,
362
+ notes text,
363
+ driver_notification_status text DEFAULT 'not_sent'::text NOT NULL,
364
+ metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
365
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
366
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
367
+ CONSTRAINT booking_leads_driver_notification_status_check CHECK ((driver_notification_status = ANY (ARRAY['not_sent'::text, 'sent'::text, 'failed'::text]))),
368
+ CONSTRAINT booking_leads_requested_seats_check CHECK ((requested_seats > 0)),
369
+ CONSTRAINT trip_selections_status_check CHECK ((status = ANY (ARRAY['pending'::text, 'cancelled'::text])))
370
+ );
371
+
372
+
373
+ --
374
+ -- Name: users; Type: TABLE; Schema: public; Owner: -
375
+ --
376
+
377
+ CREATE TABLE public.users (
378
+ remote_jid text NOT NULL,
379
+ remote_jid_alt text,
380
+ created_at timestamp with time zone DEFAULT timezone('utc'::text, now()) NOT NULL
381
+ );
382
+
383
+
384
+ --
385
+ -- Name: whatsapp_auth_prod; Type: TABLE; Schema: public; Owner: -
386
+ --
387
+
388
+ CREATE TABLE public.whatsapp_auth_prod (
389
+ id text NOT NULL,
390
+ data jsonb NOT NULL,
391
+ updated_at timestamp with time zone DEFAULT timezone('utc'::text, now()) NOT NULL
392
+ );
393
+
394
+
395
+ --
396
+ -- Name: whatsapp_auth_test; Type: TABLE; Schema: public; Owner: -
397
+ --
398
+
399
+ CREATE TABLE public.whatsapp_auth_test (
400
+ id text NOT NULL,
401
+ data jsonb NOT NULL,
402
+ updated_at timestamp with time zone DEFAULT now()
403
+ );
404
+
405
+
406
+ --
407
+ -- Name: trip_selections booking_leads_pkey; Type: CONSTRAINT; Schema: public; Owner: -
408
+ --
409
+
410
+ ALTER TABLE ONLY public.trip_selections
411
+ ADD CONSTRAINT booking_leads_pkey PRIMARY KEY (id);
412
+
413
+
414
+ --
415
+ -- Name: customers customers_phone_number_key; Type: CONSTRAINT; Schema: public; Owner: -
416
+ --
417
+
418
+ ALTER TABLE ONLY public.customers
419
+ ADD CONSTRAINT customers_phone_number_key UNIQUE ("remoteJid");
420
+
421
+
422
+ --
423
+ -- Name: customers customers_pkey; Type: CONSTRAINT; Schema: public; Owner: -
424
+ --
425
+
426
+ ALTER TABLE ONLY public.customers
427
+ ADD CONSTRAINT customers_pkey PRIMARY KEY (id);
428
+
429
+
430
+ --
431
+ -- Name: driver_cars driver_cars_pkey; Type: CONSTRAINT; Schema: public; Owner: -
432
+ --
433
+
434
+ ALTER TABLE ONLY public.driver_cars
435
+ ADD CONSTRAINT driver_cars_pkey PRIMARY KEY (id);
436
+
437
+
438
+ --
439
+ -- Name: driver_cars driver_cars_plate_number_key; Type: CONSTRAINT; Schema: public; Owner: -
440
+ --
441
+
442
+ ALTER TABLE ONLY public.driver_cars
443
+ ADD CONSTRAINT driver_cars_plate_number_key UNIQUE (plate_number);
444
+
445
+
446
+ --
447
+ -- Name: driver_trip_embeddings driver_trip_embeddings_pkey; Type: CONSTRAINT; Schema: public; Owner: -
448
+ --
449
+
450
+ ALTER TABLE ONLY public.driver_trip_embeddings
451
+ ADD CONSTRAINT driver_trip_embeddings_pkey PRIMARY KEY (trip_id);
452
+
453
+
454
+ --
455
+ -- Name: driver_trips driver_trips_pkey; Type: CONSTRAINT; Schema: public; Owner: -
456
+ --
457
+
458
+ ALTER TABLE ONLY public.driver_trips
459
+ ADD CONSTRAINT driver_trips_pkey PRIMARY KEY (id);
460
+
461
+
462
+ --
463
+ -- Name: driver_wallet driver_wallet_driver_id_key; Type: CONSTRAINT; Schema: public; Owner: -
464
+ --
465
+
466
+ ALTER TABLE ONLY public.driver_wallet
467
+ ADD CONSTRAINT driver_wallet_driver_id_key UNIQUE (driver_id);
468
+
469
+
470
+ --
471
+ -- Name: driver_wallet driver_wallet_pkey; Type: CONSTRAINT; Schema: public; Owner: -
472
+ --
473
+
474
+ ALTER TABLE ONLY public.driver_wallet
475
+ ADD CONSTRAINT driver_wallet_pkey PRIMARY KEY (id);
476
+
477
+
478
+ --
479
+ -- Name: drivers drivers_customer_id_key; Type: CONSTRAINT; Schema: public; Owner: -
480
+ --
481
+
482
+ ALTER TABLE ONLY public.drivers
483
+ ADD CONSTRAINT drivers_customer_id_key UNIQUE (customer_id);
484
+
485
+
486
+ --
487
+ -- Name: drivers drivers_pkey; Type: CONSTRAINT; Schema: public; Owner: -
488
+ --
489
+
490
+ ALTER TABLE ONLY public.drivers
491
+ ADD CONSTRAINT drivers_pkey PRIMARY KEY (id);
492
+
493
+
494
+ --
495
+ -- Name: falzh_info_chunks falsa_info_chunks_pkey; Type: CONSTRAINT; Schema: public; Owner: -
496
+ --
497
+
498
+ ALTER TABLE ONLY public.falzh_info_chunks
499
+ ADD CONSTRAINT falsa_info_chunks_pkey PRIMARY KEY (id);
500
+
501
+
502
+ --
503
+ -- Name: messages messages_pkey; Type: CONSTRAINT; Schema: public; Owner: -
504
+ --
505
+
506
+ ALTER TABLE ONLY public.messages
507
+ ADD CONSTRAINT messages_pkey PRIMARY KEY (id);
508
+
509
+
510
+ --
511
+ -- Name: messages messages_whatsapp_message_id_key; Type: CONSTRAINT; Schema: public; Owner: -
512
+ --
513
+
514
+ ALTER TABLE ONLY public.messages
515
+ ADD CONSTRAINT messages_whatsapp_message_id_key UNIQUE (whatsapp_message_id);
516
+
517
+
518
+ --
519
+ -- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
520
+ --
521
+
522
+ ALTER TABLE ONLY public.users
523
+ ADD CONSTRAINT users_pkey PRIMARY KEY (remote_jid);
524
+
525
+
526
+ --
527
+ -- Name: whatsapp_auth_prod whatsapp_auth_pkey; Type: CONSTRAINT; Schema: public; Owner: -
528
+ --
529
+
530
+ ALTER TABLE ONLY public.whatsapp_auth_prod
531
+ ADD CONSTRAINT whatsapp_auth_pkey PRIMARY KEY (id);
532
+
533
+
534
+ --
535
+ -- Name: whatsapp_auth_test whatsapp_auth_test_pkey; Type: CONSTRAINT; Schema: public; Owner: -
536
+ --
537
+
538
+ ALTER TABLE ONLY public.whatsapp_auth_test
539
+ ADD CONSTRAINT whatsapp_auth_test_pkey PRIMARY KEY (id);
540
+
541
+
542
+ --
543
+ -- Name: idx_customers_phone_number; Type: INDEX; Schema: public; Owner: -
544
+ --
545
+
546
+ CREATE INDEX idx_customers_phone_number ON public.customers USING btree (phone_number);
547
+
548
+
549
+ --
550
+ -- Name: idx_driver_trip_embeddings_embedding; Type: INDEX; Schema: public; Owner: -
551
+ --
552
+
553
+ CREATE INDEX idx_driver_trip_embeddings_embedding ON public.driver_trip_embeddings USING hnsw (embedding extensions.vector_cosine_ops);
554
+
555
+
556
+ --
557
+ -- Name: idx_driver_trips_active_route; Type: INDEX; Schema: public; Owner: -
558
+ --
559
+
560
+ CREATE INDEX idx_driver_trips_active_route ON public.driver_trips USING btree (status, departure, destination, departure_date, departure_time);
561
+
562
+
563
+ --
564
+ -- Name: idx_falzh_info_chunks_embedding; Type: INDEX; Schema: public; Owner: -
565
+ --
566
+
567
+ CREATE INDEX idx_falzh_info_chunks_embedding ON public.falzh_info_chunks USING hnsw (embedding extensions.vector_cosine_ops);
568
+
569
+
570
+ --
571
+ -- Name: idx_messages_customer_created_at; Type: INDEX; Schema: public; Owner: -
572
+ --
573
+
574
+ CREATE INDEX idx_messages_customer_created_at ON public.messages USING btree (customer_id, created_at DESC);
575
+
576
+
577
+ --
578
+ -- Name: idx_trip_selections_customer; Type: INDEX; Schema: public; Owner: -
579
+ --
580
+
581
+ CREATE INDEX idx_trip_selections_customer ON public.trip_selections USING btree (customer_id, created_at DESC);
582
+
583
+
584
+ --
585
+ -- Name: idx_trip_selections_trip; Type: INDEX; Schema: public; Owner: -
586
+ --
587
+
588
+ CREATE INDEX idx_trip_selections_trip ON public.trip_selections USING btree (trip_id, created_at DESC);
589
+
590
+
591
+ --
592
+ -- Name: idx_whatsapp_auth_test_updated_at; Type: INDEX; Schema: public; Owner: -
593
+ --
594
+
595
+ CREATE INDEX idx_whatsapp_auth_test_updated_at ON public.whatsapp_auth_test USING btree (updated_at);
596
+
597
+
598
+ --
599
+ -- Name: customers set_customers_updated_at; Type: TRIGGER; Schema: public; Owner: -
600
+ --
601
+
602
+ CREATE TRIGGER set_customers_updated_at BEFORE UPDATE ON public.customers FOR EACH ROW EXECUTE FUNCTION public.set_updated_at();
603
+
604
+
605
+ --
606
+ -- Name: driver_cars set_driver_cars_updated_at; Type: TRIGGER; Schema: public; Owner: -
607
+ --
608
+
609
+ CREATE TRIGGER set_driver_cars_updated_at BEFORE UPDATE ON public.driver_cars FOR EACH ROW EXECUTE FUNCTION public.set_updated_at();
610
+
611
+
612
+ --
613
+ -- Name: driver_trip_embeddings set_driver_trip_embeddings_updated_at; Type: TRIGGER; Schema: public; Owner: -
614
+ --
615
+
616
+ CREATE TRIGGER set_driver_trip_embeddings_updated_at BEFORE UPDATE ON public.driver_trip_embeddings FOR EACH ROW EXECUTE FUNCTION public.set_updated_at();
617
+
618
+
619
+ --
620
+ -- Name: driver_trips set_driver_trips_updated_at; Type: TRIGGER; Schema: public; Owner: -
621
+ --
622
+
623
+ CREATE TRIGGER set_driver_trips_updated_at BEFORE UPDATE ON public.driver_trips FOR EACH ROW EXECUTE FUNCTION public.set_updated_at();
624
+
625
+
626
+ --
627
+ -- Name: drivers set_drivers_updated_at; Type: TRIGGER; Schema: public; Owner: -
628
+ --
629
+
630
+ CREATE TRIGGER set_drivers_updated_at BEFORE UPDATE ON public.drivers FOR EACH ROW EXECUTE FUNCTION public.set_updated_at();
631
+
632
+
633
+ --
634
+ -- Name: falzh_info_chunks set_falzh_info_chunks_updated_at; Type: TRIGGER; Schema: public; Owner: -
635
+ --
636
+
637
+ CREATE TRIGGER set_falzh_info_chunks_updated_at BEFORE UPDATE ON public.falzh_info_chunks FOR EACH ROW EXECUTE FUNCTION public.set_updated_at();
638
+
639
+
640
+ --
641
+ -- Name: trip_selections set_trip_selections_updated_at; Type: TRIGGER; Schema: public; Owner: -
642
+ --
643
+
644
+ CREATE TRIGGER set_trip_selections_updated_at BEFORE UPDATE ON public.trip_selections FOR EACH ROW EXECUTE FUNCTION public.set_updated_at();
645
+
646
+
647
+ --
648
+ -- Name: trip_selections booking_leads_customer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
649
+ --
650
+
651
+ ALTER TABLE ONLY public.trip_selections
652
+ ADD CONSTRAINT booking_leads_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES public.customers(id) ON DELETE CASCADE;
653
+
654
+
655
+ --
656
+ -- Name: trip_selections booking_leads_trip_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
657
+ --
658
+
659
+ ALTER TABLE ONLY public.trip_selections
660
+ ADD CONSTRAINT booking_leads_trip_id_fkey FOREIGN KEY (trip_id) REFERENCES public.driver_trips(id) ON DELETE RESTRICT;
661
+
662
+
663
+ --
664
+ -- Name: driver_cars driver_cars_driver_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
665
+ --
666
+
667
+ ALTER TABLE ONLY public.driver_cars
668
+ ADD CONSTRAINT driver_cars_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES public.drivers(id) ON DELETE CASCADE;
669
+
670
+
671
+ --
672
+ -- Name: driver_trip_embeddings driver_trip_embeddings_trip_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
673
+ --
674
+
675
+ ALTER TABLE ONLY public.driver_trip_embeddings
676
+ ADD CONSTRAINT driver_trip_embeddings_trip_id_fkey FOREIGN KEY (trip_id) REFERENCES public.driver_trips(id) ON DELETE CASCADE;
677
+
678
+
679
+ --
680
+ -- Name: driver_trips driver_trips_car_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
681
+ --
682
+
683
+ ALTER TABLE ONLY public.driver_trips
684
+ ADD CONSTRAINT driver_trips_car_id_fkey FOREIGN KEY (car_id) REFERENCES public.driver_cars(id) ON DELETE SET NULL;
685
+
686
+
687
+ --
688
+ -- Name: driver_trips driver_trips_driver_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
689
+ --
690
+
691
+ ALTER TABLE ONLY public.driver_trips
692
+ ADD CONSTRAINT driver_trips_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES public.drivers(id) ON DELETE CASCADE;
693
+
694
+
695
+ --
696
+ -- Name: driver_wallet driver_wallet_driver_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
697
+ --
698
+
699
+ ALTER TABLE ONLY public.driver_wallet
700
+ ADD CONSTRAINT driver_wallet_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES public.drivers(id) ON DELETE CASCADE;
701
+
702
+
703
+ --
704
+ -- Name: drivers drivers_customer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
705
+ --
706
+
707
+ ALTER TABLE ONLY public.drivers
708
+ ADD CONSTRAINT drivers_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES public.customers(id) ON DELETE CASCADE;
709
+
710
+
711
+ --
712
+ -- Name: messages messages_customer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
713
+ --
714
+
715
+ ALTER TABLE ONLY public.messages
716
+ ADD CONSTRAINT messages_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES public.customers(id) ON DELETE CASCADE;
717
+
718
+
719
+ --
720
+ -- Name: customers; Type: ROW SECURITY; Schema: public; Owner: -
721
+ --
722
+
723
+ ALTER TABLE public.customers ENABLE ROW LEVEL SECURITY;
724
+
725
+ --
726
+ -- Name: driver_cars; Type: ROW SECURITY; Schema: public; Owner: -
727
+ --
728
+
729
+ ALTER TABLE public.driver_cars ENABLE ROW LEVEL SECURITY;
730
+
731
+ --
732
+ -- Name: driver_trip_embeddings; Type: ROW SECURITY; Schema: public; Owner: -
733
+ --
734
+
735
+ ALTER TABLE public.driver_trip_embeddings ENABLE ROW LEVEL SECURITY;
736
+
737
+ --
738
+ -- Name: driver_trips; Type: ROW SECURITY; Schema: public; Owner: -
739
+ --
740
+
741
+ ALTER TABLE public.driver_trips ENABLE ROW LEVEL SECURITY;
742
+
743
+ --
744
+ -- Name: driver_wallet; Type: ROW SECURITY; Schema: public; Owner: -
745
+ --
746
+
747
+ ALTER TABLE public.driver_wallet ENABLE ROW LEVEL SECURITY;
748
+
749
+ --
750
+ -- Name: drivers; Type: ROW SECURITY; Schema: public; Owner: -
751
+ --
752
+
753
+ ALTER TABLE public.drivers ENABLE ROW LEVEL SECURITY;
754
+
755
+ --
756
+ -- Name: falzh_info_chunks; Type: ROW SECURITY; Schema: public; Owner: -
757
+ --
758
+
759
+ ALTER TABLE public.falzh_info_chunks ENABLE ROW LEVEL SECURITY;
760
+
761
+ --
762
+ -- Name: messages; Type: ROW SECURITY; Schema: public; Owner: -
763
+ --
764
+
765
+ ALTER TABLE public.messages ENABLE ROW LEVEL SECURITY;
766
+
767
+ --
768
+ -- Name: trip_selections; Type: ROW SECURITY; Schema: public; Owner: -
769
+ --
770
+
771
+ ALTER TABLE public.trip_selections ENABLE ROW LEVEL SECURITY;
772
+
773
+ --
774
+ -- Name: users; Type: ROW SECURITY; Schema: public; Owner: -
775
+ --
776
+
777
+ ALTER TABLE public.users ENABLE ROW LEVEL SECURITY;
778
+
779
+ --
780
+ -- Name: whatsapp_auth_prod; Type: ROW SECURITY; Schema: public; Owner: -
781
+ --
782
+
783
+ ALTER TABLE public.whatsapp_auth_prod ENABLE ROW LEVEL SECURITY;
784
+
785
+ --
786
+ -- Name: whatsapp_auth_test; Type: ROW SECURITY; Schema: public; Owner: -
787
+ --
788
+
789
+ ALTER TABLE public.whatsapp_auth_test ENABLE ROW LEVEL SECURITY;
790
+
791
+ --
792
+ -- PostgreSQL database dump complete
793
+ --
794
+
795
+ \unrestrict mmwJKwqjeA3JVtIaidbJLdgw9PKc68S0JUhcgqBdfGktidQ8SzpvG9rGb4KqLiH
796
+