add reviews schema and context (phase 2)
All checks were successful
deploy / deploy (push) Successful in 1m4s
All checks were successful
deploy / deploy (push) Successful in 1m4s
- 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>
This commit is contained in:
27
priv/repo/migrations/20260401095806_create_reviews.exs
Normal file
27
priv/repo/migrations/20260401095806_create_reviews.exs
Normal file
@@ -0,0 +1,27 @@
|
||||
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
|
||||
Reference in New Issue
Block a user