berrypod/priv/repo/migrations/20260401095806_create_reviews.exs
jamey 8dc17a6f4d
All checks were successful
deploy / deploy (push) Successful in 1m4s
add reviews schema and context (phase 2)
- Create reviews table with product/order associations
- Add Review schema with create/update/moderation changesets
- Add Reviews context with CRUD, purchase verification, aggregates
- Add get_images/1 to Media, get_variant/1 to Products
- 23 tests covering all context functions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 10:34:07 +01:00

28 lines
872 B
Elixir

defmodule Berrypod.Repo.Migrations.CreateReviews do
use Ecto.Migration
def change do
create table(:reviews, primary_key: false) do
add :id, :binary_id, primary_key: true
add :product_id, references(:products, type: :binary_id, on_delete: :delete_all),
null: false
add :order_id, references(:orders, type: :binary_id, on_delete: :nilify_all)
add :email, :string, null: false
add :author_name, :string, null: false
add :rating, :integer, null: false
add :title, :string
add :body, :text
add :status, :string, null: false, default: "pending"
add :image_ids, {:array, :binary_id}, default: []
timestamps(type: :utc_datetime)
end
create unique_index(:reviews, [:email, :product_id])
create index(:reviews, [:product_id, :status])
create index(:reviews, [:status])
end
end