audit and sync
This commit is contained in:
18
db/migrations/20260119130000_audit_log.sql
Normal file
18
db/migrations/20260119130000_audit_log.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- migrate:up
|
||||
|
||||
create table if not exists audit_log (
|
||||
id bigserial primary key,
|
||||
tenant_id uuid not null references tenants(id) on delete cascade,
|
||||
entity_type text not null, -- 'product' | 'user' | 'order'
|
||||
entity_id text not null, -- woo_product_id, wa_chat_id, etc.
|
||||
action text not null, -- 'create' | 'update' | 'delete' | 'sync_from_woo' | 'push_to_woo'
|
||||
changes jsonb, -- { field: { old, new } }
|
||||
actor text not null default 'system', -- 'system' | 'webhook' | 'ui'
|
||||
created_at timestamptz not null default now()
|
||||
);
|
||||
|
||||
create index if not exists audit_log_entity_idx on audit_log(tenant_id, entity_type, entity_id);
|
||||
create index if not exists audit_log_created_idx on audit_log(tenant_id, created_at desc);
|
||||
|
||||
-- migrate:down
|
||||
drop table if exists audit_log;
|
||||
Reference in New Issue
Block a user