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.
R1Association historyUNIQUE (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 historyR2Spatial columnGeoLocation 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 coordinatesR2bSame-route integrityLeg 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 routesR3Type within categoryNoted as an application validation
Composite FK (POITypeGUID, POICategoryGUID) to a unique key on POIType
A museum type cannot sit under Dining, whatever writes the rowR4Opening hoursPOIOperatingHours 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 holidaysR5Distance upkeepDistanceFromPropertyKM "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 silentlyR6Status and code valuesFree-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 sourceR6bStop type rulePOIGUID 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 stopsR7RatingsAverageRating on the POI
mdm.POIProviderRating, one row per provider with count and retrieval time
Provider terms differ and mixed averages mislead guestsR8Provenance and de-duplicationListed 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 onlyR9Missing DDLPOIContact, POIMedia, POIFacility named only
Tables created; mdm.Facility reference list behind POIFacility; media keeps an attribution line
Complete physical modelR10TenancyNot 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 APIR11Business numbersPOICode and RoutePlanNumber required, no generator
Sequences mdm.POISequence and dbo.RoutePlanNumberSequence (POI-1021, RP-2026-000042)
Readable references for staff and guestsR12ConcurrencyNone
Integer Version on POI, POIProperty and RoutePlan; procedures refuse stale writes (50009, HTTP 409)
Two curators cannot overwrite each other silentlyR13Guest renderingNot specified
ColorHex and IconKey on POICategory
Console, Guest web and Flutter look the sameR14Planner inputsNot specified
ShortDescription, Locality, TypicalVisitMinutes on POI; DefaultVisitMinutes on POIType
Cards and itineraries without extra callsR15LanguagesSingle language
mdm.POITranslation (Arabic, English, guest languages) with fallback
Guests see their languageR16Association groupingIsRecommended / IsFeatured only
AssociationType NEARBY, RECOMMENDED, PARTNER, AFFILIATED, ESSENTIAL (flags kept)
Guest App sections (Essentials) and partner reportingR17Return to propertyFINAL_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 correctR18RecalculationLastCalculatedAt on legs
RoutingProvider, CalculationVersion and LastCalculatedAt on the header
Know which engine and run produced the timingsR19Leg geometry for appsRouteGeometry GEOGRAPHY
Kept, plus EncodedPolyline and JSON-checked RouteInstructions
Flutter maps draw a polyline without spatial conversionR20Live executionSeveral 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"R21Consent and retentionStated 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 jobR22City & Country Master TablesFree-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