feat: add Products context with provider integration (Phase 1)
Implement the schema foundation for syncing products from POD providers like Printify. This includes encrypted credential storage, product/variant schemas, and an Oban worker for background sync. New modules: - Vault: AES-256-GCM encryption for API keys - Products context: CRUD and sync operations for products - Provider behaviour: abstraction for POD provider implementations - ProductSyncWorker: Oban job for async product sync Schemas: ProviderConnection, Product, ProductImage, ProductVariant Also reorganizes Printify client to lib/simpleshop_theme/clients/ and mockup generator to lib/simpleshop_theme/mockups/ for better structure. 134 tests added covering all new functionality. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
defmodule SimpleshopTheme.Repo.Migrations.CreateProviderConnections do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:provider_connections, primary_key: false) do
|
||||
add :id, :binary_id, primary_key: true
|
||||
add :provider_type, :string, null: false
|
||||
add :name, :string, null: false
|
||||
add :enabled, :boolean, default: true, null: false
|
||||
add :api_key_encrypted, :binary
|
||||
add :config, :map, default: %{}
|
||||
add :last_synced_at, :utc_datetime
|
||||
add :sync_status, :string, default: "pending"
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
create unique_index(:provider_connections, [:provider_type])
|
||||
end
|
||||
end
|
||||
27
priv/repo/migrations/20260128235846_create_products.exs
Normal file
27
priv/repo/migrations/20260128235846_create_products.exs
Normal file
@@ -0,0 +1,27 @@
|
||||
defmodule SimpleshopTheme.Repo.Migrations.CreateProducts do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:products, primary_key: false) do
|
||||
add :id, :binary_id, primary_key: true
|
||||
add :provider_connection_id, references(:provider_connections, type: :binary_id, on_delete: :delete_all), null: false
|
||||
add :provider_product_id, :string, null: false
|
||||
add :title, :string, null: false
|
||||
add :description, :text
|
||||
add :slug, :string, null: false
|
||||
add :status, :string, default: "active", null: false
|
||||
add :visible, :boolean, default: true, null: false
|
||||
add :category, :string
|
||||
add :provider_data, :map, default: %{}
|
||||
add :checksum, :string
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
create unique_index(:products, [:slug])
|
||||
create unique_index(:products, [:provider_connection_id, :provider_product_id])
|
||||
create index(:products, [:status])
|
||||
create index(:products, [:visible])
|
||||
create index(:products, [:category])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
defmodule SimpleshopTheme.Repo.Migrations.CreateProductImages do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:product_images, 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 :src, :string, null: false
|
||||
add :position, :integer, default: 0, null: false
|
||||
add :alt, :string
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
# Composite index covers queries on product_id alone (leftmost prefix)
|
||||
create index(:product_images, [:product_id, :position])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,27 @@
|
||||
defmodule SimpleshopTheme.Repo.Migrations.CreateProductVariants do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:product_variants, 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 :provider_variant_id, :string, null: false
|
||||
add :title, :string, null: false
|
||||
add :sku, :string
|
||||
add :price, :integer, null: false
|
||||
add :compare_at_price, :integer
|
||||
add :cost, :integer
|
||||
add :options, :map, default: %{}
|
||||
add :is_enabled, :boolean, default: true, null: false
|
||||
add :is_available, :boolean, default: true, null: false
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
create unique_index(:product_variants, [:product_id, :provider_variant_id])
|
||||
create index(:product_variants, [:product_id])
|
||||
create index(:product_variants, [:sku])
|
||||
create index(:product_variants, [:is_enabled])
|
||||
create index(:product_variants, [:is_available])
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user