Vacation Rental Marketplace ER diagram and database schema
The Vacation Rental Marketplace database schema is a DB Planner template with 24 tables, 214 columns and 40 relationships, free to use. Core tables include amenities, booking_charges, booking_nights, bookings. It can be opened as an interactive ER diagram or exported as PostgreSQL, MySQL, or SQL Server DDL.
- Tables
- 24
- Columns
- 214
- Relationships
- 40
- Category
- Marketplace
- Exports
- DBML, SQL, Prisma, C#
- Price
- Free
What this schema models
A complete vacation rental marketplace database design, built the way short-term rental platforms actually run: 24 tables, 17 enums and 40 relationships covering hosts and guests, identity checks and wishlists, listings with photos, amenities, house rules and versioned cancellation policies, a per-night availability calendar with pricing rules and iCal sync, instant and request-to-book bookings with per-night price snapshots, guest payments, refunds and host payouts, two-sided reviews and message threads. THE FOUR DESIGN RULES 1. One row per listing per NIGHT. calendar_nights is keyed on (listing_id, night), and a booking claims its nights with one conditional UPDATE that must touch exactly as many rows as nights booked. A night carries only one booking_id, so two overlapping bookings can never both commit. A night is the date you sleep, so check-out day stays free for the next check-in. 2. Prices are snapshotted per night. booking_nights stores each night's price and the rule that produced it, and every fee, discount and tax is a booking_charges line. Editing a weekend or seasonal rule never changes a confirmed stay, and "why was Saturday more?" has an answer. 3. Guest money and host money are separate. Guest payments follow the guest's schedule (pay part now, part later); host payouts are released about 24 hours after check-in. The platform holds the funds in between, so a cancellation before arrival is a refund to the guest, never a clawback from the host. 4. Reviews are blind until both are in. When the first review of a stay arrives, its published_at is set to the review deadline; when the second arrives, both are published at once. Readers filter on published_at <= now(), so neither side reads the other first and no job has to run at the deadline. DETAILS WORTH STEALING - Cancellation policies are versioned rows, never edited. A booking points at the exact version it was made under, and the cancellation stores the refund it computed. - Pricing resolves in a fixed order: calendar override, then the highest-priority seasonal or weekend rule, then the base price, with length-of-stay, early bird and last minute discounts applied to the subtotal. - Instant book and request to book share one bookings table; a request holds its nights and auto-declines after 24 hours. - Exact coordinates are shown only to confirmed guests, and messages sent before confirmation have contact details masked to keep payment on the platform. - iCal import and export feeds turn busy dates from other sites into blocked nights. - Hosts and guests are one users table, because most hosts travel too. WHAT YOU GET Clean DBML that imports directly into DB Planner, and a laid-out board with zones color-coded and framed: users and trust, listings, availability and pricing, bookings, payments and payouts, and reviews and messaging. Every table carries a note. Postgres-flavoured types that port cleanly to MySQL or SQL Server. Useful for developers building a vacation rental, holiday let or short-term booking marketplace, and for students who need a realistic vacation rental ER diagram for a DBMS project. This is a schema design reference; occupancy taxes, local short-term rental rules and payment regulation vary by market and belong in your own business logic.
Tables (24)
| Table | Columns |
|---|---|
| amenities | 4 |
| booking_charges | 6 |
| booking_nights | 4 |
| bookings | 21 |
| calendar_nights | 7 |
| calendar_syncs | 6 |
| cancellation_policies | 9 |
| cancellations | 8 |
| guest_payments | 10 |
| host_payouts | 10 |
| house_rules | 5 |
| identity_verifications | 7 |
| listing_amenities | 3 |
| listing_photos | 8 |
| listings | 29 |
| message_threads | 7 |
| messages | 7 |
| payment_methods | 6 |
| payout_accounts | 7 |
| pricing_rules | 12 |
| refunds | 8 |
| reviews | 15 |
| saved_listings | 4 |
| users | 11 |
Every table and its columns
users
Everyone on the marketplace. A host is simply a user with listings, and most hosts travel as guests too.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| varchar(254) | unique, not null | |||
| first_name | varchar(100) | not null | ||
| last_name | varchar(100) | not null | ||
| phone | varchar(30) | |||
| about | text | |||
| avatar_storage_key | varchar(300) | |||
| preferred_currency | char(3) | not null, default 'USD' | ||
| host_since | date | Set when the first listing goes live. Hosts and guests are the same users. | ||
| created_at | timestamptz | not null, default `now()` | ||
| deleted_at | timestamptz | Soft delete: past bookings and reviews must still name both sides |
identity_verifications
Trust checks: email, phone, government ID. Hosts can require a verified ID before accepting a booking.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| user_id | uuid | FK, not null | users.id | |
| kind | verification_kind | not null | ||
| status | verification_status | not null, default 'pending' | ||
| provider_reference | varchar(100) | Verification vendor reference; document images stay with the vendor | ||
| verified_at | timestamptz | |||
| expires_at | timestamptz |
Indexes: (user_id, kind)
saved_listings
Wishlists.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| user_id | uuid | FK, not null | users.id | |
| listing_id | uuid | FK, not null | listings.id | |
| list_name | varchar(100) | not null, default 'Favorites' | e.g. Summer 2027, Ski trip | |
| saved_at | timestamptz | not null, default `now()` |
listings
A place to stay, owned by one host. Base price, cleaning fee and guest limits live here; adjustments live in pricing_rules and calendar_nights.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| host_id | uuid | FK, not null | users.id | |
| title | varchar(150) | not null | ||
| description | text | not null | ||
| room_type | room_type | not null | ||
| property_type | varchar(50) | not null | e.g. Apartment, Cabin, Villa, Houseboat | |
| address_line1 | varchar(200) | not null | ||
| city | varchar(120) | not null | ||
| country | char(2) | not null | ||
| latitude | numeric(9,6) | not null | Exact point is shown only to confirmed guests; search shows a blurred area | |
| longitude | numeric(9,6) | not null | ||
| timezone | varchar(64) | not null | IANA zone. Check-in times and calendar nights are local to the property. | |
| max_guests | smallint | not null | ||
| bedrooms | smallint | not null | ||
| beds | smallint | not null | ||
| bathrooms | numeric(3,1) | not null | 1.5 means one full and one half bath | |
| currency | char(3) | not null | ||
| base_nightly_cents | integer | not null | Default price for a night with no rule or override | |
| cleaning_fee_cents | integer | not null, default 0 | Charged once per stay | |
| guests_included | smallint | not null, default 1 | ||
| extra_guest_fee_cents | integer | not null, default 0 | Per night, for each guest above guests_included | |
| min_nights | smallint | not null, default 1 | ||
| max_nights | smallint | |||
| check_in_from | time | not null | ||
| check_out_by | time | not null | ||
| booking_mode | booking_mode | not null, default 'request' | ||
| cancellation_policy_id | uuid | FK, not null | cancellation_policies.id | |
| status | listing_status | not null, default 'draft' | ||
| created_at | timestamptz | not null, default `now()` |
Indexes: (host_id), (country, city, status)
listing_photos
Listing photos. Dimensions are stored so the page can reserve space before images load.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| listing_id | uuid | FK, not null | listings.id | |
| storage_key | varchar(300) | unique, not null | Object storage key. Image bytes never live in the database. | |
| caption | varchar(200) | |||
| position | smallint | not null | Display order; the first is the cover photo | |
| width | integer | not null | ||
| height | integer | not null | ||
| created_at | timestamptz | not null, default `now()` |
Indexes: (listing_id, position)
amenities
The fixed amenity catalog. Search filters by code, so a typo by one host never splits a filter.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| code | varchar(40) | unique, not null | e.g. wifi, kitchen, hot_tub, ev_charger, step_free_entrance | |
| name | varchar(100) | not null | ||
| category | amenity_category | not null |
listing_amenities
Which amenities a listing offers.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| listing_id | uuid | FK, not null | listings.id | |
| amenity_id | uuid | FK, not null | amenities.id | |
| details | varchar(200) | e.g. 500 Mbps, shared with one other unit |
Indexes: (amenity_id, listing_id)
house_rules
Rules the guest must accept before booking. The booking records when they were accepted.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| listing_id | uuid | FK, not null | listings.id | |
| rule | house_rule_kind | not null | ||
| is_allowed | boolean | not null | e.g. pets: true, smoking: false | |
| details | varchar(300) | e.g. Quiet hours 22:00 to 08:00, one dog under 20 kg |
Indexes: (listing_id)
cancellation_policies
Versioned rows, never edited. Changing a policy inserts a new version; a booking points at the exact version it was made under, so the refund a guest was promised can always be recomputed.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| code | varchar(30) | not null | e.g. flexible, moderate, strict, non_refundable | |
| version | smallint | not null | ||
| name | varchar(100) | not null | ||
| full_refund_days_before | smallint | not null | Full refund when cancelled at least this many days before check-in | |
| partial_refund_days_before | smallint | Partial refund window, if any | ||
| partial_refund_pct | smallint | Share of the nightly subtotal refunded in the partial window | ||
| cleaning_fee_refundable | boolean | not null, default true | Refunded whenever the stay has not started | |
| effective_from | timestamptz | not null |
Indexes: (code, version) unique
calendar_nights
One row per listing per night, generated for the bookable window (rolled forward daily). A booking claims its nights with one conditional UPDATE: SET status = booked, booking_id = $1 WHERE listing_id = $2 AND night >= check_in AND night < check_out AND status = available. It must touch exactly as many rows as nights booked, or the transaction rolls back. A night can carry only one booking_id, so two overlapping bookings can never both commit.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| listing_id | uuid | FK, not null | listings.id | |
| night | date | not null | The date the guest sleeps there. Check-out day is not a night, so back-to-back stays fit. | |
| status | night_status | not null, default 'available' | ||
| booking_id | uuid | FK | bookings.id | Set while the night is held for a request or booked |
| price_override_cents | integer | Host-set price for this date; beats every rule | ||
| min_nights_override | smallint | e.g. 3-night minimum over a holiday | ||
| updated_at | timestamptz | not null, default `now()` |
Indexes: (booking_id)
pricing_rules
How a night is priced. Resolution order: calendar override, then the highest-priority seasonal or weekend rule, then base_nightly_cents. Length-of-stay, early bird and last minute rules then discount the nightly subtotal. The cleaning fee is not a rule; it is a fixed per-stay amount on the listing.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| listing_id | uuid | FK, not null | listings.id | |
| kind | pricing_rule_kind | not null | ||
| adjustment_pct | numeric(5,2) | Negative for a discount, positive for a markup | ||
| nightly_price_cents | integer | Alternative to a percentage: a fixed nightly price, e.g. for a season | ||
| start_date | date | Seasonal rules | ||
| end_date | date | |||
| weekend_nights | smallint | Weekend rules: bitmask of nights, Friday and Saturday by default | ||
| min_nights | smallint | Length-of-stay rules: 7 for weekly, 28 for monthly | ||
| days_before_arrival | smallint | Early bird (at least) and last minute (at most) rules | ||
| priority | smallint | not null, default 0 | Highest wins when two nightly rules overlap | |
| is_active | boolean | not null, default true |
Indexes: (listing_id, kind)
calendar_syncs
iCal feeds to and from other sites. Imported busy dates become blocked nights, which is how hosts list on several platforms without double bookings.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| listing_id | uuid | FK, not null | listings.id | |
| direction | sync_direction | not null | ||
| feed_url | varchar(500) | not null | iCal URL. Treated as a secret: anyone with it can read the calendar. | |
| last_synced_at | timestamptz | |||
| last_error | varchar(300) |
bookings
A stay. Totals here are the sum of booking_nights and booking_charges, frozen when the guest pays.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| confirmation_code | varchar(12) | unique, not null | ||
| listing_id | uuid | FK, not null | listings.id | |
| guest_id | uuid | FK, not null | users.id | |
| host_id | uuid | FK, not null | users.id | Copied from the listing, so a listing changing hands never rewrites past stays |
| mode | booking_mode | not null | Instant books confirm at once; requests wait for the host | |
| status | booking_status | not null | ||
| check_in | date | not null | ||
| check_out | date | not null | CHECK (check_out > check_in) | |
| adults | smallint | not null | ||
| children | smallint | not null, default 0 | ||
| infants | smallint | not null, default 0 | ||
| pets | smallint | not null, default 0 | ||
| currency | char(3) | not null | ||
| guest_total_cents | integer | not null | What the guest pays: nights plus guest-side charges | |
| host_payout_cents | integer | not null | What the host earns: nights plus host-side charges, net of the host fee | |
| cancellation_policy_id | uuid | FK, not null | cancellation_policies.id | The exact policy version in force at booking |
| house_rules_accepted_at | timestamptz | not null | ||
| request_expires_at | timestamptz | Requests auto-decline after 24 hours and release their nights | ||
| created_at | timestamptz | not null, default `now()` | ||
| confirmed_at | timestamptz |
Indexes: (listing_id, check_in), (guest_id, check_in)
booking_nights
The price of every night, as quoted. Editing rules later never changes a confirmed stay, and "why was Saturday more?" has an answer.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| booking_id | uuid | FK, not null | bookings.id | |
| night | date | not null | ||
| price_cents | integer | not null | Snapshot of the resolved nightly price | |
| pricing_rule_id | uuid | FK | pricing_rules.id | The rule that set it; null for base price or a calendar override |
booking_charges
Every line on both receipts: cleaning fee, extra guests, pets, discounts, service fees and taxes.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| booking_id | uuid | FK, not null | bookings.id | |
| kind | charge_kind | not null | ||
| payer | party | not null | Guest-side lines add to the guest total; host-side lines reduce the payout | |
| description | varchar(200) | not null | e.g. Weekly discount 10%, Cleaning fee, Occupancy tax 6% | |
| amount_cents | integer | not null | Negative for discounts |
cancellations
The outcome of a cancellation. The money math is stored, not recomputed later, so a policy change can never alter it.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| booking_id | uuid | PK, FK | bookings.id | |
| cancelled_by | party | not null | ||
| cancelled_by_user_id | uuid | FK | users.id | Null when support cancels on behalf of either side |
| reason | varchar(300) | |||
| guest_refund_cents | integer | not null | Computed from the policy version on the booking, then frozen | |
| host_payout_kept_cents | integer | not null | What the host still earns after the refund | |
| host_penalty_cents | integer | not null, default 0 | Charged when the host cancels a confirmed stay | |
| cancelled_at | timestamptz | not null, default `now()` |
payment_methods
Guest cards, as processor tokens.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| user_id | uuid | FK, not null | users.id | |
| processor_token | varchar(200) | not null | Card data stays with the payment processor; only its token is stored | |
| brand | varchar(20) | not null | ||
| last4 | char(4) | not null | ||
| expires_on | date | not null |
guest_payments
Money in, from the guest, on the guest schedule.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| booking_id | uuid | FK, not null | bookings.id | |
| payment_method_id | uuid | FK, not null | payment_methods.id | |
| installment | smallint | not null, default 1 | Pay part now, part later: 1 at booking, 2 before arrival | |
| amount_cents | integer | not null | ||
| currency | char(3) | not null | ||
| status | payment_status | not null, default 'scheduled' | ||
| due_at | timestamptz | not null | ||
| processed_at | timestamptz | |||
| processor_reference | varchar(100) | unique |
Indexes: (status, due_at)
refunds
Money back to the guest, against a specific payment, since a refund goes back to the card it came from.
| Column | Type | Constraints | References |
|---|---|---|---|
| id | uuid | PK | |
| guest_payment_id | uuid | FK, not null | guest_payments.id |
| booking_id | uuid | FK, not null | bookings.id |
| amount_cents | integer | not null | |
| reason | refund_reason | not null | |
| status | payment_status | not null, default 'scheduled' | |
| processor_reference | varchar(100) | ||
| created_at | timestamptz | not null, default `now()` |
payout_accounts
Where a host gets paid.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| host_id | uuid | FK, not null | users.id | |
| processor_account_token | varchar(200) | not null | Connected-account id; bank details stay with the processor | |
| currency | char(3) | not null | ||
| country | char(2) | not null | ||
| is_default | boolean | not null, default false | ||
| verified_at | timestamptz |
host_payouts
Money out, to the host, on the host schedule. Guest money and host money never share a row: the platform holds funds between the guest charge and the host release, so a cancellation before arrival is a refund to the guest, never a clawback from the host.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| booking_id | uuid | FK, not null | bookings.id | |
| host_id | uuid | FK, not null | users.id | |
| payout_account_id | uuid | FK, not null | payout_accounts.id | |
| amount_cents | integer | not null | Negative for an adjustment, e.g. a host cancellation penalty | |
| currency | char(3) | not null | ||
| status | payout_status | not null, default 'scheduled' | ||
| release_after | timestamptz | not null | About 24 hours after check-in, once the guest has arrived | |
| paid_at | timestamptz | |||
| processor_reference | varchar(100) | unique |
Indexes: (status, release_after)
reviews
Two-sided and blind. When the first review of a stay arrives, its published_at is set to the deadline (check-out plus 14 days). When the second arrives, both are set to now(). Readers filter on published_at <= now(), so neither side can read the other first, and nothing has to wake up at the deadline.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| booking_id | uuid | FK, not null | bookings.id | |
| direction | review_direction | not null | ||
| author_id | uuid | FK, not null | users.id | |
| subject_id | uuid | FK, not null | users.id | |
| overall_rating | smallint | not null | 1 to 5 | |
| cleanliness_rating | smallint | Category ratings apply to guest-to-host reviews only | ||
| accuracy_rating | smallint | |||
| communication_rating | smallint | |||
| location_rating | smallint | |||
| value_rating | smallint | |||
| public_text | text | not null | ||
| private_feedback | text | Seen only by the other party, never published | ||
| submitted_at | timestamptz | not null, default `now()` | ||
| published_at | timestamptz | not null | When it becomes visible; see the table note |
Indexes: (booking_id, direction) unique, (subject_id, published_at)
message_threads
One conversation between a guest and a host about a listing, attached to the booking once there is one.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| listing_id | uuid | FK, not null | listings.id | |
| guest_id | uuid | FK, not null | users.id | |
| host_id | uuid | FK, not null | users.id | |
| booking_id | uuid | FK | bookings.id | Null for an inquiry before booking |
| last_message_at | timestamptz | |||
| created_at | timestamptz | not null, default `now()` |
Indexes: (guest_id, last_message_at), (host_id, last_message_at)
messages
Messages in a thread. Kept as the record if a dispute reaches support.
| Column | Type | Constraints | References | Description |
|---|---|---|---|---|
| id | uuid | PK | ||
| thread_id | uuid | FK, not null | message_threads.id | |
| sender_id | uuid | FK | users.id | Null for system messages, e.g. booking confirmed |
| body | text | not null | ||
| was_redacted | boolean | not null, default false | Phone numbers and emails are masked before a booking is confirmed, to keep payment on the platform | |
| sent_at | timestamptz | not null, default `now()` | ||
| read_at | timestamptz |
Indexes: (thread_id, sent_at)
Enums (17)
- verification_kind
- email, phone, government_id
- verification_status
- pending, verified, failed, expired
- room_type
- entire_place, private_room, shared_room
- listing_status
- draft, pending_review, listed, unlisted, suspended
- booking_mode
- instant, request
- amenity_category
- essentials, kitchen, bathroom, safety, outdoor, parking, accessibility, entertainment
- house_rule_kind
- pets, smoking, parties, children, quiet_hours, other
- night_status
- available, blocked, held, booked
- pricing_rule_kind
- weekend, seasonal, length_of_stay, early_bird, last_minute
- sync_direction
- import, export
- booking_status
- requested, declined, expired, confirmed, cancelled, completed
- charge_kind
- cleaning_fee, extra_guest_fee, pet_fee, discount, service_fee, tax
- party
- guest, host, platform
- payment_status
- scheduled, succeeded, failed, cancelled
- refund_reason
- guest_cancellation, host_cancellation, listing_issue, goodwill
- payout_status
- scheduled, released, paid, failed, reversed
- review_direction
- guest_to_host, host_to_guest
Relationships (40)
booking_charges.booking_id references bookings.idmany to onebooking_nights.booking_id references bookings.idmany to onebooking_nights.pricing_rule_id references pricing_rules.idmany to onebookings.cancellation_policy_id references cancellation_policies.idmany to onebookings.guest_id references users.idmany to onebookings.host_id references users.idmany to onebookings.id references cancellations.booking_idone to onebookings.listing_id references listings.idmany to onecalendar_nights.booking_id references bookings.idmany to onecalendar_nights.listing_id references listings.idmany to onecalendar_syncs.listing_id references listings.idmany to onecancellations.cancelled_by_user_id references users.idmany to oneguest_payments.booking_id references bookings.idmany to oneguest_payments.payment_method_id references payment_methods.idmany to onehost_payouts.booking_id references bookings.idmany to onehost_payouts.host_id references users.idmany to onehost_payouts.payout_account_id references payout_accounts.idmany to onehouse_rules.listing_id references listings.idmany to oneidentity_verifications.user_id references users.idmany to onelisting_amenities.amenity_id references amenities.idmany to onelisting_amenities.listing_id references listings.idmany to onelisting_photos.listing_id references listings.idmany to onelistings.cancellation_policy_id references cancellation_policies.idmany to onelistings.host_id references users.idmany to onemessage_threads.booking_id references bookings.idmany to onemessage_threads.guest_id references users.idmany to onemessage_threads.host_id references users.idmany to onemessage_threads.listing_id references listings.idmany to onemessages.sender_id references users.idmany to onemessages.thread_id references message_threads.idmany to onepayment_methods.user_id references users.idmany to onepayout_accounts.host_id references users.idmany to onepricing_rules.listing_id references listings.idmany to onerefunds.booking_id references bookings.idmany to onerefunds.guest_payment_id references guest_payments.idmany to onereviews.author_id references users.idmany to onereviews.booking_id references bookings.idmany to onereviews.subject_id references users.idmany to onesaved_listings.listing_id references listings.idmany to onesaved_listings.user_id references users.idmany to one
Vacation Rental Marketplace database schema in DBML
The schema as it is written: DBML, the text format DB Planner draws its diagrams from. Copy it into any DBML tool, or open it in the diagram above.
// Vacation Rental Marketplace
// Zones (header colors): users and trust (gray), listings (blue),
// availability and pricing (teal), bookings (amber), payments and payouts (purple),
// reviews and messaging (green).
// ---------------------------------------------------------------------------
// USERS AND TRUST
// ---------------------------------------------------------------------------
Table users [headercolor: #90a4ae] {
id uuid [pk]
email varchar(254) [not null, unique]
first_name varchar(100) [not null]
last_name varchar(100) [not null]
phone varchar(30)
about text
avatar_storage_key varchar(300)
preferred_currency char(3) [not null, default: 'USD']
host_since date [note: 'Set when the first listing goes live. Hosts and guests are the same users.']
created_at timestamptz [not null, default: `now()`]
deleted_at timestamptz [note: 'Soft delete: past bookings and reviews must still name both sides']
Note: 'Everyone on the marketplace. A host is simply a user with listings, and most hosts travel as guests too.'
}
Table identity_verifications [headercolor: #90a4ae] {
id uuid [pk]
user_id uuid [not null, ref: > users.id]
kind verification_kind [not null]
status verification_status [not null, default: 'pending']
provider_reference varchar(100) [note: 'Verification vendor reference; document images stay with the vendor']
verified_at timestamptz
expires_at timestamptz
indexes {
(user_id, kind)
}
Note: 'Trust checks: email, phone, government ID. Hosts can require a verified ID before accepting a booking.'
}
Table saved_listings [headercolor: #90a4ae] {
user_id uuid [not null, ref: > users.id]
listing_id uuid [not null, ref: > listings.id]
list_name varchar(100) [not null, default: 'Favorites', note: 'e.g. Summer 2027, Ski trip']
saved_at timestamptz [not null, default: `now()`]
indexes {
(user_id, listing_id, list_name) [pk]
}
Note: 'Wishlists.'
}
// ---------------------------------------------------------------------------
// LISTINGS
// ---------------------------------------------------------------------------
Table listings [headercolor: #4c8bf5] {
id uuid [pk]
host_id uuid [not null, ref: > users.id]
title varchar(150) [not null]
description text [not null]
room_type room_type [not null]
property_type varchar(50) [not null, note: 'e.g. Apartment, Cabin, Villa, Houseboat']
address_line1 varchar(200) [not null]
city varchar(120) [not null]
country char(2) [not null]
latitude numeric(9,6) [not null, note: 'Exact point is shown only to confirmed guests; search shows a blurred area']
longitude numeric(9,6) [not null]
timezone varchar(64) [not null, note: 'IANA zone. Check-in times and calendar nights are local to the property.']
max_guests smallint [not null]
bedrooms smallint [not null]
beds smallint [not null]
bathrooms numeric(3,1) [not null, note: '1.5 means one full and one half bath']
currency char(3) [not null]
base_nightly_cents integer [not null, note: 'Default price for a night with no rule or override']
cleaning_fee_cents integer [not null, default: 0, note: 'Charged once per stay']
guests_included smallint [not null, default: 1]
extra_guest_fee_cents integer [not null, default: 0, note: 'Per night, for each guest above guests_included']
min_nights smallint [not null, default: 1]
max_nights smallint
check_in_from time [not null]
check_out_by time [not null]
booking_mode booking_mode [not null, default: 'request']
cancellation_policy_id uuid [not null, ref: > cancellation_policies.id]
status listing_status [not null, default: 'draft']
created_at timestamptz [not null, default: `now()`]
indexes {
host_id
(country, city, status) [note: 'Destination search; a geo index on (latitude, longitude) serves map search']
}
Note: 'A place to stay, owned by one host. Base price, cleaning fee and guest limits live here; adjustments live in pricing_rules and calendar_nights.'
}
Table listing_photos [headercolor: #4c8bf5] {
id uuid [pk]
listing_id uuid [not null, ref: > listings.id]
storage_key varchar(300) [not null, unique, note: 'Object storage key. Image bytes never live in the database.']
caption varchar(200)
position smallint [not null, note: 'Display order; the first is the cover photo']
width integer [not null]
height integer [not null]
created_at timestamptz [not null, default: `now()`]
indexes {
(listing_id, position)
}
Note: 'Listing photos. Dimensions are stored so the page can reserve space before images load.'
}
Table amenities [headercolor: #4c8bf5] {
id uuid [pk]
code varchar(40) [not null, unique, note: 'e.g. wifi, kitchen, hot_tub, ev_charger, step_free_entrance']
name varchar(100) [not null]
category amenity_category [not null]
Note: 'The fixed amenity catalog. Search filters by code, so a typo by one host never splits a filter.'
}
Table listing_amenities [headercolor: #4c8bf5] {
listing_id uuid [not null, ref: > listings.id]
amenity_id uuid [not null, ref: > amenities.id]
details varchar(200) [note: 'e.g. 500 Mbps, shared with one other unit']
indexes {
(listing_id, amenity_id) [pk]
(amenity_id, listing_id) [note: 'Search: listings with a hot tub']
}
Note: 'Which amenities a listing offers.'
}
Table house_rules [headercolor: #4c8bf5] {
id uuid [pk]
listing_id uuid [not null, ref: > listings.id]
rule house_rule_kind [not null]
is_allowed boolean [not null, note: 'e.g. pets: true, smoking: false']
details varchar(300) [note: 'e.g. Quiet hours 22:00 to 08:00, one dog under 20 kg']
indexes {
listing_id
}
Note: 'Rules the guest must accept before booking. The booking records when they were accepted.'
}
Table cancellation_policies [headercolor: #4c8bf5] {
id uuid [pk]
code varchar(30) [not null, note: 'e.g. flexible, moderate, strict, non_refundable']
version smallint [not null]
name varchar(100) [not null]
full_refund_days_before smallint [not null, note: 'Full refund when cancelled at least this many days before check-in']
partial_refund_days_before smallint [note: 'Partial refund window, if any']
partial_refund_pct smallint [note: 'Share of the nightly subtotal refunded in the partial window']
cleaning_fee_refundable boolean [not null, default: true, note: 'Refunded whenever the stay has not started']
effective_from timestamptz [not null]
indexes {
(code, version) [unique]
}
Note: '''Versioned rows, never edited. Changing a policy inserts a new version; a booking points at the exact version it was made under, so the refund a guest was promised can always be recomputed.'''
}
// ---------------------------------------------------------------------------
// AVAILABILITY AND PRICING
// ---------------------------------------------------------------------------
Table calendar_nights [headercolor: #4cd0b0] {
listing_id uuid [not null, ref: > listings.id]
night date [not null, note: 'The date the guest sleeps there. Check-out day is not a night, so back-to-back stays fit.']
status night_status [not null, default: 'available']
booking_id uuid [ref: > bookings.id, note: 'Set while the night is held for a request or booked']
price_override_cents integer [note: 'Host-set price for this date; beats every rule']
min_nights_override smallint [note: 'e.g. 3-night minimum over a holiday']
updated_at timestamptz [not null, default: `now()`]
indexes {
(listing_id, night) [pk]
booking_id
}
Note: '''One row per listing per night, generated for the bookable window (rolled forward daily). A booking claims its nights with one conditional UPDATE: SET status = booked, booking_id = $1 WHERE listing_id = $2 AND night >= check_in AND night < check_out AND status = available. It must touch exactly as many rows as nights booked, or the transaction rolls back. A night can carry only one booking_id, so two overlapping bookings can never both commit.'''
}
Table pricing_rules [headercolor: #4cd0b0] {
id uuid [pk]
listing_id uuid [not null, ref: > listings.id]
kind pricing_rule_kind [not null]
adjustment_pct numeric(5,2) [note: 'Negative for a discount, positive for a markup']
nightly_price_cents integer [note: 'Alternative to a percentage: a fixed nightly price, e.g. for a season']
start_date date [note: 'Seasonal rules']
end_date date
weekend_nights smallint [note: 'Weekend rules: bitmask of nights, Friday and Saturday by default']
min_nights smallint [note: 'Length-of-stay rules: 7 for weekly, 28 for monthly']
days_before_arrival smallint [note: 'Early bird (at least) and last minute (at most) rules']
priority smallint [not null, default: 0, note: 'Highest wins when two nightly rules overlap']
is_active boolean [not null, default: true]
indexes {
(listing_id, kind)
}
Note: '''How a night is priced. Resolution order: calendar override, then the highest-priority seasonal or weekend rule, then base_nightly_cents. Length-of-stay, early bird and last minute rules then discount the nightly subtotal. The cleaning fee is not a rule; it is a fixed per-stay amount on the listing.'''
}
Table calendar_syncs [headercolor: #4cd0b0] {
id uuid [pk]
listing_id uuid [not null, ref: > listings.id]
direction sync_direction [not null]
feed_url varchar(500) [not null, note: 'iCal URL. Treated as a secret: anyone with it can read the calendar.']
last_synced_at timestamptz
last_error varchar(300)
Note: 'iCal feeds to and from other sites. Imported busy dates become blocked nights, which is how hosts list on several platforms without double bookings.'
}
// ---------------------------------------------------------------------------
// BOOKINGS
// ---------------------------------------------------------------------------
Table bookings [headercolor: #f5b74c] {
id uuid [pk]
confirmation_code varchar(12) [not null, unique]
listing_id uuid [not null, ref: > listings.id]
guest_id uuid [not null, ref: > users.id]
host_id uuid [not null, ref: > users.id, note: 'Copied from the listing, so a listing changing hands never rewrites past stays']
mode booking_mode [not null, note: 'Instant books confirm at once; requests wait for the host']
status booking_status [not null]
check_in date [not null]
check_out date [not null, note: 'CHECK (check_out > check_in)']
adults smallint [not null]
children smallint [not null, default: 0]
infants smallint [not null, default: 0]
pets smallint [not null, default: 0]
currency char(3) [not null]
guest_total_cents integer [not null, note: 'What the guest pays: nights plus guest-side charges']
host_payout_cents integer [not null, note: 'What the host earns: nights plus host-side charges, net of the host fee']
cancellation_policy_id uuid [not null, ref: > cancellation_policies.id, note: 'The exact policy version in force at booking']
house_rules_accepted_at timestamptz [not null]
request_expires_at timestamptz [note: 'Requests auto-decline after 24 hours and release their nights']
created_at timestamptz [not null, default: `now()`]
confirmed_at timestamptz
indexes {
(listing_id, check_in)
(guest_id, check_in)
}
Note: 'A stay. Totals here are the sum of booking_nights and booking_charges, frozen when the guest pays.'
}
Table booking_nights [headercolor: #f5b74c] {
booking_id uuid [not null, ref: > bookings.id]
night date [not null]
price_cents integer [not null, note: 'Snapshot of the resolved nightly price']
pricing_rule_id uuid [ref: > pricing_rules.id, note: 'The rule that set it; null for base price or a calendar override']
indexes {
(booking_id, night) [pk]
}
Note: 'The price of every night, as quoted. Editing rules later never changes a confirmed stay, and "why was Saturday more?" has an answer.'
}
Table booking_charges [headercolor: #f5b74c] {
id uuid [pk]
booking_id uuid [not null, ref: > bookings.id]
kind charge_kind [not null]
payer party [not null, note: 'Guest-side lines add to the guest total; host-side lines reduce the payout']
description varchar(200) [not null, note: 'e.g. Weekly discount 10%, Cleaning fee, Occupancy tax 6%']
amount_cents integer [not null, note: 'Negative for discounts']
Note: 'Every line on both receipts: cleaning fee, extra guests, pets, discounts, service fees and taxes.'
}
Table cancellations [headercolor: #f5b74c] {
booking_id uuid [pk, ref: - bookings.id]
cancelled_by party [not null]
cancelled_by_user_id uuid [ref: > users.id, note: 'Null when support cancels on behalf of either side']
reason varchar(300)
guest_refund_cents integer [not null, note: 'Computed from the policy version on the booking, then frozen']
host_payout_kept_cents integer [not null, note: 'What the host still earns after the refund']
host_penalty_cents integer [not null, default: 0, note: 'Charged when the host cancels a confirmed stay']
cancelled_at timestamptz [not null, default: `now()`]
Note: 'The outcome of a cancellation. The money math is stored, not recomputed later, so a policy change can never alter it.'
}
// ---------------------------------------------------------------------------
// PAYMENTS AND PAYOUTS
// ---------------------------------------------------------------------------
Table payment_methods [headercolor: #b98cf0] {
id uuid [pk]
user_id uuid [not null, ref: > users.id]
processor_token varchar(200) [not null, note: 'Card data stays with the payment processor; only its token is stored']
brand varchar(20) [not null]
last4 char(4) [not null]
expires_on date [not null]
Note: 'Guest cards, as processor tokens.'
}
Table guest_payments [headercolor: #b98cf0] {
id uuid [pk]
booking_id uuid [not null, ref: > bookings.id]
payment_method_id uuid [not null, ref: > payment_methods.id]
installment smallint [not null, default: 1, note: 'Pay part now, part later: 1 at booking, 2 before arrival']
amount_cents integer [not null]
currency char(3) [not null]
status payment_status [not null, default: 'scheduled']
due_at timestamptz [not null]
processed_at timestamptz
processor_reference varchar(100) [unique]
indexes {
(status, due_at) [note: 'The collection job: scheduled installments now due']
}
Note: 'Money in, from the guest, on the guest schedule.'
}
Table refunds [headercolor: #b98cf0] {
id uuid [pk]
guest_payment_id uuid [not null, ref: > guest_payments.id]
booking_id uuid [not null, ref: > bookings.id]
amount_cents integer [not null]
reason refund_reason [not null]
status payment_status [not null, default: 'scheduled']
processor_reference varchar(100)
created_at timestamptz [not null, default: `now()`]
Note: 'Money back to the guest, against a specific payment, since a refund goes back to the card it came from.'
}
Table payout_accounts [headercolor: #b98cf0] {
id uuid [pk]
host_id uuid [not null, ref: > users.id]
processor_account_token varchar(200) [not null, note: 'Connected-account id; bank details stay with the processor']
currency char(3) [not null]
country char(2) [not null]
is_default boolean [not null, default: false]
verified_at timestamptz
Note: 'Where a host gets paid.'
}
Table host_payouts [headercolor: #b98cf0] {
id uuid [pk]
booking_id uuid [not null, ref: > bookings.id]
host_id uuid [not null, ref: > users.id]
payout_account_id uuid [not null, ref: > payout_accounts.id]
amount_cents integer [not null, note: 'Negative for an adjustment, e.g. a host cancellation penalty']
currency char(3) [not null]
status payout_status [not null, default: 'scheduled']
release_after timestamptz [not null, note: 'About 24 hours after check-in, once the guest has arrived']
paid_at timestamptz
processor_reference varchar(100) [unique]
indexes {
(status, release_after) [note: 'The payout job']
}
Note: '''Money out, to the host, on the host schedule. Guest money and host money never share a row: the platform holds funds between the guest charge and the host release, so a cancellation before arrival is a refund to the guest, never a clawback from the host.'''
}
// ---------------------------------------------------------------------------
// REVIEWS AND MESSAGING
// ---------------------------------------------------------------------------
Table reviews [headercolor: #8bc34a] {
id uuid [pk]
booking_id uuid [not null, ref: > bookings.id]
direction review_direction [not null]
author_id uuid [not null, ref: > users.id]
subject_id uuid [not null, ref: > users.id]
overall_rating smallint [not null, note: '1 to 5']
cleanliness_rating smallint [note: 'Category ratings apply to guest-to-host reviews only']
accuracy_rating smallint
communication_rating smallint
location_rating smallint
value_rating smallint
public_text text [not null]
private_feedback text [note: 'Seen only by the other party, never published']
submitted_at timestamptz [not null, default: `now()`]
published_at timestamptz [not null, note: 'When it becomes visible; see the table note']
indexes {
(booking_id, direction) [unique]
(subject_id, published_at)
}
Note: '''Two-sided and blind. When the first review of a stay arrives, its published_at is set to the deadline (check-out plus 14 days). When the second arrives, both are set to now(). Readers filter on published_at <= now(), so neither side can read the other first, and nothing has to wake up at the deadline.'''
}
Table message_threads [headercolor: #8bc34a] {
id uuid [pk]
listing_id uuid [not null, ref: > listings.id]
guest_id uuid [not null, ref: > users.id]
host_id uuid [not null, ref: > users.id]
booking_id uuid [ref: > bookings.id, note: 'Null for an inquiry before booking']
last_message_at timestamptz
created_at timestamptz [not null, default: `now()`]
indexes {
(guest_id, last_message_at)
(host_id, last_message_at)
}
Note: 'One conversation between a guest and a host about a listing, attached to the booking once there is one.'
}
Table messages [headercolor: #8bc34a] {
id uuid [pk]
thread_id uuid [not null, ref: > message_threads.id]
sender_id uuid [ref: > users.id, note: 'Null for system messages, e.g. booking confirmed']
body text [not null]
was_redacted boolean [not null, default: false, note: 'Phone numbers and emails are masked before a booking is confirmed, to keep payment on the platform']
sent_at timestamptz [not null, default: `now()`]
read_at timestamptz
indexes {
(thread_id, sent_at)
}
Note: 'Messages in a thread. Kept as the record if a dispute reaches support.'
}
// ---------------------------------------------------------------------------
// ENUMS
// ---------------------------------------------------------------------------
Enum verification_kind {
email
phone
government_id
}
Enum verification_status {
pending
verified
failed
expired
}
Enum room_type {
entire_place
private_room
shared_room
}
Enum listing_status {
draft
pending_review
listed
unlisted
suspended
}
Enum booking_mode {
instant
request
}
Enum amenity_category {
essentials
kitchen
bathroom
safety
outdoor
parking
accessibility
entertainment
}
Enum house_rule_kind {
pets
smoking
parties
children
quiet_hours
other
}
Enum night_status {
available
blocked [note: 'Host block or an imported busy date']
held [note: 'Waiting on a booking request']
booked
}
Enum pricing_rule_kind {
weekend
seasonal
length_of_stay
early_bird
last_minute
}
Enum sync_direction {
import
export
}
Enum booking_status {
requested
declined
expired
confirmed
cancelled
completed
}
Enum charge_kind {
cleaning_fee
extra_guest_fee
pet_fee
discount
service_fee
tax
}
Enum party {
guest
host
platform
}
Enum payment_status {
scheduled
succeeded
failed
cancelled
}
Enum refund_reason {
guest_cancellation
host_cancellation
listing_issue
goodwill
}
Enum payout_status {
scheduled
released
paid
failed
reversed
}
Enum review_direction {
guest_to_host
host_to_guest
}Vacation Rental Marketplace database schema as SQL
The same schema as CREATE TABLE statements, exported by DB Planner.
PostgreSQL is shown first; MySQL and SQL Server are below it.
PostgreSQL
CREATE TYPE "verification_kind" AS ENUM (
'email',
'phone',
'government_id'
);
CREATE TYPE "verification_status" AS ENUM (
'pending',
'verified',
'failed',
'expired'
);
CREATE TYPE "room_type" AS ENUM (
'entire_place',
'private_room',
'shared_room'
);
CREATE TYPE "listing_status" AS ENUM (
'draft',
'pending_review',
'listed',
'unlisted',
'suspended'
);
CREATE TYPE "booking_mode" AS ENUM (
'instant',
'request'
);
CREATE TYPE "amenity_category" AS ENUM (
'essentials',
'kitchen',
'bathroom',
'safety',
'outdoor',
'parking',
'accessibility',
'entertainment'
);
CREATE TYPE "house_rule_kind" AS ENUM (
'pets',
'smoking',
'parties',
'children',
'quiet_hours',
'other'
);
CREATE TYPE "night_status" AS ENUM (
'available',
'blocked',
'held',
'booked'
);
CREATE TYPE "pricing_rule_kind" AS ENUM (
'weekend',
'seasonal',
'length_of_stay',
'early_bird',
'last_minute'
);
CREATE TYPE "sync_direction" AS ENUM (
'import',
'export'
);
CREATE TYPE "booking_status" AS ENUM (
'requested',
'declined',
'expired',
'confirmed',
'cancelled',
'completed'
);
CREATE TYPE "charge_kind" AS ENUM (
'cleaning_fee',
'extra_guest_fee',
'pet_fee',
'discount',
'service_fee',
'tax'
);
CREATE TYPE "party" AS ENUM (
'guest',
'host',
'platform'
);
CREATE TYPE "payment_status" AS ENUM (
'scheduled',
'succeeded',
'failed',
'cancelled'
);
CREATE TYPE "refund_reason" AS ENUM (
'guest_cancellation',
'host_cancellation',
'listing_issue',
'goodwill'
);
CREATE TYPE "payout_status" AS ENUM (
'scheduled',
'released',
'paid',
'failed',
'reversed'
);
CREATE TYPE "review_direction" AS ENUM (
'guest_to_host',
'host_to_guest'
);
CREATE TABLE "users" (
"id" uuid PRIMARY KEY,
"email" varchar(254) UNIQUE NOT NULL,
"first_name" varchar(100) NOT NULL,
"last_name" varchar(100) NOT NULL,
"phone" varchar(30),
"about" text,
"avatar_storage_key" varchar(300),
"preferred_currency" char(3) NOT NULL DEFAULT 'USD',
"host_since" date,
"created_at" timestamptz NOT NULL DEFAULT (now()),
"deleted_at" timestamptz
);
CREATE TABLE "identity_verifications" (
"id" uuid PRIMARY KEY,
"user_id" uuid NOT NULL,
"kind" verification_kind NOT NULL,
"status" verification_status NOT NULL DEFAULT 'pending',
"provider_reference" varchar(100),
"verified_at" timestamptz,
"expires_at" timestamptz
);
CREATE TABLE "saved_listings" (
"user_id" uuid NOT NULL,
"listing_id" uuid NOT NULL,
"list_name" varchar(100) NOT NULL DEFAULT 'Favorites',
"saved_at" timestamptz NOT NULL DEFAULT (now()),
PRIMARY KEY ("user_id", "listing_id", "list_name")
);
CREATE TABLE "listings" (
"id" uuid PRIMARY KEY,
"host_id" uuid NOT NULL,
"title" varchar(150) NOT NULL,
"description" text NOT NULL,
"room_type" room_type NOT NULL,
"property_type" varchar(50) NOT NULL,
"address_line1" varchar(200) NOT NULL,
"city" varchar(120) NOT NULL,
"country" char(2) NOT NULL,
"latitude" numeric(9,6) NOT NULL,
"longitude" numeric(9,6) NOT NULL,
"timezone" varchar(64) NOT NULL,
"max_guests" smallint NOT NULL,
"bedrooms" smallint NOT NULL,
"beds" smallint NOT NULL,
"bathrooms" numeric(3,1) NOT NULL,
"currency" char(3) NOT NULL,
"base_nightly_cents" integer NOT NULL,
"cleaning_fee_cents" integer NOT NULL DEFAULT 0,
"guests_included" smallint NOT NULL DEFAULT 1,
"extra_guest_fee_cents" integer NOT NULL DEFAULT 0,
"min_nights" smallint NOT NULL DEFAULT 1,
"max_nights" smallint,
"check_in_from" time NOT NULL,
"check_out_by" time NOT NULL,
"booking_mode" booking_mode NOT NULL DEFAULT 'request',
"cancellation_policy_id" uuid NOT NULL,
"status" listing_status NOT NULL DEFAULT 'draft',
"created_at" timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE "listing_photos" (
"id" uuid PRIMARY KEY,
"listing_id" uuid NOT NULL,
"storage_key" varchar(300) UNIQUE NOT NULL,
"caption" varchar(200),
"position" smallint NOT NULL,
"width" integer NOT NULL,
"height" integer NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE "amenities" (
"id" uuid PRIMARY KEY,
"code" varchar(40) UNIQUE NOT NULL,
"name" varchar(100) NOT NULL,
"category" amenity_category NOT NULL
);
CREATE TABLE "listing_amenities" (
"listing_id" uuid NOT NULL,
"amenity_id" uuid NOT NULL,
"details" varchar(200),
PRIMARY KEY ("listing_id", "amenity_id")
);
CREATE TABLE "house_rules" (
"id" uuid PRIMARY KEY,
"listing_id" uuid NOT NULL,
"rule" house_rule_kind NOT NULL,
"is_allowed" boolean NOT NULL,
"details" varchar(300)
);
CREATE TABLE "cancellation_policies" (
"id" uuid PRIMARY KEY,
"code" varchar(30) NOT NULL,
"version" smallint NOT NULL,
"name" varchar(100) NOT NULL,
"full_refund_days_before" smallint NOT NULL,
"partial_refund_days_before" smallint,
"partial_refund_pct" smallint,
"cleaning_fee_refundable" boolean NOT NULL DEFAULT true,
"effective_from" timestamptz NOT NULL
);
CREATE TABLE "calendar_nights" (
"listing_id" uuid NOT NULL,
"night" date NOT NULL,
"status" night_status NOT NULL DEFAULT 'available',
"booking_id" uuid,
"price_override_cents" integer,
"min_nights_override" smallint,
"updated_at" timestamptz NOT NULL DEFAULT (now()),
PRIMARY KEY ("listing_id", "night")
);
CREATE TABLE "pricing_rules" (
"id" uuid PRIMARY KEY,
"listing_id" uuid NOT NULL,
"kind" pricing_rule_kind NOT NULL,
"adjustment_pct" numeric(5,2),
"nightly_price_cents" integer,
"start_date" date,
"end_date" date,
"weekend_nights" smallint,
"min_nights" smallint,
"days_before_arrival" smallint,
"priority" smallint NOT NULL DEFAULT 0,
"is_active" boolean NOT NULL DEFAULT true
);
CREATE TABLE "calendar_syncs" (
"id" uuid PRIMARY KEY,
"listing_id" uuid NOT NULL,
"direction" sync_direction NOT NULL,
"feed_url" varchar(500) NOT NULL,
"last_synced_at" timestamptz,
"last_error" varchar(300)
);
CREATE TABLE "bookings" (
"id" uuid PRIMARY KEY,
"confirmation_code" varchar(12) UNIQUE NOT NULL,
"listing_id" uuid NOT NULL,
"guest_id" uuid NOT NULL,
"host_id" uuid NOT NULL,
"mode" booking_mode NOT NULL,
"status" booking_status NOT NULL,
"check_in" date NOT NULL,
"check_out" date NOT NULL,
"adults" smallint NOT NULL,
"children" smallint NOT NULL DEFAULT 0,
"infants" smallint NOT NULL DEFAULT 0,
"pets" smallint NOT NULL DEFAULT 0,
"currency" char(3) NOT NULL,
"guest_total_cents" integer NOT NULL,
"host_payout_cents" integer NOT NULL,
"cancellation_policy_id" uuid NOT NULL,
"house_rules_accepted_at" timestamptz NOT NULL,
"request_expires_at" timestamptz,
"created_at" timestamptz NOT NULL DEFAULT (now()),
"confirmed_at" timestamptz
);
CREATE TABLE "booking_nights" (
"booking_id" uuid NOT NULL,
"night" date NOT NULL,
"price_cents" integer NOT NULL,
"pricing_rule_id" uuid,
PRIMARY KEY ("booking_id", "night")
);
CREATE TABLE "booking_charges" (
"id" uuid PRIMARY KEY,
"booking_id" uuid NOT NULL,
"kind" charge_kind NOT NULL,
"payer" party NOT NULL,
"description" varchar(200) NOT NULL,
"amount_cents" integer NOT NULL
);
CREATE TABLE "cancellations" (
"booking_id" uuid PRIMARY KEY,
"cancelled_by" party NOT NULL,
"cancelled_by_user_id" uuid,
"reason" varchar(300),
"guest_refund_cents" integer NOT NULL,
"host_payout_kept_cents" integer NOT NULL,
"host_penalty_cents" integer NOT NULL DEFAULT 0,
"cancelled_at" timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE "payment_methods" (
"id" uuid PRIMARY KEY,
"user_id" uuid NOT NULL,
"processor_token" varchar(200) NOT NULL,
"brand" varchar(20) NOT NULL,
"last4" char(4) NOT NULL,
"expires_on" date NOT NULL
);
CREATE TABLE "guest_payments" (
"id" uuid PRIMARY KEY,
"booking_id" uuid NOT NULL,
"payment_method_id" uuid NOT NULL,
"installment" smallint NOT NULL DEFAULT 1,
"amount_cents" integer NOT NULL,
"currency" char(3) NOT NULL,
"status" payment_status NOT NULL DEFAULT 'scheduled',
"due_at" timestamptz NOT NULL,
"processed_at" timestamptz,
"processor_reference" varchar(100) UNIQUE
);
CREATE TABLE "refunds" (
"id" uuid PRIMARY KEY,
"guest_payment_id" uuid NOT NULL,
"booking_id" uuid NOT NULL,
"amount_cents" integer NOT NULL,
"reason" refund_reason NOT NULL,
"status" payment_status NOT NULL DEFAULT 'scheduled',
"processor_reference" varchar(100),
"created_at" timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE "payout_accounts" (
"id" uuid PRIMARY KEY,
"host_id" uuid NOT NULL,
"processor_account_token" varchar(200) NOT NULL,
"currency" char(3) NOT NULL,
"country" char(2) NOT NULL,
"is_default" boolean NOT NULL DEFAULT false,
"verified_at" timestamptz
);
CREATE TABLE "host_payouts" (
"id" uuid PRIMARY KEY,
"booking_id" uuid NOT NULL,
"host_id" uuid NOT NULL,
"payout_account_id" uuid NOT NULL,
"amount_cents" integer NOT NULL,
"currency" char(3) NOT NULL,
"status" payout_status NOT NULL DEFAULT 'scheduled',
"release_after" timestamptz NOT NULL,
"paid_at" timestamptz,
"processor_reference" varchar(100) UNIQUE
);
CREATE TABLE "reviews" (
"id" uuid PRIMARY KEY,
"booking_id" uuid NOT NULL,
"direction" review_direction NOT NULL,
"author_id" uuid NOT NULL,
"subject_id" uuid NOT NULL,
"overall_rating" smallint NOT NULL,
"cleanliness_rating" smallint,
"accuracy_rating" smallint,
"communication_rating" smallint,
"location_rating" smallint,
"value_rating" smallint,
"public_text" text NOT NULL,
"private_feedback" text,
"submitted_at" timestamptz NOT NULL DEFAULT (now()),
"published_at" timestamptz NOT NULL
);
CREATE TABLE "message_threads" (
"id" uuid PRIMARY KEY,
"listing_id" uuid NOT NULL,
"guest_id" uuid NOT NULL,
"host_id" uuid NOT NULL,
"booking_id" uuid,
"last_message_at" timestamptz,
"created_at" timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE "messages" (
"id" uuid PRIMARY KEY,
"thread_id" uuid NOT NULL,
"sender_id" uuid,
"body" text NOT NULL,
"was_redacted" boolean NOT NULL DEFAULT false,
"sent_at" timestamptz NOT NULL DEFAULT (now()),
"read_at" timestamptz
);
CREATE INDEX ON "identity_verifications" ("user_id", "kind");
CREATE INDEX ON "listings" ("host_id");
CREATE INDEX ON "listings" ("country", "city", "status");
CREATE INDEX ON "listing_photos" ("listing_id", "position");
CREATE INDEX ON "listing_amenities" ("amenity_id", "listing_id");
CREATE INDEX ON "house_rules" ("listing_id");
CREATE UNIQUE INDEX ON "cancellation_policies" ("code", "version");
CREATE INDEX ON "calendar_nights" ("booking_id");
CREATE INDEX ON "pricing_rules" ("listing_id", "kind");
CREATE INDEX ON "bookings" ("listing_id", "check_in");
CREATE INDEX ON "bookings" ("guest_id", "check_in");
CREATE INDEX ON "guest_payments" ("status", "due_at");
CREATE INDEX ON "host_payouts" ("status", "release_after");
CREATE UNIQUE INDEX ON "reviews" ("booking_id", "direction");
CREATE INDEX ON "reviews" ("subject_id", "published_at");
CREATE INDEX ON "message_threads" ("guest_id", "last_message_at");
CREATE INDEX ON "message_threads" ("host_id", "last_message_at");
CREATE INDEX ON "messages" ("thread_id", "sent_at");
COMMENT ON TABLE "users" IS 'Everyone on the marketplace. A host is simply a user with listings, and most hosts travel as guests too.';
COMMENT ON COLUMN "users"."host_since" IS 'Set when the first listing goes live. Hosts and guests are the same users.';
COMMENT ON COLUMN "users"."deleted_at" IS 'Soft delete: past bookings and reviews must still name both sides';
COMMENT ON TABLE "identity_verifications" IS 'Trust checks: email, phone, government ID. Hosts can require a verified ID before accepting a booking.';
COMMENT ON COLUMN "identity_verifications"."provider_reference" IS 'Verification vendor reference; document images stay with the vendor';
COMMENT ON TABLE "saved_listings" IS 'Wishlists.';
COMMENT ON COLUMN "saved_listings"."list_name" IS 'e.g. Summer 2027, Ski trip';
COMMENT ON TABLE "listings" IS 'A place to stay, owned by one host. Base price, cleaning fee and guest limits live here; adjustments live in pricing_rules and calendar_nights.';
COMMENT ON COLUMN "listings"."property_type" IS 'e.g. Apartment, Cabin, Villa, Houseboat';
COMMENT ON COLUMN "listings"."latitude" IS 'Exact point is shown only to confirmed guests; search shows a blurred area';
COMMENT ON COLUMN "listings"."timezone" IS 'IANA zone. Check-in times and calendar nights are local to the property.';
COMMENT ON COLUMN "listings"."bathrooms" IS '1.5 means one full and one half bath';
COMMENT ON COLUMN "listings"."base_nightly_cents" IS 'Default price for a night with no rule or override';
COMMENT ON COLUMN "listings"."cleaning_fee_cents" IS 'Charged once per stay';
COMMENT ON COLUMN "listings"."extra_guest_fee_cents" IS 'Per night, for each guest above guests_included';
COMMENT ON TABLE "listing_photos" IS 'Listing photos. Dimensions are stored so the page can reserve space before images load.';
COMMENT ON COLUMN "listing_photos"."storage_key" IS 'Object storage key. Image bytes never live in the database.';
COMMENT ON COLUMN "listing_photos"."position" IS 'Display order; the first is the cover photo';
COMMENT ON TABLE "amenities" IS 'The fixed amenity catalog. Search filters by code, so a typo by one host never splits a filter.';
COMMENT ON COLUMN "amenities"."code" IS 'e.g. wifi, kitchen, hot_tub, ev_charger, step_free_entrance';
COMMENT ON TABLE "listing_amenities" IS 'Which amenities a listing offers.';
COMMENT ON COLUMN "listing_amenities"."details" IS 'e.g. 500 Mbps, shared with one other unit';
COMMENT ON TABLE "house_rules" IS 'Rules the guest must accept before booking. The booking records when they were accepted.';
COMMENT ON COLUMN "house_rules"."is_allowed" IS 'e.g. pets: true, smoking: false';
COMMENT ON COLUMN "house_rules"."details" IS 'e.g. Quiet hours 22:00 to 08:00, one dog under 20 kg';
COMMENT ON TABLE "cancellation_policies" IS 'Versioned rows, never edited. Changing a policy inserts a new version; a booking points at the exact version it was made under, so the refund a guest was promised can always be recomputed.';
COMMENT ON COLUMN "cancellation_policies"."code" IS 'e.g. flexible, moderate, strict, non_refundable';
COMMENT ON COLUMN "cancellation_policies"."full_refund_days_before" IS 'Full refund when cancelled at least this many days before check-in';
COMMENT ON COLUMN "cancellation_policies"."partial_refund_days_before" IS 'Partial refund window, if any';
COMMENT ON COLUMN "cancellation_policies"."partial_refund_pct" IS 'Share of the nightly subtotal refunded in the partial window';
COMMENT ON COLUMN "cancellation_policies"."cleaning_fee_refundable" IS 'Refunded whenever the stay has not started';
COMMENT ON TABLE "calendar_nights" IS 'One row per listing per night, generated for the bookable window (rolled forward daily). A booking claims its nights with one conditional UPDATE: SET status = booked, booking_id = $1 WHERE listing_id = $2 AND night >= check_in AND night < check_out AND status = available. It must touch exactly as many rows as nights booked, or the transaction rolls back. A night can carry only one booking_id, so two overlapping bookings can never both commit.';
COMMENT ON COLUMN "calendar_nights"."night" IS 'The date the guest sleeps there. Check-out day is not a night, so back-to-back stays fit.';
COMMENT ON COLUMN "calendar_nights"."booking_id" IS 'Set while the night is held for a request or booked';
COMMENT ON COLUMN "calendar_nights"."price_override_cents" IS 'Host-set price for this date; beats every rule';
COMMENT ON COLUMN "calendar_nights"."min_nights_override" IS 'e.g. 3-night minimum over a holiday';
COMMENT ON TABLE "pricing_rules" IS 'How a night is priced. Resolution order: calendar override, then the highest-priority seasonal or weekend rule, then base_nightly_cents. Length-of-stay, early bird and last minute rules then discount the nightly subtotal. The cleaning fee is not a rule; it is a fixed per-stay amount on the listing.';
COMMENT ON COLUMN "pricing_rules"."adjustment_pct" IS 'Negative for a discount, positive for a markup';
COMMENT ON COLUMN "pricing_rules"."nightly_price_cents" IS 'Alternative to a percentage: a fixed nightly price, e.g. for a season';
COMMENT ON COLUMN "pricing_rules"."start_date" IS 'Seasonal rules';
COMMENT ON COLUMN "pricing_rules"."weekend_nights" IS 'Weekend rules: bitmask of nights, Friday and Saturday by default';
COMMENT ON COLUMN "pricing_rules"."min_nights" IS 'Length-of-stay rules: 7 for weekly, 28 for monthly';
COMMENT ON COLUMN "pricing_rules"."days_before_arrival" IS 'Early bird (at least) and last minute (at most) rules';
COMMENT ON COLUMN "pricing_rules"."priority" IS 'Highest wins when two nightly rules overlap';
COMMENT ON TABLE "calendar_syncs" IS 'iCal feeds to and from other sites. Imported busy dates become blocked nights, which is how hosts list on several platforms without double bookings.';
COMMENT ON COLUMN "calendar_syncs"."feed_url" IS 'iCal URL. Treated as a secret: anyone with it can read the calendar.';
COMMENT ON TABLE "bookings" IS 'A stay. Totals here are the sum of booking_nights and booking_charges, frozen when the guest pays.';
COMMENT ON COLUMN "bookings"."host_id" IS 'Copied from the listing, so a listing changing hands never rewrites past stays';
COMMENT ON COLUMN "bookings"."mode" IS 'Instant books confirm at once; requests wait for the host';
COMMENT ON COLUMN "bookings"."check_out" IS 'CHECK (check_out > check_in)';
COMMENT ON COLUMN "bookings"."guest_total_cents" IS 'What the guest pays: nights plus guest-side charges';
COMMENT ON COLUMN "bookings"."host_payout_cents" IS 'What the host earns: nights plus host-side charges, net of the host fee';
COMMENT ON COLUMN "bookings"."cancellation_policy_id" IS 'The exact policy version in force at booking';
COMMENT ON COLUMN "bookings"."request_expires_at" IS 'Requests auto-decline after 24 hours and release their nights';
COMMENT ON TABLE "booking_nights" IS 'The price of every night, as quoted. Editing rules later never changes a confirmed stay, and "why was Saturday more?" has an answer.';
COMMENT ON COLUMN "booking_nights"."price_cents" IS 'Snapshot of the resolved nightly price';
COMMENT ON COLUMN "booking_nights"."pricing_rule_id" IS 'The rule that set it; null for base price or a calendar override';
COMMENT ON TABLE "booking_charges" IS 'Every line on both receipts: cleaning fee, extra guests, pets, discounts, service fees and taxes.';
COMMENT ON COLUMN "booking_charges"."payer" IS 'Guest-side lines add to the guest total; host-side lines reduce the payout';
COMMENT ON COLUMN "booking_charges"."description" IS 'e.g. Weekly discount 10%, Cleaning fee, Occupancy tax 6%';
COMMENT ON COLUMN "booking_charges"."amount_cents" IS 'Negative for discounts';
COMMENT ON TABLE "cancellations" IS 'The outcome of a cancellation. The money math is stored, not recomputed later, so a policy change can never alter it.';
COMMENT ON COLUMN "cancellations"."cancelled_by_user_id" IS 'Null when support cancels on behalf of either side';
COMMENT ON COLUMN "cancellations"."guest_refund_cents" IS 'Computed from the policy version on the booking, then frozen';
COMMENT ON COLUMN "cancellations"."host_payout_kept_cents" IS 'What the host still earns after the refund';
COMMENT ON COLUMN "cancellations"."host_penalty_cents" IS 'Charged when the host cancels a confirmed stay';
COMMENT ON TABLE "payment_methods" IS 'Guest cards, as processor tokens.';
COMMENT ON COLUMN "payment_methods"."processor_token" IS 'Card data stays with the payment processor; only its token is stored';
COMMENT ON TABLE "guest_payments" IS 'Money in, from the guest, on the guest schedule.';
COMMENT ON COLUMN "guest_payments"."installment" IS 'Pay part now, part later: 1 at booking, 2 before arrival';
COMMENT ON TABLE "refunds" IS 'Money back to the guest, against a specific payment, since a refund goes back to the card it came from.';
COMMENT ON TABLE "payout_accounts" IS 'Where a host gets paid.';
COMMENT ON COLUMN "payout_accounts"."processor_account_token" IS 'Connected-account id; bank details stay with the processor';
COMMENT ON TABLE "host_payouts" IS 'Money out, to the host, on the host schedule. Guest money and host money never share a row: the platform holds funds between the guest charge and the host release, so a cancellation before arrival is a refund to the guest, never a clawback from the host.';
COMMENT ON COLUMN "host_payouts"."amount_cents" IS 'Negative for an adjustment, e.g. a host cancellation penalty';
COMMENT ON COLUMN "host_payouts"."release_after" IS 'About 24 hours after check-in, once the guest has arrived';
COMMENT ON TABLE "reviews" IS 'Two-sided and blind. When the first review of a stay arrives, its published_at is set to the deadline (check-out plus 14 days). When the second arrives, both are set to now(). Readers filter on published_at <= now(), so neither side can read the other first, and nothing has to wake up at the deadline.';
COMMENT ON COLUMN "reviews"."overall_rating" IS '1 to 5';
COMMENT ON COLUMN "reviews"."cleanliness_rating" IS 'Category ratings apply to guest-to-host reviews only';
COMMENT ON COLUMN "reviews"."private_feedback" IS 'Seen only by the other party, never published';
COMMENT ON COLUMN "reviews"."published_at" IS 'When it becomes visible; see the table note';
COMMENT ON TABLE "message_threads" IS 'One conversation between a guest and a host about a listing, attached to the booking once there is one.';
COMMENT ON COLUMN "message_threads"."booking_id" IS 'Null for an inquiry before booking';
COMMENT ON TABLE "messages" IS 'Messages in a thread. Kept as the record if a dispute reaches support.';
COMMENT ON COLUMN "messages"."sender_id" IS 'Null for system messages, e.g. booking confirmed';
COMMENT ON COLUMN "messages"."was_redacted" IS 'Phone numbers and emails are masked before a booking is confirmed, to keep payment on the platform';
ALTER TABLE "identity_verifications" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");
ALTER TABLE "saved_listings" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");
ALTER TABLE "saved_listings" ADD FOREIGN KEY ("listing_id") REFERENCES "listings" ("id");
ALTER TABLE "listings" ADD FOREIGN KEY ("host_id") REFERENCES "users" ("id");
ALTER TABLE "listings" ADD FOREIGN KEY ("cancellation_policy_id") REFERENCES "cancellation_policies" ("id");
ALTER TABLE "listing_photos" ADD FOREIGN KEY ("listing_id") REFERENCES "listings" ("id");
ALTER TABLE "listing_amenities" ADD FOREIGN KEY ("listing_id") REFERENCES "listings" ("id");
ALTER TABLE "listing_amenities" ADD FOREIGN KEY ("amenity_id") REFERENCES "amenities" ("id");
ALTER TABLE "house_rules" ADD FOREIGN KEY ("listing_id") REFERENCES "listings" ("id");
ALTER TABLE "calendar_nights" ADD FOREIGN KEY ("listing_id") REFERENCES "listings" ("id");
ALTER TABLE "calendar_nights" ADD FOREIGN KEY ("booking_id") REFERENCES "bookings" ("id");
ALTER TABLE "pricing_rules" ADD FOREIGN KEY ("listing_id") REFERENCES "listings" ("id");
ALTER TABLE "calendar_syncs" ADD FOREIGN KEY ("listing_id") REFERENCES "listings" ("id");
ALTER TABLE "bookings" ADD FOREIGN KEY ("listing_id") REFERENCES "listings" ("id");
ALTER TABLE "bookings" ADD FOREIGN KEY ("guest_id") REFERENCES "users" ("id");
ALTER TABLE "bookings" ADD FOREIGN KEY ("host_id") REFERENCES "users" ("id");
ALTER TABLE "bookings" ADD FOREIGN KEY ("cancellation_policy_id") REFERENCES "cancellation_policies" ("id");
ALTER TABLE "booking_nights" ADD FOREIGN KEY ("booking_id") REFERENCES "bookings" ("id");
ALTER TABLE "booking_nights" ADD FOREIGN KEY ("pricing_rule_id") REFERENCES "pricing_rules" ("id");
ALTER TABLE "booking_charges" ADD FOREIGN KEY ("booking_id") REFERENCES "bookings" ("id");
ALTER TABLE "cancellations" ADD FOREIGN KEY ("booking_id") REFERENCES "bookings" ("id");
ALTER TABLE "cancellations" ADD FOREIGN KEY ("cancelled_by_user_id") REFERENCES "users" ("id");
ALTER TABLE "payment_methods" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");
ALTER TABLE "guest_payments" ADD FOREIGN KEY ("booking_id") REFERENCES "bookings" ("id");
ALTER TABLE "guest_payments" ADD FOREIGN KEY ("payment_method_id") REFERENCES "payment_methods" ("id");
ALTER TABLE "refunds" ADD FOREIGN KEY ("guest_payment_id") REFERENCES "guest_payments" ("id");
ALTER TABLE "refunds" ADD FOREIGN KEY ("booking_id") REFERENCES "bookings" ("id");
ALTER TABLE "payout_accounts" ADD FOREIGN KEY ("host_id") REFERENCES "users" ("id");
ALTER TABLE "host_payouts" ADD FOREIGN KEY ("booking_id") REFERENCES "bookings" ("id");
ALTER TABLE "host_payouts" ADD FOREIGN KEY ("host_id") REFERENCES "users" ("id");
ALTER TABLE "host_payouts" ADD FOREIGN KEY ("payout_account_id") REFERENCES "payout_accounts" ("id");
ALTER TABLE "reviews" ADD FOREIGN KEY ("booking_id") REFERENCES "bookings" ("id");
ALTER TABLE "reviews" ADD FOREIGN KEY ("author_id") REFERENCES "users" ("id");
ALTER TABLE "reviews" ADD FOREIGN KEY ("subject_id") REFERENCES "users" ("id");
ALTER TABLE "message_threads" ADD FOREIGN KEY ("listing_id") REFERENCES "listings" ("id");
ALTER TABLE "message_threads" ADD FOREIGN KEY ("guest_id") REFERENCES "users" ("id");
ALTER TABLE "message_threads" ADD FOREIGN KEY ("host_id") REFERENCES "users" ("id");
ALTER TABLE "message_threads" ADD FOREIGN KEY ("booking_id") REFERENCES "bookings" ("id");
ALTER TABLE "messages" ADD FOREIGN KEY ("thread_id") REFERENCES "message_threads" ("id");
ALTER TABLE "messages" ADD FOREIGN KEY ("sender_id") REFERENCES "users" ("id");MySQL
CREATE TABLE `users` (
`id` uuid PRIMARY KEY,
`email` varchar(254) UNIQUE NOT NULL,
`first_name` varchar(100) NOT NULL,
`last_name` varchar(100) NOT NULL,
`phone` varchar(30),
`about` text,
`avatar_storage_key` varchar(300),
`preferred_currency` char(3) NOT NULL DEFAULT 'USD',
`host_since` date COMMENT 'Set when the first listing goes live. Hosts and guests are the same users.',
`created_at` timestamptz NOT NULL DEFAULT (now()),
`deleted_at` timestamptz COMMENT 'Soft delete: past bookings and reviews must still name both sides'
);
CREATE TABLE `identity_verifications` (
`id` uuid PRIMARY KEY,
`user_id` uuid NOT NULL,
`kind` ENUM ('email', 'phone', 'government_id') NOT NULL,
`status` ENUM ('pending', 'verified', 'failed', 'expired') NOT NULL DEFAULT 'pending',
`provider_reference` varchar(100) COMMENT 'Verification vendor reference; document images stay with the vendor',
`verified_at` timestamptz,
`expires_at` timestamptz
);
CREATE TABLE `saved_listings` (
`user_id` uuid NOT NULL,
`listing_id` uuid NOT NULL,
`list_name` varchar(100) NOT NULL DEFAULT 'Favorites' COMMENT 'e.g. Summer 2027, Ski trip',
`saved_at` timestamptz NOT NULL DEFAULT (now()),
PRIMARY KEY (`user_id`, `listing_id`, `list_name`)
);
CREATE TABLE `listings` (
`id` uuid PRIMARY KEY,
`host_id` uuid NOT NULL,
`title` varchar(150) NOT NULL,
`description` text NOT NULL,
`room_type` ENUM ('entire_place', 'private_room', 'shared_room') NOT NULL,
`property_type` varchar(50) NOT NULL COMMENT 'e.g. Apartment, Cabin, Villa, Houseboat',
`address_line1` varchar(200) NOT NULL,
`city` varchar(120) NOT NULL,
`country` char(2) NOT NULL,
`latitude` numeric(9,6) NOT NULL COMMENT 'Exact point is shown only to confirmed guests; search shows a blurred area',
`longitude` numeric(9,6) NOT NULL,
`timezone` varchar(64) NOT NULL COMMENT 'IANA zone. Check-in times and calendar nights are local to the property.',
`max_guests` smallint NOT NULL,
`bedrooms` smallint NOT NULL,
`beds` smallint NOT NULL,
`bathrooms` numeric(3,1) NOT NULL COMMENT '1.5 means one full and one half bath',
`currency` char(3) NOT NULL,
`base_nightly_cents` integer NOT NULL COMMENT 'Default price for a night with no rule or override',
`cleaning_fee_cents` integer NOT NULL DEFAULT 0 COMMENT 'Charged once per stay',
`guests_included` smallint NOT NULL DEFAULT 1,
`extra_guest_fee_cents` integer NOT NULL DEFAULT 0 COMMENT 'Per night, for each guest above guests_included',
`min_nights` smallint NOT NULL DEFAULT 1,
`max_nights` smallint,
`check_in_from` time NOT NULL,
`check_out_by` time NOT NULL,
`booking_mode` ENUM ('instant', 'request') NOT NULL DEFAULT 'request',
`cancellation_policy_id` uuid NOT NULL,
`status` ENUM ('draft', 'pending_review', 'listed', 'unlisted', 'suspended') NOT NULL DEFAULT 'draft',
`created_at` timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE `listing_photos` (
`id` uuid PRIMARY KEY,
`listing_id` uuid NOT NULL,
`storage_key` varchar(300) UNIQUE NOT NULL COMMENT 'Object storage key. Image bytes never live in the database.',
`caption` varchar(200),
`position` smallint NOT NULL COMMENT 'Display order; the first is the cover photo',
`width` integer NOT NULL,
`height` integer NOT NULL,
`created_at` timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE `amenities` (
`id` uuid PRIMARY KEY,
`code` varchar(40) UNIQUE NOT NULL COMMENT 'e.g. wifi, kitchen, hot_tub, ev_charger, step_free_entrance',
`name` varchar(100) NOT NULL,
`category` ENUM ('essentials', 'kitchen', 'bathroom', 'safety', 'outdoor', 'parking', 'accessibility', 'entertainment') NOT NULL
);
CREATE TABLE `listing_amenities` (
`listing_id` uuid NOT NULL,
`amenity_id` uuid NOT NULL,
`details` varchar(200) COMMENT 'e.g. 500 Mbps, shared with one other unit',
PRIMARY KEY (`listing_id`, `amenity_id`)
);
CREATE TABLE `house_rules` (
`id` uuid PRIMARY KEY,
`listing_id` uuid NOT NULL,
`rule` ENUM ('pets', 'smoking', 'parties', 'children', 'quiet_hours', 'other') NOT NULL,
`is_allowed` boolean NOT NULL COMMENT 'e.g. pets: true, smoking: false',
`details` varchar(300) COMMENT 'e.g. Quiet hours 22:00 to 08:00, one dog under 20 kg'
);
CREATE TABLE `cancellation_policies` (
`id` uuid PRIMARY KEY,
`code` varchar(30) NOT NULL COMMENT 'e.g. flexible, moderate, strict, non_refundable',
`version` smallint NOT NULL,
`name` varchar(100) NOT NULL,
`full_refund_days_before` smallint NOT NULL COMMENT 'Full refund when cancelled at least this many days before check-in',
`partial_refund_days_before` smallint COMMENT 'Partial refund window, if any',
`partial_refund_pct` smallint COMMENT 'Share of the nightly subtotal refunded in the partial window',
`cleaning_fee_refundable` boolean NOT NULL DEFAULT true COMMENT 'Refunded whenever the stay has not started',
`effective_from` timestamptz NOT NULL
);
CREATE TABLE `calendar_nights` (
`listing_id` uuid NOT NULL,
`night` date NOT NULL COMMENT 'The date the guest sleeps there. Check-out day is not a night, so back-to-back stays fit.',
`status` ENUM ('available', 'blocked', 'held', 'booked') NOT NULL DEFAULT 'available',
`booking_id` uuid COMMENT 'Set while the night is held for a request or booked',
`price_override_cents` integer COMMENT 'Host-set price for this date; beats every rule',
`min_nights_override` smallint COMMENT 'e.g. 3-night minimum over a holiday',
`updated_at` timestamptz NOT NULL DEFAULT (now()),
PRIMARY KEY (`listing_id`, `night`)
);
CREATE TABLE `pricing_rules` (
`id` uuid PRIMARY KEY,
`listing_id` uuid NOT NULL,
`kind` ENUM ('weekend', 'seasonal', 'length_of_stay', 'early_bird', 'last_minute') NOT NULL,
`adjustment_pct` numeric(5,2) COMMENT 'Negative for a discount, positive for a markup',
`nightly_price_cents` integer COMMENT 'Alternative to a percentage: a fixed nightly price, e.g. for a season',
`start_date` date COMMENT 'Seasonal rules',
`end_date` date,
`weekend_nights` smallint COMMENT 'Weekend rules: bitmask of nights, Friday and Saturday by default',
`min_nights` smallint COMMENT 'Length-of-stay rules: 7 for weekly, 28 for monthly',
`days_before_arrival` smallint COMMENT 'Early bird (at least) and last minute (at most) rules',
`priority` smallint NOT NULL DEFAULT 0 COMMENT 'Highest wins when two nightly rules overlap',
`is_active` boolean NOT NULL DEFAULT true
);
CREATE TABLE `calendar_syncs` (
`id` uuid PRIMARY KEY,
`listing_id` uuid NOT NULL,
`direction` ENUM ('import', 'export') NOT NULL,
`feed_url` varchar(500) NOT NULL COMMENT 'iCal URL. Treated as a secret: anyone with it can read the calendar.',
`last_synced_at` timestamptz,
`last_error` varchar(300)
);
CREATE TABLE `bookings` (
`id` uuid PRIMARY KEY,
`confirmation_code` varchar(12) UNIQUE NOT NULL,
`listing_id` uuid NOT NULL,
`guest_id` uuid NOT NULL,
`host_id` uuid NOT NULL COMMENT 'Copied from the listing, so a listing changing hands never rewrites past stays',
`mode` ENUM ('instant', 'request') NOT NULL COMMENT 'Instant books confirm at once; requests wait for the host',
`status` ENUM ('requested', 'declined', 'expired', 'confirmed', 'cancelled', 'completed') NOT NULL,
`check_in` date NOT NULL,
`check_out` date NOT NULL COMMENT 'CHECK (check_out > check_in)',
`adults` smallint NOT NULL,
`children` smallint NOT NULL DEFAULT 0,
`infants` smallint NOT NULL DEFAULT 0,
`pets` smallint NOT NULL DEFAULT 0,
`currency` char(3) NOT NULL,
`guest_total_cents` integer NOT NULL COMMENT 'What the guest pays: nights plus guest-side charges',
`host_payout_cents` integer NOT NULL COMMENT 'What the host earns: nights plus host-side charges, net of the host fee',
`cancellation_policy_id` uuid NOT NULL COMMENT 'The exact policy version in force at booking',
`house_rules_accepted_at` timestamptz NOT NULL,
`request_expires_at` timestamptz COMMENT 'Requests auto-decline after 24 hours and release their nights',
`created_at` timestamptz NOT NULL DEFAULT (now()),
`confirmed_at` timestamptz
);
CREATE TABLE `booking_nights` (
`booking_id` uuid NOT NULL,
`night` date NOT NULL,
`price_cents` integer NOT NULL COMMENT 'Snapshot of the resolved nightly price',
`pricing_rule_id` uuid COMMENT 'The rule that set it; null for base price or a calendar override',
PRIMARY KEY (`booking_id`, `night`)
);
CREATE TABLE `booking_charges` (
`id` uuid PRIMARY KEY,
`booking_id` uuid NOT NULL,
`kind` ENUM ('cleaning_fee', 'extra_guest_fee', 'pet_fee', 'discount', 'service_fee', 'tax') NOT NULL,
`payer` ENUM ('guest', 'host', 'platform') NOT NULL COMMENT 'Guest-side lines add to the guest total; host-side lines reduce the payout',
`description` varchar(200) NOT NULL COMMENT 'e.g. Weekly discount 10%, Cleaning fee, Occupancy tax 6%',
`amount_cents` integer NOT NULL COMMENT 'Negative for discounts'
);
CREATE TABLE `cancellations` (
`booking_id` uuid PRIMARY KEY,
`cancelled_by` ENUM ('guest', 'host', 'platform') NOT NULL,
`cancelled_by_user_id` uuid COMMENT 'Null when support cancels on behalf of either side',
`reason` varchar(300),
`guest_refund_cents` integer NOT NULL COMMENT 'Computed from the policy version on the booking, then frozen',
`host_payout_kept_cents` integer NOT NULL COMMENT 'What the host still earns after the refund',
`host_penalty_cents` integer NOT NULL DEFAULT 0 COMMENT 'Charged when the host cancels a confirmed stay',
`cancelled_at` timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE `payment_methods` (
`id` uuid PRIMARY KEY,
`user_id` uuid NOT NULL,
`processor_token` varchar(200) NOT NULL COMMENT 'Card data stays with the payment processor; only its token is stored',
`brand` varchar(20) NOT NULL,
`last4` char(4) NOT NULL,
`expires_on` date NOT NULL
);
CREATE TABLE `guest_payments` (
`id` uuid PRIMARY KEY,
`booking_id` uuid NOT NULL,
`payment_method_id` uuid NOT NULL,
`installment` smallint NOT NULL DEFAULT 1 COMMENT 'Pay part now, part later: 1 at booking, 2 before arrival',
`amount_cents` integer NOT NULL,
`currency` char(3) NOT NULL,
`status` ENUM ('scheduled', 'succeeded', 'failed', 'cancelled') NOT NULL DEFAULT 'scheduled',
`due_at` timestamptz NOT NULL,
`processed_at` timestamptz,
`processor_reference` varchar(100) UNIQUE
);
CREATE TABLE `refunds` (
`id` uuid PRIMARY KEY,
`guest_payment_id` uuid NOT NULL,
`booking_id` uuid NOT NULL,
`amount_cents` integer NOT NULL,
`reason` ENUM ('guest_cancellation', 'host_cancellation', 'listing_issue', 'goodwill') NOT NULL,
`status` ENUM ('scheduled', 'succeeded', 'failed', 'cancelled') NOT NULL DEFAULT 'scheduled',
`processor_reference` varchar(100),
`created_at` timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE `payout_accounts` (
`id` uuid PRIMARY KEY,
`host_id` uuid NOT NULL,
`processor_account_token` varchar(200) NOT NULL COMMENT 'Connected-account id; bank details stay with the processor',
`currency` char(3) NOT NULL,
`country` char(2) NOT NULL,
`is_default` boolean NOT NULL DEFAULT false,
`verified_at` timestamptz
);
CREATE TABLE `host_payouts` (
`id` uuid PRIMARY KEY,
`booking_id` uuid NOT NULL,
`host_id` uuid NOT NULL,
`payout_account_id` uuid NOT NULL,
`amount_cents` integer NOT NULL COMMENT 'Negative for an adjustment, e.g. a host cancellation penalty',
`currency` char(3) NOT NULL,
`status` ENUM ('scheduled', 'released', 'paid', 'failed', 'reversed') NOT NULL DEFAULT 'scheduled',
`release_after` timestamptz NOT NULL COMMENT 'About 24 hours after check-in, once the guest has arrived',
`paid_at` timestamptz,
`processor_reference` varchar(100) UNIQUE
);
CREATE TABLE `reviews` (
`id` uuid PRIMARY KEY,
`booking_id` uuid NOT NULL,
`direction` ENUM ('guest_to_host', 'host_to_guest') NOT NULL,
`author_id` uuid NOT NULL,
`subject_id` uuid NOT NULL,
`overall_rating` smallint NOT NULL COMMENT '1 to 5',
`cleanliness_rating` smallint COMMENT 'Category ratings apply to guest-to-host reviews only',
`accuracy_rating` smallint,
`communication_rating` smallint,
`location_rating` smallint,
`value_rating` smallint,
`public_text` text NOT NULL,
`private_feedback` text COMMENT 'Seen only by the other party, never published',
`submitted_at` timestamptz NOT NULL DEFAULT (now()),
`published_at` timestamptz NOT NULL COMMENT 'When it becomes visible; see the table note'
);
CREATE TABLE `message_threads` (
`id` uuid PRIMARY KEY,
`listing_id` uuid NOT NULL,
`guest_id` uuid NOT NULL,
`host_id` uuid NOT NULL,
`booking_id` uuid COMMENT 'Null for an inquiry before booking',
`last_message_at` timestamptz,
`created_at` timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE `messages` (
`id` uuid PRIMARY KEY,
`thread_id` uuid NOT NULL,
`sender_id` uuid COMMENT 'Null for system messages, e.g. booking confirmed',
`body` text NOT NULL,
`was_redacted` boolean NOT NULL DEFAULT false COMMENT 'Phone numbers and emails are masked before a booking is confirmed, to keep payment on the platform',
`sent_at` timestamptz NOT NULL DEFAULT (now()),
`read_at` timestamptz
);
CREATE INDEX `identity_verifications_index_0` ON `identity_verifications` (`user_id`, `kind`);
CREATE INDEX `listings_index_1` ON `listings` (`host_id`);
CREATE INDEX `listings_index_2` ON `listings` (`country`, `city`, `status`);
CREATE INDEX `listing_photos_index_3` ON `listing_photos` (`listing_id`, `position`);
CREATE INDEX `listing_amenities_index_4` ON `listing_amenities` (`amenity_id`, `listing_id`);
CREATE INDEX `house_rules_index_5` ON `house_rules` (`listing_id`);
CREATE UNIQUE INDEX `cancellation_policies_index_6` ON `cancellation_policies` (`code`, `version`);
CREATE INDEX `calendar_nights_index_7` ON `calendar_nights` (`booking_id`);
CREATE INDEX `pricing_rules_index_8` ON `pricing_rules` (`listing_id`, `kind`);
CREATE INDEX `bookings_index_9` ON `bookings` (`listing_id`, `check_in`);
CREATE INDEX `bookings_index_10` ON `bookings` (`guest_id`, `check_in`);
CREATE INDEX `guest_payments_index_11` ON `guest_payments` (`status`, `due_at`);
CREATE INDEX `host_payouts_index_12` ON `host_payouts` (`status`, `release_after`);
CREATE UNIQUE INDEX `reviews_index_13` ON `reviews` (`booking_id`, `direction`);
CREATE INDEX `reviews_index_14` ON `reviews` (`subject_id`, `published_at`);
CREATE INDEX `message_threads_index_15` ON `message_threads` (`guest_id`, `last_message_at`);
CREATE INDEX `message_threads_index_16` ON `message_threads` (`host_id`, `last_message_at`);
CREATE INDEX `messages_index_17` ON `messages` (`thread_id`, `sent_at`);
ALTER TABLE `users` COMMENT = 'Everyone on the marketplace. A host is simply a user with listings, and most hosts travel as guests too.';
ALTER TABLE `identity_verifications` COMMENT = 'Trust checks: email, phone, government ID. Hosts can require a verified ID before accepting a booking.';
ALTER TABLE `saved_listings` COMMENT = 'Wishlists.';
ALTER TABLE `listings` COMMENT = 'A place to stay, owned by one host. Base price, cleaning fee and guest limits live here; adjustments live in pricing_rules and calendar_nights.';
ALTER TABLE `listing_photos` COMMENT = 'Listing photos. Dimensions are stored so the page can reserve space before images load.';
ALTER TABLE `amenities` COMMENT = 'The fixed amenity catalog. Search filters by code, so a typo by one host never splits a filter.';
ALTER TABLE `listing_amenities` COMMENT = 'Which amenities a listing offers.';
ALTER TABLE `house_rules` COMMENT = 'Rules the guest must accept before booking. The booking records when they were accepted.';
ALTER TABLE `cancellation_policies` COMMENT = 'Versioned rows, never edited. Changing a policy inserts a new version; a booking points at the exact version it was made under, so the refund a guest was promised can always be recomputed.';
ALTER TABLE `calendar_nights` COMMENT = 'One row per listing per night, generated for the bookable window (rolled forward daily). A booking claims its nights with one conditional UPDATE: SET status = booked, booking_id = $1 WHERE listing_id = $2 AND night >= check_in AND night < check_out AND status = available. It must touch exactly as many rows as nights booked, or the transaction rolls back. A night can carry only one booking_id, so two overlapping bookings can never both commit.';
ALTER TABLE `pricing_rules` COMMENT = 'How a night is priced. Resolution order: calendar override, then the highest-priority seasonal or weekend rule, then base_nightly_cents. Length-of-stay, early bird and last minute rules then discount the nightly subtotal. The cleaning fee is not a rule; it is a fixed per-stay amount on the listing.';
ALTER TABLE `calendar_syncs` COMMENT = 'iCal feeds to and from other sites. Imported busy dates become blocked nights, which is how hosts list on several platforms without double bookings.';
ALTER TABLE `bookings` COMMENT = 'A stay. Totals here are the sum of booking_nights and booking_charges, frozen when the guest pays.';
ALTER TABLE `booking_nights` COMMENT = 'The price of every night, as quoted. Editing rules later never changes a confirmed stay, and "why was Saturday more?" has an answer.';
ALTER TABLE `booking_charges` COMMENT = 'Every line on both receipts: cleaning fee, extra guests, pets, discounts, service fees and taxes.';
ALTER TABLE `cancellations` COMMENT = 'The outcome of a cancellation. The money math is stored, not recomputed later, so a policy change can never alter it.';
ALTER TABLE `payment_methods` COMMENT = 'Guest cards, as processor tokens.';
ALTER TABLE `guest_payments` COMMENT = 'Money in, from the guest, on the guest schedule.';
ALTER TABLE `refunds` COMMENT = 'Money back to the guest, against a specific payment, since a refund goes back to the card it came from.';
ALTER TABLE `payout_accounts` COMMENT = 'Where a host gets paid.';
ALTER TABLE `host_payouts` COMMENT = 'Money out, to the host, on the host schedule. Guest money and host money never share a row: the platform holds funds between the guest charge and the host release, so a cancellation before arrival is a refund to the guest, never a clawback from the host.';
ALTER TABLE `reviews` COMMENT = 'Two-sided and blind. When the first review of a stay arrives, its published_at is set to the deadline (check-out plus 14 days). When the second arrives, both are set to now(). Readers filter on published_at <= now(), so neither side can read the other first, and nothing has to wake up at the deadline.';
ALTER TABLE `message_threads` COMMENT = 'One conversation between a guest and a host about a listing, attached to the booking once there is one.';
ALTER TABLE `messages` COMMENT = 'Messages in a thread. Kept as the record if a dispute reaches support.';
ALTER TABLE `identity_verifications` ADD FOREIGN KEY (`user_id`) REFERENCES `users` (`id`);
ALTER TABLE `saved_listings` ADD FOREIGN KEY (`user_id`) REFERENCES `users` (`id`);
ALTER TABLE `saved_listings` ADD FOREIGN KEY (`listing_id`) REFERENCES `listings` (`id`);
ALTER TABLE `listings` ADD FOREIGN KEY (`host_id`) REFERENCES `users` (`id`);
ALTER TABLE `listings` ADD FOREIGN KEY (`cancellation_policy_id`) REFERENCES `cancellation_policies` (`id`);
ALTER TABLE `listing_photos` ADD FOREIGN KEY (`listing_id`) REFERENCES `listings` (`id`);
ALTER TABLE `listing_amenities` ADD FOREIGN KEY (`listing_id`) REFERENCES `listings` (`id`);
ALTER TABLE `listing_amenities` ADD FOREIGN KEY (`amenity_id`) REFERENCES `amenities` (`id`);
ALTER TABLE `house_rules` ADD FOREIGN KEY (`listing_id`) REFERENCES `listings` (`id`);
ALTER TABLE `calendar_nights` ADD FOREIGN KEY (`listing_id`) REFERENCES `listings` (`id`);
ALTER TABLE `calendar_nights` ADD FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`);
ALTER TABLE `pricing_rules` ADD FOREIGN KEY (`listing_id`) REFERENCES `listings` (`id`);
ALTER TABLE `calendar_syncs` ADD FOREIGN KEY (`listing_id`) REFERENCES `listings` (`id`);
ALTER TABLE `bookings` ADD FOREIGN KEY (`listing_id`) REFERENCES `listings` (`id`);
ALTER TABLE `bookings` ADD FOREIGN KEY (`guest_id`) REFERENCES `users` (`id`);
ALTER TABLE `bookings` ADD FOREIGN KEY (`host_id`) REFERENCES `users` (`id`);
ALTER TABLE `bookings` ADD FOREIGN KEY (`cancellation_policy_id`) REFERENCES `cancellation_policies` (`id`);
ALTER TABLE `booking_nights` ADD FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`);
ALTER TABLE `booking_nights` ADD FOREIGN KEY (`pricing_rule_id`) REFERENCES `pricing_rules` (`id`);
ALTER TABLE `booking_charges` ADD FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`);
ALTER TABLE `cancellations` ADD FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`);
ALTER TABLE `cancellations` ADD FOREIGN KEY (`cancelled_by_user_id`) REFERENCES `users` (`id`);
ALTER TABLE `payment_methods` ADD FOREIGN KEY (`user_id`) REFERENCES `users` (`id`);
ALTER TABLE `guest_payments` ADD FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`);
ALTER TABLE `guest_payments` ADD FOREIGN KEY (`payment_method_id`) REFERENCES `payment_methods` (`id`);
ALTER TABLE `refunds` ADD FOREIGN KEY (`guest_payment_id`) REFERENCES `guest_payments` (`id`);
ALTER TABLE `refunds` ADD FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`);
ALTER TABLE `payout_accounts` ADD FOREIGN KEY (`host_id`) REFERENCES `users` (`id`);
ALTER TABLE `host_payouts` ADD FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`);
ALTER TABLE `host_payouts` ADD FOREIGN KEY (`host_id`) REFERENCES `users` (`id`);
ALTER TABLE `host_payouts` ADD FOREIGN KEY (`payout_account_id`) REFERENCES `payout_accounts` (`id`);
ALTER TABLE `reviews` ADD FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`);
ALTER TABLE `reviews` ADD FOREIGN KEY (`author_id`) REFERENCES `users` (`id`);
ALTER TABLE `reviews` ADD FOREIGN KEY (`subject_id`) REFERENCES `users` (`id`);
ALTER TABLE `message_threads` ADD FOREIGN KEY (`listing_id`) REFERENCES `listings` (`id`);
ALTER TABLE `message_threads` ADD FOREIGN KEY (`guest_id`) REFERENCES `users` (`id`);
ALTER TABLE `message_threads` ADD FOREIGN KEY (`host_id`) REFERENCES `users` (`id`);
ALTER TABLE `message_threads` ADD FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`id`);
ALTER TABLE `messages` ADD FOREIGN KEY (`thread_id`) REFERENCES `message_threads` (`id`);
ALTER TABLE `messages` ADD FOREIGN KEY (`sender_id`) REFERENCES `users` (`id`);SQL Server
CREATE TABLE [users] (
[id] uuid PRIMARY KEY,
[email] varchar(254) UNIQUE NOT NULL,
[first_name] varchar(100) NOT NULL,
[last_name] varchar(100) NOT NULL,
[phone] varchar(30),
[about] text,
[avatar_storage_key] varchar(300),
[preferred_currency] char(3) NOT NULL DEFAULT 'USD',
[host_since] date,
[created_at] timestamptz NOT NULL DEFAULT (now()),
[deleted_at] timestamptz
)
GO
CREATE TABLE [identity_verifications] (
[id] uuid PRIMARY KEY,
[user_id] uuid NOT NULL,
[kind] nvarchar(255) NOT NULL CHECK ([kind] IN ('email', 'phone', 'government_id')),
[status] nvarchar(255) NOT NULL CHECK ([status] IN ('pending', 'verified', 'failed', 'expired')) DEFAULT 'pending',
[provider_reference] varchar(100),
[verified_at] timestamptz,
[expires_at] timestamptz
)
GO
CREATE TABLE [saved_listings] (
[user_id] uuid NOT NULL,
[listing_id] uuid NOT NULL,
[list_name] varchar(100) NOT NULL DEFAULT 'Favorites',
[saved_at] timestamptz NOT NULL DEFAULT (now()),
PRIMARY KEY ([user_id], [listing_id], [list_name])
)
GO
CREATE TABLE [listings] (
[id] uuid PRIMARY KEY,
[host_id] uuid NOT NULL,
[title] varchar(150) NOT NULL,
[description] text NOT NULL,
[room_type] nvarchar(255) NOT NULL CHECK ([room_type] IN ('entire_place', 'private_room', 'shared_room')),
[property_type] varchar(50) NOT NULL,
[address_line1] varchar(200) NOT NULL,
[city] varchar(120) NOT NULL,
[country] char(2) NOT NULL,
[latitude] numeric(9,6) NOT NULL,
[longitude] numeric(9,6) NOT NULL,
[timezone] varchar(64) NOT NULL,
[max_guests] smallint NOT NULL,
[bedrooms] smallint NOT NULL,
[beds] smallint NOT NULL,
[bathrooms] numeric(3,1) NOT NULL,
[currency] char(3) NOT NULL,
[base_nightly_cents] integer NOT NULL,
[cleaning_fee_cents] integer NOT NULL DEFAULT (0),
[guests_included] smallint NOT NULL DEFAULT (1),
[extra_guest_fee_cents] integer NOT NULL DEFAULT (0),
[min_nights] smallint NOT NULL DEFAULT (1),
[max_nights] smallint,
[check_in_from] time NOT NULL,
[check_out_by] time NOT NULL,
[booking_mode] nvarchar(255) NOT NULL CHECK ([booking_mode] IN ('instant', 'request')) DEFAULT 'request',
[cancellation_policy_id] uuid NOT NULL,
[status] nvarchar(255) NOT NULL CHECK ([status] IN ('draft', 'pending_review', 'listed', 'unlisted', 'suspended')) DEFAULT 'draft',
[created_at] timestamptz NOT NULL DEFAULT (now())
)
GO
CREATE TABLE [listing_photos] (
[id] uuid PRIMARY KEY,
[listing_id] uuid NOT NULL,
[storage_key] varchar(300) UNIQUE NOT NULL,
[caption] varchar(200),
[position] smallint NOT NULL,
[width] integer NOT NULL,
[height] integer NOT NULL,
[created_at] timestamptz NOT NULL DEFAULT (now())
)
GO
CREATE TABLE [amenities] (
[id] uuid PRIMARY KEY,
[code] varchar(40) UNIQUE NOT NULL,
[name] varchar(100) NOT NULL,
[category] nvarchar(255) NOT NULL CHECK ([category] IN ('essentials', 'kitchen', 'bathroom', 'safety', 'outdoor', 'parking', 'accessibility', 'entertainment'))
)
GO
CREATE TABLE [listing_amenities] (
[listing_id] uuid NOT NULL,
[amenity_id] uuid NOT NULL,
[details] varchar(200),
PRIMARY KEY ([listing_id], [amenity_id])
)
GO
CREATE TABLE [house_rules] (
[id] uuid PRIMARY KEY,
[listing_id] uuid NOT NULL,
[rule] nvarchar(255) NOT NULL CHECK ([rule] IN ('pets', 'smoking', 'parties', 'children', 'quiet_hours', 'other')),
[is_allowed] boolean NOT NULL,
[details] varchar(300)
)
GO
CREATE TABLE [cancellation_policies] (
[id] uuid PRIMARY KEY,
[code] varchar(30) NOT NULL,
[version] smallint NOT NULL,
[name] varchar(100) NOT NULL,
[full_refund_days_before] smallint NOT NULL,
[partial_refund_days_before] smallint,
[partial_refund_pct] smallint,
[cleaning_fee_refundable] boolean NOT NULL DEFAULT (true),
[effective_from] timestamptz NOT NULL
)
GO
CREATE TABLE [calendar_nights] (
[listing_id] uuid NOT NULL,
[night] date NOT NULL,
[status] nvarchar(255) NOT NULL CHECK ([status] IN ('available', 'blocked', 'held', 'booked')) DEFAULT 'available',
[booking_id] uuid,
[price_override_cents] integer,
[min_nights_override] smallint,
[updated_at] timestamptz NOT NULL DEFAULT (now()),
PRIMARY KEY ([listing_id], [night])
)
GO
CREATE TABLE [pricing_rules] (
[id] uuid PRIMARY KEY,
[listing_id] uuid NOT NULL,
[kind] nvarchar(255) NOT NULL CHECK ([kind] IN ('weekend', 'seasonal', 'length_of_stay', 'early_bird', 'last_minute')),
[adjustment_pct] numeric(5,2),
[nightly_price_cents] integer,
[start_date] date,
[end_date] date,
[weekend_nights] smallint,
[min_nights] smallint,
[days_before_arrival] smallint,
[priority] smallint NOT NULL DEFAULT (0),
[is_active] boolean NOT NULL DEFAULT (true)
)
GO
CREATE TABLE [calendar_syncs] (
[id] uuid PRIMARY KEY,
[listing_id] uuid NOT NULL,
[direction] nvarchar(255) NOT NULL CHECK ([direction] IN ('import', 'export')),
[feed_url] varchar(500) NOT NULL,
[last_synced_at] timestamptz,
[last_error] varchar(300)
)
GO
CREATE TABLE [bookings] (
[id] uuid PRIMARY KEY,
[confirmation_code] varchar(12) UNIQUE NOT NULL,
[listing_id] uuid NOT NULL,
[guest_id] uuid NOT NULL,
[host_id] uuid NOT NULL,
[mode] nvarchar(255) NOT NULL CHECK ([mode] IN ('instant', 'request')),
[status] nvarchar(255) NOT NULL CHECK ([status] IN ('requested', 'declined', 'expired', 'confirmed', 'cancelled', 'completed')),
[check_in] date NOT NULL,
[check_out] date NOT NULL,
[adults] smallint NOT NULL,
[children] smallint NOT NULL DEFAULT (0),
[infants] smallint NOT NULL DEFAULT (0),
[pets] smallint NOT NULL DEFAULT (0),
[currency] char(3) NOT NULL,
[guest_total_cents] integer NOT NULL,
[host_payout_cents] integer NOT NULL,
[cancellation_policy_id] uuid NOT NULL,
[house_rules_accepted_at] timestamptz NOT NULL,
[request_expires_at] timestamptz,
[created_at] timestamptz NOT NULL DEFAULT (now()),
[confirmed_at] timestamptz
)
GO
CREATE TABLE [booking_nights] (
[booking_id] uuid NOT NULL,
[night] date NOT NULL,
[price_cents] integer NOT NULL,
[pricing_rule_id] uuid,
PRIMARY KEY ([booking_id], [night])
)
GO
CREATE TABLE [booking_charges] (
[id] uuid PRIMARY KEY,
[booking_id] uuid NOT NULL,
[kind] nvarchar(255) NOT NULL CHECK ([kind] IN ('cleaning_fee', 'extra_guest_fee', 'pet_fee', 'discount', 'service_fee', 'tax')),
[payer] nvarchar(255) NOT NULL CHECK ([payer] IN ('guest', 'host', 'platform')),
[description] varchar(200) NOT NULL,
[amount_cents] integer NOT NULL
)
GO
CREATE TABLE [cancellations] (
[booking_id] uuid PRIMARY KEY,
[cancelled_by] nvarchar(255) NOT NULL CHECK ([cancelled_by] IN ('guest', 'host', 'platform')),
[cancelled_by_user_id] uuid,
[reason] varchar(300),
[guest_refund_cents] integer NOT NULL,
[host_payout_kept_cents] integer NOT NULL,
[host_penalty_cents] integer NOT NULL DEFAULT (0),
[cancelled_at] timestamptz NOT NULL DEFAULT (now())
)
GO
CREATE TABLE [payment_methods] (
[id] uuid PRIMARY KEY,
[user_id] uuid NOT NULL,
[processor_token] varchar(200) NOT NULL,
[brand] varchar(20) NOT NULL,
[last4] char(4) NOT NULL,
[expires_on] date NOT NULL
)
GO
CREATE TABLE [guest_payments] (
[id] uuid PRIMARY KEY,
[booking_id] uuid NOT NULL,
[payment_method_id] uuid NOT NULL,
[installment] smallint NOT NULL DEFAULT (1),
[amount_cents] integer NOT NULL,
[currency] char(3) NOT NULL,
[status] nvarchar(255) NOT NULL CHECK ([status] IN ('scheduled', 'succeeded', 'failed', 'cancelled')) DEFAULT 'scheduled',
[due_at] timestamptz NOT NULL,
[processed_at] timestamptz,
[processor_reference] varchar(100) UNIQUE
)
GO
CREATE TABLE [refunds] (
[id] uuid PRIMARY KEY,
[guest_payment_id] uuid NOT NULL,
[booking_id] uuid NOT NULL,
[amount_cents] integer NOT NULL,
[reason] nvarchar(255) NOT NULL CHECK ([reason] IN ('guest_cancellation', 'host_cancellation', 'listing_issue', 'goodwill')),
[status] nvarchar(255) NOT NULL CHECK ([status] IN ('scheduled', 'succeeded', 'failed', 'cancelled')) DEFAULT 'scheduled',
[processor_reference] varchar(100),
[created_at] timestamptz NOT NULL DEFAULT (now())
)
GO
CREATE TABLE [payout_accounts] (
[id] uuid PRIMARY KEY,
[host_id] uuid NOT NULL,
[processor_account_token] varchar(200) NOT NULL,
[currency] char(3) NOT NULL,
[country] char(2) NOT NULL,
[is_default] boolean NOT NULL DEFAULT (false),
[verified_at] timestamptz
)
GO
CREATE TABLE [host_payouts] (
[id] uuid PRIMARY KEY,
[booking_id] uuid NOT NULL,
[host_id] uuid NOT NULL,
[payout_account_id] uuid NOT NULL,
[amount_cents] integer NOT NULL,
[currency] char(3) NOT NULL,
[status] nvarchar(255) NOT NULL CHECK ([status] IN ('scheduled', 'released', 'paid', 'failed', 'reversed')) DEFAULT 'scheduled',
[release_after] timestamptz NOT NULL,
[paid_at] timestamptz,
[processor_reference] varchar(100) UNIQUE
)
GO
CREATE TABLE [reviews] (
[id] uuid PRIMARY KEY,
[booking_id] uuid NOT NULL,
[direction] nvarchar(255) NOT NULL CHECK ([direction] IN ('guest_to_host', 'host_to_guest')),
[author_id] uuid NOT NULL,
[subject_id] uuid NOT NULL,
[overall_rating] smallint NOT NULL,
[cleanliness_rating] smallint,
[accuracy_rating] smallint,
[communication_rating] smallint,
[location_rating] smallint,
[value_rating] smallint,
[public_text] text NOT NULL,
[private_feedback] text,
[submitted_at] timestamptz NOT NULL DEFAULT (now()),
[published_at] timestamptz NOT NULL
)
GO
CREATE TABLE [message_threads] (
[id] uuid PRIMARY KEY,
[listing_id] uuid NOT NULL,
[guest_id] uuid NOT NULL,
[host_id] uuid NOT NULL,
[booking_id] uuid,
[last_message_at] timestamptz,
[created_at] timestamptz NOT NULL DEFAULT (now())
)
GO
CREATE TABLE [messages] (
[id] uuid PRIMARY KEY,
[thread_id] uuid NOT NULL,
[sender_id] uuid,
[body] text NOT NULL,
[was_redacted] boolean NOT NULL DEFAULT (false),
[sent_at] timestamptz NOT NULL DEFAULT (now()),
[read_at] timestamptz
)
GO
CREATE INDEX [identity_verifications_index_0] ON [identity_verifications] ("user_id", "kind")
GO
CREATE INDEX [listings_index_1] ON [listings] ("host_id")
GO
CREATE INDEX [listings_index_2] ON [listings] ("country", "city", "status")
GO
CREATE INDEX [listing_photos_index_3] ON [listing_photos] ("listing_id", "position")
GO
CREATE INDEX [listing_amenities_index_4] ON [listing_amenities] ("amenity_id", "listing_id")
GO
CREATE INDEX [house_rules_index_5] ON [house_rules] ("listing_id")
GO
CREATE UNIQUE INDEX [cancellation_policies_index_6] ON [cancellation_policies] ("code", "version")
GO
CREATE INDEX [calendar_nights_index_7] ON [calendar_nights] ("booking_id")
GO
CREATE INDEX [pricing_rules_index_8] ON [pricing_rules] ("listing_id", "kind")
GO
CREATE INDEX [bookings_index_9] ON [bookings] ("listing_id", "check_in")
GO
CREATE INDEX [bookings_index_10] ON [bookings] ("guest_id", "check_in")
GO
CREATE INDEX [guest_payments_index_11] ON [guest_payments] ("status", "due_at")
GO
CREATE INDEX [host_payouts_index_12] ON [host_payouts] ("status", "release_after")
GO
CREATE UNIQUE INDEX [reviews_index_13] ON [reviews] ("booking_id", "direction")
GO
CREATE INDEX [reviews_index_14] ON [reviews] ("subject_id", "published_at")
GO
CREATE INDEX [message_threads_index_15] ON [message_threads] ("guest_id", "last_message_at")
GO
CREATE INDEX [message_threads_index_16] ON [message_threads] ("host_id", "last_message_at")
GO
CREATE INDEX [messages_index_17] ON [messages] ("thread_id", "sent_at")
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Everyone on the marketplace. A host is simply a user with listings, and most hosts travel as guests too.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'users';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Set when the first listing goes live. Hosts and guests are the same users.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'users',
@level2type = N'Column', @level2name = 'host_since';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Soft delete: past bookings and reviews must still name both sides',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'users',
@level2type = N'Column', @level2name = 'deleted_at';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Trust checks: email, phone, government ID. Hosts can require a verified ID before accepting a booking.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'identity_verifications';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Verification vendor reference; document images stay with the vendor',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'identity_verifications',
@level2type = N'Column', @level2name = 'provider_reference';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Wishlists.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'saved_listings';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'e.g. Summer 2027, Ski trip',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'saved_listings',
@level2type = N'Column', @level2name = 'list_name';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'A place to stay, owned by one host. Base price, cleaning fee and guest limits live here; adjustments live in pricing_rules and calendar_nights.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listings';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'e.g. Apartment, Cabin, Villa, Houseboat',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listings',
@level2type = N'Column', @level2name = 'property_type';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Exact point is shown only to confirmed guests; search shows a blurred area',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listings',
@level2type = N'Column', @level2name = 'latitude';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'IANA zone. Check-in times and calendar nights are local to the property.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listings',
@level2type = N'Column', @level2name = 'timezone';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = '1.5 means one full and one half bath',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listings',
@level2type = N'Column', @level2name = 'bathrooms';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Default price for a night with no rule or override',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listings',
@level2type = N'Column', @level2name = 'base_nightly_cents';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Charged once per stay',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listings',
@level2type = N'Column', @level2name = 'cleaning_fee_cents';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Per night, for each guest above guests_included',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listings',
@level2type = N'Column', @level2name = 'extra_guest_fee_cents';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Listing photos. Dimensions are stored so the page can reserve space before images load.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listing_photos';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Object storage key. Image bytes never live in the database.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listing_photos',
@level2type = N'Column', @level2name = 'storage_key';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Display order; the first is the cover photo',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listing_photos',
@level2type = N'Column', @level2name = 'position';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'The fixed amenity catalog. Search filters by code, so a typo by one host never splits a filter.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'amenities';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'e.g. wifi, kitchen, hot_tub, ev_charger, step_free_entrance',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'amenities',
@level2type = N'Column', @level2name = 'code';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Which amenities a listing offers.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listing_amenities';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'e.g. 500 Mbps, shared with one other unit',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'listing_amenities',
@level2type = N'Column', @level2name = 'details';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Rules the guest must accept before booking. The booking records when they were accepted.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'house_rules';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'e.g. pets: true, smoking: false',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'house_rules',
@level2type = N'Column', @level2name = 'is_allowed';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'e.g. Quiet hours 22:00 to 08:00, one dog under 20 kg',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'house_rules',
@level2type = N'Column', @level2name = 'details';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Versioned rows, never edited. Changing a policy inserts a new version; a booking points at the exact version it was made under, so the refund a guest was promised can always be recomputed.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'cancellation_policies';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'e.g. flexible, moderate, strict, non_refundable',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'cancellation_policies',
@level2type = N'Column', @level2name = 'code';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Full refund when cancelled at least this many days before check-in',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'cancellation_policies',
@level2type = N'Column', @level2name = 'full_refund_days_before';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Partial refund window, if any',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'cancellation_policies',
@level2type = N'Column', @level2name = 'partial_refund_days_before';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Share of the nightly subtotal refunded in the partial window',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'cancellation_policies',
@level2type = N'Column', @level2name = 'partial_refund_pct';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Refunded whenever the stay has not started',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'cancellation_policies',
@level2type = N'Column', @level2name = 'cleaning_fee_refundable';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'One row per listing per night, generated for the bookable window (rolled forward daily). A booking claims its nights with one conditional UPDATE: SET status = booked, booking_id = $1 WHERE listing_id = $2 AND night >= check_in AND night < check_out AND status = available. It must touch exactly as many rows as nights booked, or the transaction rolls back. A night can carry only one booking_id, so two overlapping bookings can never both commit.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'calendar_nights';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'The date the guest sleeps there. Check-out day is not a night, so back-to-back stays fit.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'calendar_nights',
@level2type = N'Column', @level2name = 'night';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Set while the night is held for a request or booked',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'calendar_nights',
@level2type = N'Column', @level2name = 'booking_id';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Host-set price for this date; beats every rule',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'calendar_nights',
@level2type = N'Column', @level2name = 'price_override_cents';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'e.g. 3-night minimum over a holiday',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'calendar_nights',
@level2type = N'Column', @level2name = 'min_nights_override';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'How a night is priced. Resolution order: calendar override, then the highest-priority seasonal or weekend rule, then base_nightly_cents. Length-of-stay, early bird and last minute rules then discount the nightly subtotal. The cleaning fee is not a rule; it is a fixed per-stay amount on the listing.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'pricing_rules';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Negative for a discount, positive for a markup',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'pricing_rules',
@level2type = N'Column', @level2name = 'adjustment_pct';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Alternative to a percentage: a fixed nightly price, e.g. for a season',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'pricing_rules',
@level2type = N'Column', @level2name = 'nightly_price_cents';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Seasonal rules',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'pricing_rules',
@level2type = N'Column', @level2name = 'start_date';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Weekend rules: bitmask of nights, Friday and Saturday by default',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'pricing_rules',
@level2type = N'Column', @level2name = 'weekend_nights';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Length-of-stay rules: 7 for weekly, 28 for monthly',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'pricing_rules',
@level2type = N'Column', @level2name = 'min_nights';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Early bird (at least) and last minute (at most) rules',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'pricing_rules',
@level2type = N'Column', @level2name = 'days_before_arrival';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Highest wins when two nightly rules overlap',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'pricing_rules',
@level2type = N'Column', @level2name = 'priority';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'iCal feeds to and from other sites. Imported busy dates become blocked nights, which is how hosts list on several platforms without double bookings.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'calendar_syncs';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'iCal URL. Treated as a secret: anyone with it can read the calendar.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'calendar_syncs',
@level2type = N'Column', @level2name = 'feed_url';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'A stay. Totals here are the sum of booking_nights and booking_charges, frozen when the guest pays.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'bookings';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Copied from the listing, so a listing changing hands never rewrites past stays',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'bookings',
@level2type = N'Column', @level2name = 'host_id';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Instant books confirm at once; requests wait for the host',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'bookings',
@level2type = N'Column', @level2name = 'mode';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'CHECK (check_out > check_in)',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'bookings',
@level2type = N'Column', @level2name = 'check_out';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'What the guest pays: nights plus guest-side charges',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'bookings',
@level2type = N'Column', @level2name = 'guest_total_cents';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'What the host earns: nights plus host-side charges, net of the host fee',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'bookings',
@level2type = N'Column', @level2name = 'host_payout_cents';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'The exact policy version in force at booking',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'bookings',
@level2type = N'Column', @level2name = 'cancellation_policy_id';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Requests auto-decline after 24 hours and release their nights',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'bookings',
@level2type = N'Column', @level2name = 'request_expires_at';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'The price of every night, as quoted. Editing rules later never changes a confirmed stay, and "why was Saturday more?" has an answer.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'booking_nights';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Snapshot of the resolved nightly price',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'booking_nights',
@level2type = N'Column', @level2name = 'price_cents';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'The rule that set it; null for base price or a calendar override',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'booking_nights',
@level2type = N'Column', @level2name = 'pricing_rule_id';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Every line on both receipts: cleaning fee, extra guests, pets, discounts, service fees and taxes.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'booking_charges';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Guest-side lines add to the guest total; host-side lines reduce the payout',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'booking_charges',
@level2type = N'Column', @level2name = 'payer';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'e.g. Weekly discount 10%, Cleaning fee, Occupancy tax 6%',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'booking_charges',
@level2type = N'Column', @level2name = 'description';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Negative for discounts',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'booking_charges',
@level2type = N'Column', @level2name = 'amount_cents';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'The outcome of a cancellation. The money math is stored, not recomputed later, so a policy change can never alter it.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'cancellations';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Null when support cancels on behalf of either side',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'cancellations',
@level2type = N'Column', @level2name = 'cancelled_by_user_id';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Computed from the policy version on the booking, then frozen',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'cancellations',
@level2type = N'Column', @level2name = 'guest_refund_cents';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'What the host still earns after the refund',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'cancellations',
@level2type = N'Column', @level2name = 'host_payout_kept_cents';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Charged when the host cancels a confirmed stay',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'cancellations',
@level2type = N'Column', @level2name = 'host_penalty_cents';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Guest cards, as processor tokens.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'payment_methods';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Card data stays with the payment processor; only its token is stored',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'payment_methods',
@level2type = N'Column', @level2name = 'processor_token';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Money in, from the guest, on the guest schedule.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'guest_payments';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Pay part now, part later: 1 at booking, 2 before arrival',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'guest_payments',
@level2type = N'Column', @level2name = 'installment';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Money back to the guest, against a specific payment, since a refund goes back to the card it came from.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'refunds';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Where a host gets paid.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'payout_accounts';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Connected-account id; bank details stay with the processor',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'payout_accounts',
@level2type = N'Column', @level2name = 'processor_account_token';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Money out, to the host, on the host schedule. Guest money and host money never share a row: the platform holds funds between the guest charge and the host release, so a cancellation before arrival is a refund to the guest, never a clawback from the host.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'host_payouts';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Negative for an adjustment, e.g. a host cancellation penalty',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'host_payouts',
@level2type = N'Column', @level2name = 'amount_cents';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'About 24 hours after check-in, once the guest has arrived',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'host_payouts',
@level2type = N'Column', @level2name = 'release_after';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Two-sided and blind. When the first review of a stay arrives, its published_at is set to the deadline (check-out plus 14 days). When the second arrives, both are set to now(). Readers filter on published_at <= now(), so neither side can read the other first, and nothing has to wake up at the deadline.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'reviews';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = '1 to 5',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'reviews',
@level2type = N'Column', @level2name = 'overall_rating';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Category ratings apply to guest-to-host reviews only',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'reviews',
@level2type = N'Column', @level2name = 'cleanliness_rating';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Seen only by the other party, never published',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'reviews',
@level2type = N'Column', @level2name = 'private_feedback';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'When it becomes visible; see the table note',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'reviews',
@level2type = N'Column', @level2name = 'published_at';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'One conversation between a guest and a host about a listing, attached to the booking once there is one.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'message_threads';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Null for an inquiry before booking',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'message_threads',
@level2type = N'Column', @level2name = 'booking_id';
GO
EXEC sp_addextendedproperty
@name = N'Table_Description',
@value = 'Messages in a thread. Kept as the record if a dispute reaches support.',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'messages';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Null for system messages, e.g. booking confirmed',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'messages',
@level2type = N'Column', @level2name = 'sender_id';
GO
EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'Phone numbers and emails are masked before a booking is confirmed, to keep payment on the platform',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'messages',
@level2type = N'Column', @level2name = 'was_redacted';
GO
ALTER TABLE [identity_verifications] ADD FOREIGN KEY ([user_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [saved_listings] ADD FOREIGN KEY ([user_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [saved_listings] ADD FOREIGN KEY ([listing_id]) REFERENCES [listings] ([id])
GO
ALTER TABLE [listings] ADD FOREIGN KEY ([host_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [listings] ADD FOREIGN KEY ([cancellation_policy_id]) REFERENCES [cancellation_policies] ([id])
GO
ALTER TABLE [listing_photos] ADD FOREIGN KEY ([listing_id]) REFERENCES [listings] ([id])
GO
ALTER TABLE [listing_amenities] ADD FOREIGN KEY ([listing_id]) REFERENCES [listings] ([id])
GO
ALTER TABLE [listing_amenities] ADD FOREIGN KEY ([amenity_id]) REFERENCES [amenities] ([id])
GO
ALTER TABLE [house_rules] ADD FOREIGN KEY ([listing_id]) REFERENCES [listings] ([id])
GO
ALTER TABLE [calendar_nights] ADD FOREIGN KEY ([listing_id]) REFERENCES [listings] ([id])
GO
ALTER TABLE [calendar_nights] ADD FOREIGN KEY ([booking_id]) REFERENCES [bookings] ([id])
GO
ALTER TABLE [pricing_rules] ADD FOREIGN KEY ([listing_id]) REFERENCES [listings] ([id])
GO
ALTER TABLE [calendar_syncs] ADD FOREIGN KEY ([listing_id]) REFERENCES [listings] ([id])
GO
ALTER TABLE [bookings] ADD FOREIGN KEY ([listing_id]) REFERENCES [listings] ([id])
GO
ALTER TABLE [bookings] ADD FOREIGN KEY ([guest_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [bookings] ADD FOREIGN KEY ([host_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [bookings] ADD FOREIGN KEY ([cancellation_policy_id]) REFERENCES [cancellation_policies] ([id])
GO
ALTER TABLE [booking_nights] ADD FOREIGN KEY ([booking_id]) REFERENCES [bookings] ([id])
GO
ALTER TABLE [booking_nights] ADD FOREIGN KEY ([pricing_rule_id]) REFERENCES [pricing_rules] ([id])
GO
ALTER TABLE [booking_charges] ADD FOREIGN KEY ([booking_id]) REFERENCES [bookings] ([id])
GO
ALTER TABLE [cancellations] ADD FOREIGN KEY ([booking_id]) REFERENCES [bookings] ([id])
GO
ALTER TABLE [cancellations] ADD FOREIGN KEY ([cancelled_by_user_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [payment_methods] ADD FOREIGN KEY ([user_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [guest_payments] ADD FOREIGN KEY ([booking_id]) REFERENCES [bookings] ([id])
GO
ALTER TABLE [guest_payments] ADD FOREIGN KEY ([payment_method_id]) REFERENCES [payment_methods] ([id])
GO
ALTER TABLE [refunds] ADD FOREIGN KEY ([guest_payment_id]) REFERENCES [guest_payments] ([id])
GO
ALTER TABLE [refunds] ADD FOREIGN KEY ([booking_id]) REFERENCES [bookings] ([id])
GO
ALTER TABLE [payout_accounts] ADD FOREIGN KEY ([host_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [host_payouts] ADD FOREIGN KEY ([booking_id]) REFERENCES [bookings] ([id])
GO
ALTER TABLE [host_payouts] ADD FOREIGN KEY ([host_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [host_payouts] ADD FOREIGN KEY ([payout_account_id]) REFERENCES [payout_accounts] ([id])
GO
ALTER TABLE [reviews] ADD FOREIGN KEY ([booking_id]) REFERENCES [bookings] ([id])
GO
ALTER TABLE [reviews] ADD FOREIGN KEY ([author_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [reviews] ADD FOREIGN KEY ([subject_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [message_threads] ADD FOREIGN KEY ([listing_id]) REFERENCES [listings] ([id])
GO
ALTER TABLE [message_threads] ADD FOREIGN KEY ([guest_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [message_threads] ADD FOREIGN KEY ([host_id]) REFERENCES [users] ([id])
GO
ALTER TABLE [message_threads] ADD FOREIGN KEY ([booking_id]) REFERENCES [bookings] ([id])
GO
ALTER TABLE [messages] ADD FOREIGN KEY ([thread_id]) REFERENCES [message_threads] ([id])
GO
ALTER TABLE [messages] ADD FOREIGN KEY ([sender_id]) REFERENCES [users] ([id])
GOHow to use this template
- Open the ER diagram to see the tables and how they relate.
- Copy it into your workspace. You get your own editable copy, in DBML.
- Export it as PostgreSQL, MySQL, or SQL Server DDL, or as Prisma, Drizzle, SQLAlchemy, TypeScript, Zod or C# models.
The copy opens in DB Planner’s ER diagram tool, with the schema as text in the DBML editor beside it. Have a database already? Turn its SQL into an ER diagram instead.
Frequently asked questions
- Which table is at the centre of the Vacation Rental Marketplace database schema?
- users. It is referenced by 11 other tables: bookings, cancellations, host_payouts, identity_verifications, listings and 6 more.
- How is bookings related to users?
- bookings.guest_id references users.id, a many to one relationship. All 40 relationships in the schema are listed on this page.
- Which table in the Vacation Rental Marketplace database schema has the most columns?
- listings, with 29 columns, followed by bookings (21) and reviews (15). The schema has 214 columns across 24 tables.
- Can I export it to PostgreSQL or MySQL?
- Yes. Every DB Planner template exports as DBML, as PostgreSQL, MySQL, or SQL Server DDL, and as C# models.
- Is this template free?
- Yes. You can open it in the browser without an account, and copy it into your own workspace with a free DB Planner account.
- Can I change it after copying it?
- Yes. A copy is yours: you can rename tables, add columns, and export it. Changes the author makes later do not affect your copy.