Add native Olist composition sync
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m24s

This commit is contained in:
Cauê Faleiros
2026-08-10 11:26:38 -03:00
parent e85dbe6f10
commit 1a430d4fb0
12 changed files with 669 additions and 5 deletions

View File

@@ -277,6 +277,47 @@ const initDB = async () => {
);
`);
await pool.query(`
CREATE TABLE IF NOT EXISTS olist_connections (
id SMALLINT PRIMARY KEY CHECK (id = 1),
access_token_ciphertext TEXT NOT NULL,
access_token_iv VARCHAR(64) NOT NULL,
refresh_token_ciphertext TEXT NOT NULL,
refresh_token_iv VARCHAR(64) NOT NULL,
token_expires_at TIMESTAMPTZ,
connected_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
`);
await pool.query(`
CREATE TABLE IF NOT EXISTS olist_oauth_states (
state_hash VARCHAR(128) PRIMARY KEY,
expires_at TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
`);
await pool.query(`
CREATE TABLE IF NOT EXISTS olist_sync_runs (
id SERIAL PRIMARY KEY,
trigger VARCHAR(30) NOT NULL,
mode VARCHAR(20) NOT NULL,
status VARCHAR(20) NOT NULL,
started_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
completed_at TIMESTAMPTZ,
products_scanned INTEGER NOT NULL DEFAULT 0,
manufactured_products INTEGER NOT NULL DEFAULT 0,
imported INTEGER NOT NULL DEFAULT 0,
component_count INTEGER NOT NULL DEFAULT 0,
reference_count INTEGER NOT NULL DEFAULT 0,
skipped_reference_count INTEGER NOT NULL DEFAULT 0,
failed INTEGER NOT NULL DEFAULT 0,
error_message TEXT,
details JSONB NOT NULL DEFAULT '[]'::jsonb
);
`);
await pool.query(`
CREATE TABLE IF NOT EXISTS consumption_references (
id SERIAL PRIMARY KEY,
@@ -554,6 +595,7 @@ const initDB = async () => {
await pool.query(`CREATE INDEX IF NOT EXISTS idx_cutting_product_overrides_family_key ON cutting_product_overrides (family_key);`);
await pool.query(`CREATE INDEX IF NOT EXISTS idx_catalog_products_type ON catalog_products (type);`);
await pool.query(`CREATE INDEX IF NOT EXISTS idx_catalog_products_category_id ON catalog_products (category_id);`);
await pool.query(`CREATE INDEX IF NOT EXISTS idx_olist_sync_runs_started_at ON olist_sync_runs (started_at DESC);`);
await pool.query(`CREATE INDEX IF NOT EXISTS idx_consumption_references_product_id ON consumption_references (product_id);`);
await pool.query(`CREATE INDEX IF NOT EXISTS idx_consumption_references_material_product_id ON consumption_references (material_product_id);`);
await pool.query(`