@startuml
title Before: Provision SQL Relies on Runtime Search Path
skinparam backgroundColor #FFFFFF
skinparam componentStyle rectangle
skinparam defaultFontName Consolas
skinparam defaultFontColor #000000
skinparam ArrowColor #1F2937
skinparam packageBorderColor #1F2937
skinparam packageFontColor #000000
skinparam databaseBorderColor #1F2937
skinparam databaseFontColor #000000

package "Server Startup" #E8F1FF {
  component "ensure_auth_schema_provisioned(auth_schema)" as ensure
  component "CREATE SCHEMA IF NOT EXISTS\n<auth_schema>" as create_schema
  component "SET LOCAL search_path\nTO <auth_schema>" as set_path
  component "sql/provision.sql\nunqualified DDL" as provision
}

package "Provision SQL Before" #FFF7E6 {
  component "CREATE TABLE IF NOT EXISTS\nusers / sessions / accounts" as tables
  component "REFERENCES users(id)" as fks
  component "CREATE INDEX ... ON users" as indexes
}

database "PostgreSQL" as db

ensure --> create_schema
create_schema --> db
ensure --> set_path
set_path --> db
ensure --> provision
provision --> tables
provision --> fks
provision --> indexes
tables --> db : lands wherever search_path points
fks --> db : resolves by search_path
indexes --> db : resolves by search_path

note right of provision
The provisioning file does not name athena explicitly.
Direct psql use or future startup changes can place objects
outside the intended athena schema.
end note
@enduml
