getting started

This commit is contained in:
androidlover5842
2026-01-24 14:42:07 +05:30
commit a5a6aa4999
29 changed files with 1133 additions and 0 deletions

View File

@@ -0,0 +1 @@
spring.datasource.url=jdbc:postgresql://192.168.1.53:5432/trisolaris

View File

@@ -0,0 +1 @@
spring.datasource.url=jdbc:postgresql://localhost:5432/trisolaris

View File

@@ -0,0 +1,7 @@
spring.application.name=TrisolarisServer
spring.datasource.username=android
spring.datasource.password=${DB_PASSWORD}
spring.jpa.hibernate.ddl-auto=update
spring.jpa.open-in-view=false
spring.flyway.enabled=false
spring.flyway.locations=classpath:db/migration

View File

@@ -0,0 +1,180 @@
-- Enable UUIDs
create extension if not exists pgcrypto;
-- ---------- guest ----------
create table guest (
id uuid primary key default gen_random_uuid(),
phone_e164 text unique,
name text,
nationality text,
address_text text,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
-- ---------- room ----------
create table room (
id uuid primary key default gen_random_uuid(),
room_number int not null unique,
room_type text,
is_active boolean not null default true,
has_nfc boolean not null default false
);
-- ---------- booking ----------
create table booking (
id uuid primary key default gen_random_uuid(),
source text not null default 'WALKIN'
check (source in ('WALKIN','MMT','AGODA','BOOKING.COM','CLEARTRIP','AGENT','OTHER')),
source_booking_id text,
source_payload jsonb,
status text not null default 'RESERVED'
check (status in ('RESERVED','CHECKED_IN','CHECKED_OUT','CANCELLED','NO_SHOW')),
primary_guest_id uuid references guest(id),
checkin_at timestamptz,
checkout_at timestamptz,
estimated_checkout_at timestamptz,
cancelled_at timestamptz,
cancel_reason text,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now(),
unique (source, source_booking_id)
);
create index booking_status_idx on booking(status);
create index booking_checkin_idx on booking(checkin_at);
create table booking_party (
booking_id uuid primary key references booking(id) on delete cascade,
male int not null default 0,
female int not null default 0,
children int not null default 0
);
create table booking_details (
booking_id uuid primary key references booking(id) on delete cascade,
mode_of_transport text,
coming_from text,
going_to text,
purpose text,
relation text
);
-- ---------- room stay segments ----------
create table room_stay (
id uuid primary key default gen_random_uuid(),
booking_id uuid not null references booking(id) on delete cascade,
room_id uuid not null references room(id),
from_at timestamptz not null,
to_at timestamptz,
rate numeric(12,2) not null,
rate_unit text not null default 'NIGHT'
check (rate_unit in ('NIGHT','DAY','HOUR')),
note text);
);
create index room_stay_booking_idx on room_stay(booking_id);
create index room_stay_room_active_idx on room_stay(room_id) where to_at is null;
-- ---------- charges ----------
create table charge (
id uuid primary key default gen_random_uuid(),
booking_id uuid not null references booking(id) on delete cascade,
type text not null
check (type in ('ROOM_RENT','EXTRA_GUEST','EXTRA_BED','FOOD','DAMAGE','DISCOUNT','ADJUSTMENT','CANCELLATION_FEE','ROUNDING','COMMISSION')),
amount numeric(12,2) not null,
note text,
occurred_at timestamptz not null default now(),
created_at timestamptz not null default now()
);
create table audit_log (
id bigserial primary key,
occurred_at timestamptz not null default now(),
actor_type text not null default 'SYSTEM'
check (actor_type in ('SYSTEM','EMPLOYEE','API','GUEST')),
actor_id text, -- store employeeId / uid / api key id as text
actor_ip inet,
user_agent text,
entity_type text not null, -- e.g. BOOKING, PAYMENT, ROOM_STAY, GUEST
entity_id uuid, -- the uuid id if you have it
action text not null, -- e.g. CREATE, UPDATE, CANCEL, CHECKIN, CHECKOUT, ADD_PAYMENT, REFUND, ROOM_CHANGE
message text, -- human-readable note
before jsonb, -- optional previous state
after jsonb, -- optional new state
meta jsonb -- any extra (diff, reason, source, etc.)
);
create table app_user (
id uuid primary key default gen_random_uuid(),
firebase_uid text not null unique,
phone_e164 text,
name text,
is_disabled boolean not null default false,
roles text[] not null default '{}', -- ['admin','staff']
created_at timestamptz not null default now()
);
create index audit_entity_idx on audit_log(entity_type, entity_id, occurred_at desc);
create index audit_action_idx on audit_log(action, occurred_at desc);
create index audit_actor_idx on audit_log(actor_type, actor_id, occurred_at desc);
create type document_type as enum
('UNKNOWN','AADHAR','PASSPORT','DL','VOTER','OTHER');
create table client_ids (
id uuid primary key default gen_random_uuid(),
guest_id uuid not null references guest(id) on delete cascade,
file_key text not null,
uploaded_at timestamptz not null default now(),
ai_raw_text text,
ai_ran_at timestamptz,
full_name text,
date_of_birth date,
gender text,
father_name text,
address text,
city text,
state text,
postal_code text,
country text,
type document_type not null default 'UNKNOWN'
);
create table issued_card (
id uuid primary key default gen_random_uuid(),
card_id text not null, -- "E2E2464E"
card_index int, -- 100590
doc_id text, -- "FBE3D1737DC937F" (lock internal / doc id)
room_number int, -- keep int like you have
booking_id uuid references booking(id) on delete set null, -- optional but useful
issue_at timestamptz not null,
expiry_at timestamptz not null,
issuer_name text,
issuer_firebase_uid text references app_user(firebase_uid) on delete set null,
created_at timestamptz not null default now(),
check (expiry_at > issue_at)
);
create index issued_card_room_idx on issued_card(room_number, issue_at desc);
create index issued_card_booking_idx on issued_card(booking_id, issue_at desc);
create index issued_card_issuer_idx on issued_card(issuer_firebase_uid, issue_at desc);
create unique index issued_card_unique_idx on issued_card(card_id, card_index, issue_at);