-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathskynest_schema.sql
More file actions
8442 lines (7862 loc) · 446 KB
/
skynest_schema.sql
File metadata and controls
8442 lines (7862 loc) · 446 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- PostgreSQL database dump
--
\restrict Qy1DrmI3OE1bo6KS02qsf7FF3YtkAjj6SCuoRvfiFOPZz61Pezqs6hYYXfPCJh6
-- Dumped from database version 18.0
-- Dumped by pg_dump version 18.0
-- Started on 2025-10-18 02:49:51
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET transaction_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- TOC entry 2 (class 3079 OID 16390)
-- Name: btree_gist; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;
--
-- TOC entry 5565 (class 0 OID 0)
-- Dependencies: 2
-- Name: EXTENSION btree_gist; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION btree_gist IS 'support for indexing common datatypes in GiST';
--
-- TOC entry 1123 (class 1247 OID 17117)
-- Name: adjustment_type; Type: TYPE; Schema: public; Owner: postgres
--
CREATE TYPE public.adjustment_type AS ENUM (
'refund',
'chargeback',
'manual_adjustment'
);
ALTER TYPE public.adjustment_type OWNER TO postgres;
--
-- TOC entry 1126 (class 1247 OID 17124)
-- Name: booking_status; Type: TYPE; Schema: public; Owner: postgres
--
CREATE TYPE public.booking_status AS ENUM (
'Booked',
'Checked-In',
'Checked-Out',
'Cancelled'
);
ALTER TYPE public.booking_status OWNER TO postgres;
--
-- TOC entry 1129 (class 1247 OID 17134)
-- Name: payment_method; Type: TYPE; Schema: public; Owner: postgres
--
CREATE TYPE public.payment_method AS ENUM (
'Cash',
'Card',
'Online',
'BankTransfer'
);
ALTER TYPE public.payment_method OWNER TO postgres;
--
-- TOC entry 1132 (class 1247 OID 17144)
-- Name: prebooking_method; Type: TYPE; Schema: public; Owner: postgres
--
CREATE TYPE public.prebooking_method AS ENUM (
'Online',
'Phone',
'Walk-in'
);
ALTER TYPE public.prebooking_method OWNER TO postgres;
--
-- TOC entry 1135 (class 1247 OID 17152)
-- Name: room_status; Type: TYPE; Schema: public; Owner: postgres
--
CREATE TYPE public.room_status AS ENUM (
'Available',
'Occupied',
'Maintenance'
);
ALTER TYPE public.room_status OWNER TO postgres;
--
-- TOC entry 1138 (class 1247 OID 17160)
-- Name: user_role; Type: TYPE; Schema: public; Owner: postgres
--
CREATE TYPE public.user_role AS ENUM (
'Admin',
'Manager',
'Receptionist',
'Accountant',
'Customer'
);
ALTER TYPE public.user_role OWNER TO postgres;
--
-- TOC entry 420 (class 1255 OID 17171)
-- Name: fn_balance_due(bigint); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fn_balance_due(p bigint) RETURNS numeric
LANGUAGE sql STABLE
AS $$
SELECT ROUND(COALESCE(fn_bill_total(p),0) - COALESCE(fn_total_paid(p),0), 2);
$$;
ALTER FUNCTION public.fn_balance_due(p bigint) OWNER TO postgres;
--
-- TOC entry 255 (class 1255 OID 17172)
-- Name: fn_bill_total(bigint); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fn_bill_total(p_booking_id bigint) RETURNS numeric
LANGUAGE sql STABLE
AS $$
WITH base AS (
SELECT
COALESCE(fn_room_charges(b.booking_id),0) +
COALESCE(fn_service_charges(b.booking_id),0) +
b.late_fee_amount - b.discount_amount AS subtotal,
b.tax_rate_percent
FROM booking b WHERE b.booking_id = p_booking_id
)
SELECT ROUND(subtotal * (1 + tax_rate_percent/100.0),2) FROM base;
$$;
ALTER FUNCTION public.fn_bill_total(p_booking_id bigint) OWNER TO postgres;
--
-- TOC entry 366 (class 1255 OID 17173)
-- Name: fn_net_balance(bigint); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fn_net_balance(p_booking_id bigint) RETURNS numeric
LANGUAGE sql STABLE
AS $$
SELECT ROUND(
COALESCE(fn_bill_total(p_booking_id),0)
- (COALESCE(fn_total_paid(p_booking_id),0) - COALESCE(fn_total_refunds(p_booking_id),0))
, 2);
$$;
ALTER FUNCTION public.fn_net_balance(p_booking_id bigint) OWNER TO postgres;
--
-- TOC entry 376 (class 1255 OID 17174)
-- Name: fn_room_charges(bigint); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fn_room_charges(p_booking_id bigint) RETURNS numeric
LANGUAGE sql STABLE
AS $$
SELECT GREATEST((b.check_out_date - b.check_in_date),0)::int * b.booked_rate
FROM booking b WHERE b.booking_id = p_booking_id;
$$;
ALTER FUNCTION public.fn_room_charges(p_booking_id bigint) OWNER TO postgres;
--
-- TOC entry 432 (class 1255 OID 17175)
-- Name: fn_service_charges(bigint); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fn_service_charges(p_booking_id bigint) RETURNS numeric
LANGUAGE sql STABLE
AS $$
SELECT COALESCE(SUM(u.qty * u.unit_price_at_use),0)
FROM service_usage u WHERE u.booking_id = p_booking_id;
$$;
ALTER FUNCTION public.fn_service_charges(p_booking_id bigint) OWNER TO postgres;
--
-- TOC entry 284 (class 1255 OID 17176)
-- Name: fn_total_paid(bigint); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fn_total_paid(p_booking_id bigint) RETURNS numeric
LANGUAGE sql STABLE
AS $$
SELECT COALESCE(SUM(p.amount),0) FROM payment p WHERE p.booking_id = p_booking_id;
$$;
ALTER FUNCTION public.fn_total_paid(p_booking_id bigint) OWNER TO postgres;
--
-- TOC entry 285 (class 1255 OID 17177)
-- Name: fn_total_refunds(bigint); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fn_total_refunds(p_booking_id bigint) RETURNS numeric
LANGUAGE sql STABLE
AS $$
SELECT COALESCE(SUM(amount),0)
FROM payment_adjustment
WHERE booking_id = p_booking_id AND type IN ('refund','chargeback');
$$;
ALTER FUNCTION public.fn_total_refunds(p_booking_id bigint) OWNER TO postgres;
--
-- TOC entry 471 (class 1255 OID 17178)
-- Name: randn(numeric); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.randn(p numeric) RETURNS numeric
LANGUAGE sql IMMUTABLE
AS $$
SELECT (random() * p)::numeric;
$$;
ALTER FUNCTION public.randn(p numeric) OWNER TO postgres;
--
-- TOC entry 436 (class 1255 OID 17179)
-- Name: sp_cancel_booking(bigint, character varying); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.sp_cancel_booking(p_booking_id bigint, p_reference_note character varying DEFAULT NULL::character varying) RETURNS TABLE(booking_id bigint, bill_total numeric, total_paid numeric, cancellation_fee numeric, refund_amount numeric, status_after text)
LANGUAGE plpgsql
AS $$
DECLARE
v_bill NUMERIC;
v_paid NUMERIC;
v_fee NUMERIC := 0;
v_refund NUMERIC := 0;
v_checkin DATE;
v_today DATE := CURRENT_DATE;
v_status booking_status;
BEGIN
-- 1) Load current facts
SELECT check_in_date, status INTO v_checkin, v_status
FROM booking WHERE booking_id = p_booking_id FOR UPDATE;
IF NOT FOUND THEN
RAISE EXCEPTION 'Booking % not found', p_booking_id;
END IF;
v_bill := COALESCE(fn_bill_total(p_booking_id),0);
v_paid := COALESCE(fn_total_paid(p_booking_id),0);
-- 2) Policy: free >= 2 days before check-in; else 10% fee
IF v_checkin - v_today >= 2 THEN
v_fee := 0;
ELSE
v_fee := ROUND(v_bill * 0.10, 2); -- 10% fee
END IF;
-- Never refund more than bill total minus fee (and not more than paid)
v_refund := GREATEST(LEAST(v_paid, GREATEST(v_bill - v_fee, 0)), 0);
-- 3) Record refund only if there is something to refund
IF v_refund > 0 THEN
INSERT INTO payment_adjustment (booking_id, amount, type, reference_note)
VALUES (p_booking_id, v_refund, 'refund', COALESCE(p_reference_note, 'auto-refund on cancel'));
END IF;
-- 4) Set status to Cancelled (idempotent)
UPDATE booking
SET status = 'Cancelled'
WHERE booking_id = p_booking_id;
-- 5) Return a summary row
RETURN QUERY
SELECT p_booking_id, v_bill, v_paid, v_fee, v_refund, 'Cancelled'::text;
END $$;
ALTER FUNCTION public.sp_cancel_booking(p_booking_id bigint, p_reference_note character varying) OWNER TO postgres;
--
-- TOC entry 298 (class 1255 OID 17180)
-- Name: trg_check_min_advance(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.trg_check_min_advance() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
v_required numeric(10,2);
BEGIN
v_required := ROUND(
(GREATEST((NEW.check_out_date - NEW.check_in_date), 0)::int * NEW.booked_rate) * 0.10, 2
);
IF NEW.advance_payment < v_required THEN
RAISE EXCEPTION
'advance_payment (%.2f) is below the required 10%% (%.2f) of room charges (nights × rate)',
NEW.advance_payment, v_required
USING ERRCODE = '23514'; -- check_violation
END IF;
RETURN NEW;
END $$;
ALTER FUNCTION public.trg_check_min_advance() OWNER TO postgres;
--
-- TOC entry 472 (class 1255 OID 17181)
-- Name: trg_refund_advance_on_cancel(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.trg_refund_advance_on_cancel() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
v_adv NUMERIC;
BEGIN
IF NEW.status = 'Cancelled' AND OLD.status <> 'Cancelled' THEN
v_adv := COALESCE(NEW.advance_payment,0);
IF v_adv > 0 THEN
INSERT INTO payment_adjustment (booking_id, amount, type, reference_note)
VALUES (NEW.booking_id, v_adv, 'refund', 'Auto refund of advance on cancel');
END IF;
END IF;
RETURN NEW;
END $$;
ALTER FUNCTION public.trg_refund_advance_on_cancel() OWNER TO postgres;
--
-- TOC entry 364 (class 1255 OID 17182)
-- Name: trg_refund_advance_policy(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.trg_refund_advance_policy() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
v_checkin DATE;
v_today DATE := CURRENT_DATE;
v_adv NUMERIC;
v_fee NUMERIC;
v_refund NUMERIC;
BEGIN
-- Run only when status just changed to Cancelled
IF NEW.status = 'Cancelled' AND OLD.status <> 'Cancelled' THEN
v_checkin := NEW.check_in_date;
v_adv := COALESCE(NEW.advance_payment,0);
IF v_adv > 0 THEN
-- Rule: full refund if ≥2 days before check-in, else 10 % fee
IF v_checkin - v_today >= 2 THEN
v_fee := 0;
ELSE
v_fee := ROUND(v_adv * 0.10,2); -- 10 % fee
END IF;
v_refund := GREATEST(v_adv - v_fee,0);
INSERT INTO payment_adjustment(booking_id,amount,type,reference_note)
VALUES(NEW.booking_id,v_refund,'refund',
CASE WHEN v_fee=0
THEN 'Full advance refund (≥2 days before check-in)'
ELSE 'Refund after 10 % late-cancel fee'
END);
END IF;
END IF;
RETURN NEW;
END $$;
ALTER FUNCTION public.trg_refund_advance_policy() OWNER TO postgres;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- TOC entry 220 (class 1259 OID 17183)
-- Name: audit_log; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.audit_log (
audit_id integer NOT NULL,
actor text NOT NULL,
action text NOT NULL,
entity text NOT NULL,
entity_id bigint,
details jsonb,
created_at timestamp without time zone DEFAULT now()
);
ALTER TABLE public.audit_log OWNER TO postgres;
--
-- TOC entry 221 (class 1259 OID 17193)
-- Name: audit_log_audit_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.audit_log_audit_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.audit_log_audit_id_seq OWNER TO postgres;
--
-- TOC entry 5566 (class 0 OID 0)
-- Dependencies: 221
-- Name: audit_log_audit_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.audit_log_audit_id_seq OWNED BY public.audit_log.audit_id;
--
-- TOC entry 222 (class 1259 OID 17194)
-- Name: booking; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.booking (
booking_id bigint NOT NULL,
pre_booking_id bigint,
guest_id bigint NOT NULL,
room_id bigint NOT NULL,
check_in_date date NOT NULL,
check_out_date date NOT NULL,
status public.booking_status DEFAULT 'Booked'::public.booking_status NOT NULL,
booked_rate numeric(10,2) NOT NULL,
tax_rate_percent numeric(5,2) DEFAULT 0 NOT NULL,
discount_amount numeric(10,2) DEFAULT 0 NOT NULL,
late_fee_amount numeric(10,2) DEFAULT 0 NOT NULL,
preferred_payment_method public.payment_method,
advance_payment numeric(10,2) DEFAULT 0 NOT NULL,
room_estimate numeric(10,2) GENERATED ALWAYS AS (((GREATEST((check_out_date - check_in_date), 0))::numeric * booked_rate)) STORED,
created_at timestamp with time zone DEFAULT now(),
CONSTRAINT booking_advance_min_10pct CHECK (((advance_payment + 0.005) >= round((((GREATEST((check_out_date - check_in_date), 0))::numeric * booked_rate) * 0.10), 2)))
);
ALTER TABLE public.booking OWNER TO postgres;
--
-- TOC entry 223 (class 1259 OID 17216)
-- Name: booking_booking_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.booking_booking_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.booking_booking_id_seq OWNER TO postgres;
--
-- TOC entry 5567 (class 0 OID 0)
-- Dependencies: 223
-- Name: booking_booking_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.booking_booking_id_seq OWNED BY public.booking.booking_id;
--
-- TOC entry 224 (class 1259 OID 17217)
-- Name: branch; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.branch (
branch_id bigint NOT NULL,
branch_name character varying(100) NOT NULL,
contact_number character varying(30),
address text,
manager_name character varying(100),
branch_code character varying(10)
);
ALTER TABLE public.branch OWNER TO postgres;
--
-- TOC entry 225 (class 1259 OID 17224)
-- Name: branch_branch_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.branch_branch_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.branch_branch_id_seq OWNER TO postgres;
--
-- TOC entry 5568 (class 0 OID 0)
-- Dependencies: 225
-- Name: branch_branch_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.branch_branch_id_seq OWNED BY public.branch.branch_id;
--
-- TOC entry 226 (class 1259 OID 17225)
-- Name: customer; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.customer (
customer_id bigint NOT NULL,
user_id bigint,
guest_id bigint NOT NULL,
created_at timestamp with time zone DEFAULT now()
);
ALTER TABLE public.customer OWNER TO postgres;
--
-- TOC entry 227 (class 1259 OID 17231)
-- Name: customer_customer_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.customer_customer_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.customer_customer_id_seq OWNER TO postgres;
--
-- TOC entry 5569 (class 0 OID 0)
-- Dependencies: 227
-- Name: customer_customer_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.customer_customer_id_seq OWNED BY public.customer.customer_id;
--
-- TOC entry 228 (class 1259 OID 17232)
-- Name: employee; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.employee (
employee_id bigint NOT NULL,
user_id bigint NOT NULL,
branch_id bigint NOT NULL,
name character varying(120) NOT NULL,
email character varying(150),
contact_no character varying(30)
);
ALTER TABLE public.employee OWNER TO postgres;
--
-- TOC entry 229 (class 1259 OID 17239)
-- Name: employee_employee_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.employee_employee_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.employee_employee_id_seq OWNER TO postgres;
--
-- TOC entry 5570 (class 0 OID 0)
-- Dependencies: 229
-- Name: employee_employee_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.employee_employee_id_seq OWNED BY public.employee.employee_id;
--
-- TOC entry 230 (class 1259 OID 17240)
-- Name: guest; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.guest (
guest_id bigint NOT NULL,
nic character varying(30),
full_name character varying(120) NOT NULL,
email character varying(150),
phone character varying(30),
gender character varying(20),
date_of_birth date,
address text,
nationality character varying(80)
);
ALTER TABLE public.guest OWNER TO postgres;
--
-- TOC entry 231 (class 1259 OID 17247)
-- Name: guest_guest_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.guest_guest_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.guest_guest_id_seq OWNER TO postgres;
--
-- TOC entry 5571 (class 0 OID 0)
-- Dependencies: 231
-- Name: guest_guest_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.guest_guest_id_seq OWNED BY public.guest.guest_id;
--
-- TOC entry 232 (class 1259 OID 17248)
-- Name: invoice; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.invoice (
invoice_id bigint NOT NULL,
booking_id bigint NOT NULL,
period_start date,
period_end date,
issued_at timestamp with time zone DEFAULT now() NOT NULL
);
ALTER TABLE public.invoice OWNER TO postgres;
--
-- TOC entry 233 (class 1259 OID 17255)
-- Name: invoice_invoice_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.invoice_invoice_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.invoice_invoice_id_seq OWNER TO postgres;
--
-- TOC entry 5572 (class 0 OID 0)
-- Dependencies: 233
-- Name: invoice_invoice_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.invoice_invoice_id_seq OWNED BY public.invoice.invoice_id;
--
-- TOC entry 234 (class 1259 OID 17256)
-- Name: payment; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.payment (
payment_id bigint NOT NULL,
booking_id bigint NOT NULL,
amount numeric(10,2) NOT NULL,
method public.payment_method,
paid_at timestamp with time zone DEFAULT now() NOT NULL,
payment_reference character varying(100)
);
ALTER TABLE public.payment OWNER TO postgres;
--
-- TOC entry 235 (class 1259 OID 17264)
-- Name: payment_adjustment; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.payment_adjustment (
adjustment_id bigint NOT NULL,
booking_id bigint NOT NULL,
amount numeric(10,2) NOT NULL,
type public.adjustment_type NOT NULL,
reference_note character varying(200),
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT payment_adjustment_amount_check CHECK ((amount > (0)::numeric))
);
ALTER TABLE public.payment_adjustment OWNER TO postgres;
--
-- TOC entry 236 (class 1259 OID 17274)
-- Name: payment_adjustment_adjustment_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.payment_adjustment_adjustment_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.payment_adjustment_adjustment_id_seq OWNER TO postgres;
--
-- TOC entry 5573 (class 0 OID 0)
-- Dependencies: 236
-- Name: payment_adjustment_adjustment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.payment_adjustment_adjustment_id_seq OWNED BY public.payment_adjustment.adjustment_id;
--
-- TOC entry 237 (class 1259 OID 17275)
-- Name: payment_payment_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.payment_payment_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.payment_payment_id_seq OWNER TO postgres;
--
-- TOC entry 5574 (class 0 OID 0)
-- Dependencies: 237
-- Name: payment_payment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.payment_payment_id_seq OWNED BY public.payment.payment_id;
--
-- TOC entry 238 (class 1259 OID 17276)
-- Name: pre_booking; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.pre_booking (
pre_booking_id bigint NOT NULL,
guest_id bigint NOT NULL,
capacity integer NOT NULL,
prebooking_method public.prebooking_method NOT NULL,
expected_check_in date NOT NULL,
expected_check_out date NOT NULL,
room_id bigint,
created_by_employee_id bigint,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
ALTER TABLE public.pre_booking OWNER TO postgres;
--
-- TOC entry 239 (class 1259 OID 17287)
-- Name: pre_booking_pre_booking_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.pre_booking_pre_booking_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.pre_booking_pre_booking_id_seq OWNER TO postgres;
--
-- TOC entry 5575 (class 0 OID 0)
-- Dependencies: 239
-- Name: pre_booking_pre_booking_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.pre_booking_pre_booking_id_seq OWNED BY public.pre_booking.pre_booking_id;
--
-- TOC entry 240 (class 1259 OID 17288)
-- Name: room; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.room (
room_id bigint NOT NULL,
branch_id bigint NOT NULL,
room_type_id bigint NOT NULL,
room_number character varying(20) NOT NULL,
status public.room_status DEFAULT 'Available'::public.room_status NOT NULL
);
ALTER TABLE public.room OWNER TO postgres;
--
-- TOC entry 241 (class 1259 OID 17297)
-- Name: room_room_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.room_room_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.room_room_id_seq OWNER TO postgres;
--
-- TOC entry 5576 (class 0 OID 0)
-- Dependencies: 241
-- Name: room_room_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.room_room_id_seq OWNED BY public.room.room_id;
--
-- TOC entry 242 (class 1259 OID 17298)
-- Name: room_type; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.room_type (
room_type_id bigint NOT NULL,
name character varying(50) NOT NULL,
capacity integer NOT NULL,
daily_rate numeric(10,2) NOT NULL,
amenities text
);
ALTER TABLE public.room_type OWNER TO postgres;
--
-- TOC entry 243 (class 1259 OID 17307)
-- Name: room_type_room_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.room_type_room_type_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.room_type_room_type_id_seq OWNER TO postgres;
--
-- TOC entry 5577 (class 0 OID 0)
-- Dependencies: 243
-- Name: room_type_room_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.room_type_room_type_id_seq OWNED BY public.room_type.room_type_id;
--
-- TOC entry 244 (class 1259 OID 17308)
-- Name: service_catalog; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.service_catalog (
service_id bigint NOT NULL,
code character varying(30),
name character varying(100) NOT NULL,
category character varying(60),
unit_price numeric(10,2) NOT NULL,
tax_rate_percent numeric(5,2) DEFAULT 0 NOT NULL,
active boolean DEFAULT true NOT NULL
);
ALTER TABLE public.service_catalog OWNER TO postgres;
--
-- TOC entry 245 (class 1259 OID 17318)
-- Name: service_catalog_service_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.service_catalog_service_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.service_catalog_service_id_seq OWNER TO postgres;
--
-- TOC entry 5578 (class 0 OID 0)
-- Dependencies: 245
-- Name: service_catalog_service_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.service_catalog_service_id_seq OWNED BY public.service_catalog.service_id;
--
-- TOC entry 246 (class 1259 OID 17319)
-- Name: service_usage; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.service_usage (
service_usage_id bigint NOT NULL,
booking_id bigint NOT NULL,
service_id bigint NOT NULL,
used_on date DEFAULT CURRENT_DATE NOT NULL,
qty integer NOT NULL,
unit_price_at_use numeric(10,2) NOT NULL
);
ALTER TABLE public.service_usage OWNER TO postgres;
--
-- TOC entry 247 (class 1259 OID 17329)
-- Name: service_usage_service_usage_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public.service_usage_service_usage_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.service_usage_service_usage_id_seq OWNER TO postgres;
--
-- TOC entry 5579 (class 0 OID 0)
-- Dependencies: 247
-- Name: service_usage_service_usage_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public.service_usage_service_usage_id_seq OWNED BY public.service_usage.service_usage_id;