berrypod/priv/repo/migrations/20260207005141_create_orders.exs
jamey ff1bc483b9 feat: add Stripe checkout, order persistence, and webhook handling
Stripe-hosted Checkout integration with full order lifecycle:
- stripity_stripe ~> 3.2 with sandbox/prod config via env vars
- Order and OrderItem schemas with price snapshots at purchase time
- CheckoutController creates pending order then redirects to Stripe
- StripeWebhookController verifies signatures and confirms payment
- Success page with real-time PubSub updates from webhook
- Shop flash messages for checkout error feedback
- Cart cleared after successful payment

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 08:30:17 +00:00

40 lines
1.3 KiB
Elixir

defmodule SimpleshopTheme.Repo.Migrations.CreateOrders do
use Ecto.Migration
def change do
create table(:orders, primary_key: false) do
add :id, :binary_id, primary_key: true
add :order_number, :string, null: false
add :stripe_session_id, :string
add :stripe_payment_intent_id, :string
add :payment_status, :string, null: false, default: "pending"
add :customer_email, :string
add :shipping_address, :map, default: %{}
add :subtotal, :integer, null: false
add :total, :integer, null: false
add :currency, :string, null: false, default: "gbp"
add :metadata, :map, default: %{}
timestamps(type: :utc_datetime)
end
create unique_index(:orders, [:order_number])
create unique_index(:orders, [:stripe_session_id])
create index(:orders, [:payment_status])
create table(:order_items, primary_key: false) do
add :id, :binary_id, primary_key: true
add :order_id, references(:orders, type: :binary_id, on_delete: :delete_all), null: false
add :variant_id, :string, null: false
add :product_name, :string, null: false
add :variant_title, :string
add :quantity, :integer, null: false
add :unit_price, :integer, null: false
timestamps(type: :utc_datetime)
end
create index(:order_items, [:order_id])
end
end