Entity relationships
core.Property is the core asset; mdm holds master data; dbo holds Route Planner transactions. Deployed by database/sql/01_AGRAAJA_POI_RoutePlanner_v2.sql.
Master data · mdm
Route Planner · dbo
Kept from v2
- Property is the core business asset (core.Property, PropertyGUID); no Hotel entity and no copy of Property.
- mdm.POI is global, reusable master data; a POI is never duplicated because several properties recommend it.
- mdm.POIProperty is the many-to-many curation: recommended, featured, visibility, ordering, travel and commercial settings.
- Hierarchical classification: POICategory (with parent) and POIType.
- Route Planner in dbo references POIs but snapshots name, address and coordinates on each stop.
- The first stop is the property (PROPERTY_ORIGIN) without a duplicate POI; custom stops are allowed.
- SQL Server GEOGRAPHY with a spatial index for proximity; routing results from an external engine persisted in RoutePlanLeg.
- DistanceFromPropertyKM (proximity) and RoutePlanLeg.DistanceKM (journey) stay separate measures.
- Location tracking only with explicit guest consent and a retention policy.
Next iteration
- Google Routes / HERE / Mapbox RoutingProvider for traffic-aware legs and geometry (the estimate stays the offline fallback).
- POI ingestion job: provider feeds into PENDING records, de-duplicated on POIExternalReference and the 75 m rule, verified in the console.
- Recommendation ranking per guest (tags, stay context, time of day) feeding DisplaySequence or a separate score.
- Links to bookable experiences, restaurant reservations, spa and transport requests from a stop (the v2 "request services" step).
- Engagement events (impression, open, add to plan, visit) into the analytics store for recommendation conversion.
Refinements
Each reference appears as a comment in the SQL script.
| Ref | Area | v2 as written | Refinement | Why |
|---|---|---|---|---|
R1 | Association history | UNIQUE (PropertyGUID, POIGUID) together with EffectiveFrom/To and RecordStatus | Filtered unique index: one ACTIVE association per property and POI. Ending sets ENDED and keeps the row; re-linking adds a new row | The plain unique key made "one current association" impossible to combine with history |
R2 | Spatial column | GeoLocation GEOGRAPHY NULL, populated separately | NOT NULL, set from Latitude/Longitude (SRID 4326) inside usp_POI_Upsert only | Proximity search can never miss a POI or use stale coordinates |
R2b | Same-route integrity | Leg stops and stop events "validated by the application" | Composite foreign keys (RoutePlanGUID, StopGUID) on legs and events; events also prove their execution belongs to the route | The database enforces it; no application can store a leg between two routes |
R3 | Type within category | Noted as an application validation | Composite FK (POITypeGUID, POICategoryGUID) to a unique key on POIType | A museum type cannot sit under Dining, whatever writes the row |
R4 | Opening hours | POIOperatingHours listed ("by day and seasonal period") with no DDL | SeasonCode + ValidFrom/ValidTo + DayOfWeek + SessionNo, plus POIHoursException; fn_POI_IsOpenAt resolves the season | Split sessions (Friday prayer break), late-night sessions, Ramadan and public holidays |
R5 | Distance upkeep | DistanceFromPropertyKM "calculated", no mechanism | Calculated by the procedures on link, on POI move and by usp_POIProperty_RefreshDistances; DistanceCalculatedAt recorded | The guest feed reads a stored value and it never goes stale silently |
R6 | Status and code values | Free-text NVARCHAR(30) columns | CHECK constraints with upper-case codes for every status, type, mode and event; "public transport" = TRANSIT | Web, API and Flutter share one vocabulary; bad values are rejected at source |
R6b | Stop type rule | POIGUID nullable for custom stops | CHECK: POI stops must have a POIGUID; origin, custom and final stops must not; one origin per route | No half-formed stops |
R7 | Ratings | AverageRating on the POI | mdm.POIProviderRating, one row per provider with count and retrieval time | Provider terms differ and mixed averages mislead guests |
R8 | Provenance and de-duplication | Listed as a next step | Source, LastVerifiedAt, POIExternalReference unique on (Provider, ExternalId); upsert refuses the same name within 75 m (50005) | Ingestion from several feeds without duplicates; for Google keep the place_id only |
R9 | Missing DDL | POIContact, POIMedia, POIFacility named only | Tables created; mdm.Facility reference list behind POIFacility; media keeps an attribution line | Complete physical model |
R10 | Tenancy | Not addressed | OwnerTenantGUID on POI (NULL = global AGRAAJA POI); TenantGUID copied to RoutePlan; every procedure takes @TenantGUID | Isolation enforced in the data layer as well as the API |
R11 | Business numbers | POICode and RoutePlanNumber required, no generator | Sequences mdm.POISequence and dbo.RoutePlanNumberSequence (POI-1021, RP-2026-000042) | Readable references for staff and guests |
R12 | Concurrency | None | Integer Version on POI, POIProperty and RoutePlan; procedures refuse stale writes (50009, HTTP 409) | Two curators cannot overwrite each other silently |
R13 | Guest rendering | Not specified | ColorHex and IconKey on POICategory | Console, Guest web and Flutter look the same |
R14 | Planner inputs | Not specified | ShortDescription, Locality, TypicalVisitMinutes on POI; DefaultVisitMinutes on POIType | Cards and itineraries without extra calls |
R15 | Languages | Single language | mdm.POITranslation (Arabic, English, guest languages) with fallback | Guests see their language |
R16 | Association grouping | IsRecommended / IsFeatured only | AssociationType NEARBY, RECOMMENDED, PARTNER, AFFILIATED, ESSENTIAL (flags kept) | Guest App sections (Essentials) and partner reporting |
R17 | Return to property | FINAL_DESTINATION type only | ReturnToOrigin on RoutePlan; the save procedure adds PROPERTY_ORIGIN and FINAL_DESTINATION from core.Property | Clients send visits only; origin and return are always correct |
R18 | Recalculation | LastCalculatedAt on legs | RoutingProvider, CalculationVersion and LastCalculatedAt on the header | Know which engine and run produced the timings |
R19 | Leg geometry for apps | RouteGeometry GEOGRAPHY | Kept, plus EncodedPolyline and JSON-checked RouteInstructions | Flutter maps draw a polyline without spatial conversion |
R20 | Live execution | Several executions possible at once | Filtered unique index: one STARTED or PAUSED execution per route; CurrentStopSequence | One truth for "where is the guest in the trip" |
R21 | Consent and retention | Stated as a principle | LocationConsentGiven/At; CHECK forbids a stored position without consent; usp_RouteExecution_PurgeLocations clears positions after N days | The principle is enforced by the schema and a scheduled job |
R22 | City & Country Master Tables | Free-text City and CountryCode on POI | mdm.Country and mdm.City master tables with ISO codes, states/emirates, foreign keys, and cascading UI dropdowns | Standardised master data eliminates spelling variations and enables structured multi-city filtering and curation |