separated in modules
This commit is contained in:
54
db/migrations/20260114132000_woo_products_snapshot.sql
Normal file
54
db/migrations/20260114132000_woo_products_snapshot.sql
Normal file
@@ -0,0 +1,54 @@
|
||||
-- migrate:up
|
||||
create table if not exists woo_snapshot_runs (
|
||||
id bigserial primary key,
|
||||
tenant_id uuid not null references tenants(id) on delete cascade,
|
||||
source text not null, -- csv | api | webhook
|
||||
total_items integer not null default 0,
|
||||
created_at timestamptz not null default now()
|
||||
);
|
||||
|
||||
create table if not exists woo_products_snapshot (
|
||||
tenant_id uuid not null references tenants(id) on delete cascade,
|
||||
woo_id integer not null,
|
||||
type text not null, -- simple | variable | variation
|
||||
parent_id integer null,
|
||||
name text not null,
|
||||
slug text null,
|
||||
status text null,
|
||||
catalog_visibility text null,
|
||||
price_regular numeric(12,2) null,
|
||||
price_sale numeric(12,2) null,
|
||||
price_current numeric(12,2) null,
|
||||
stock_status text null,
|
||||
stock_qty integer null,
|
||||
backorders text null,
|
||||
categories jsonb not null default '[]'::jsonb,
|
||||
tags jsonb not null default '[]'::jsonb,
|
||||
attributes_normalized jsonb not null default '{}'::jsonb,
|
||||
date_modified timestamptz null,
|
||||
run_id bigint null references woo_snapshot_runs(id) on delete set null,
|
||||
raw jsonb not null default '{}'::jsonb,
|
||||
updated_at timestamptz not null default now(),
|
||||
primary key (tenant_id, woo_id)
|
||||
);
|
||||
|
||||
create index if not exists woo_snapshot_tenant_type_idx
|
||||
on woo_products_snapshot (tenant_id, type);
|
||||
|
||||
create index if not exists woo_snapshot_tenant_parent_idx
|
||||
on woo_products_snapshot (tenant_id, parent_id);
|
||||
|
||||
create index if not exists woo_snapshot_tenant_status_idx
|
||||
on woo_products_snapshot (tenant_id, status);
|
||||
|
||||
create or replace view sellable_items as
|
||||
select *
|
||||
from woo_products_snapshot
|
||||
where lower(type) in ('simple', 'variation')
|
||||
and coalesce(lower(status), 'publish') = 'publish'
|
||||
and coalesce(lower(catalog_visibility), 'visible') not in ('hidden');
|
||||
|
||||
-- migrate:down
|
||||
drop view if exists sellable_items;
|
||||
drop table if exists woo_products_snapshot;
|
||||
drop table if exists woo_snapshot_runs;
|
||||
17
db/migrations/20260115123000_drop_woo_products_cache.sql
Normal file
17
db/migrations/20260115123000_drop_woo_products_cache.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
-- migrate:up
|
||||
drop table if exists woo_products_cache;
|
||||
|
||||
-- migrate:down
|
||||
create table if not exists woo_products_cache (
|
||||
tenant_id uuid not null references tenants(id) on delete cascade,
|
||||
woo_product_id integer not null,
|
||||
name text not null,
|
||||
sku text,
|
||||
price numeric(12,2),
|
||||
currency text,
|
||||
refreshed_at timestamptz not null default now(),
|
||||
payload jsonb not null default '{}'::jsonb,
|
||||
created_at timestamptz not null default now(),
|
||||
updated_at timestamptz not null default now(),
|
||||
primary key (tenant_id, woo_product_id)
|
||||
);
|
||||
Reference in New Issue
Block a user