defmodule PolicyService.Repo.Migrations.CreatePolicyApplications do use Ecto.Migration def change do create table(:policy_applications, primary_key: false) do add :id, :string, primary_key: true add :application_id, :string, null: false add :org_id, :string, null: false add :submitted_by, :string, null: false # "car" | "life" | "fire_structure" | "fire_contents" add :policy_type, :string, null: false # Insured — full map, shape varies by individual vs corporate add :insured, :map, default: %{} # Buyer — full map, shape varies by individual vs corporate add :buyer, :map, default: %{} # Insured object — policy-type-specific details, shape varies by policy_type add :insured_object, :map, default: %{} # Providers + quotes add :selected_providers, {:array, :string}, default: [] add :quotes, :map, default: %{} # Accepted plan add :accepted_plan_id, :string add :accepted_by, :string # Issued policy add :provider_policy_number, :string add :premium, :decimal add :effective_date, :date add :expiry_date, :date # Status + timestamps add :status, :string, null: false add :submitted_at, :utc_datetime_usec add :solicitation_sent_at, :utc_datetime_usec add :issued_at, :utc_datetime_usec timestamps(type: :utc_datetime_usec) end create index(:policy_applications, [:org_id]) create index(:policy_applications, [:policy_type]) create index(:policy_applications, [:status]) create index(:policy_applications, [:org_id, :status]) create index(:policy_applications, [:org_id, :policy_type]) create index(:policy_applications, [:org_id, :policy_type, :status]) end end