SharedTableProtocol now covers the full shared-table surface:
- sellers, market_comps, reported_sellers (already in SnipeSharedStore)
- scammer_blocklist (new — is_blocklisted, add/remove/list_blocklist)
- refresh_seller_categories (reads per-user SQLite, writes to Postgres)
TrustScorer updated to accept SharedTableProtocol (was Store).
api/main.py:
- _pg_shared_store global + _make_shared_store(path) helper
- Lifespan init: SNIPE_SHARED_DB_URL → SnipeSharedDB + SnipeSharedStore
- All Store(shared_db) calls for shared tables replaced with
_make_shared_store(shared_db) or shared_store.clone()
- Blocklist endpoints use _make_shared_store (Postgres when configured)
- Community signals stay SQLite-only (low-write, not in protocol)
Postgres migration 001: scammer_blocklist table added.
8 blocklist tests added (gated behind SNIPE_SHARED_DB_URL / @pytest.mark.postgres).
.env.example: SNIPE_SHARED_DB_URL documented.
compose.cloud.yml: GPU_SERVER_URL + SNIPE_SHARED_DB_URL comment added.
248 passed, 8 skipped (postgres-gated).
Closes: #45
49 lines
1.8 KiB
SQL
49 lines
1.8 KiB
SQL
-- Snipe shared tables: sellers, market_comps, reported_sellers
|
|
-- Replaces the equivalent tables in shared.db (SQLite).
|
|
-- Per-user tables (listings, trust_scores, saved_searches) remain in SQLite.
|
|
|
|
CREATE TABLE IF NOT EXISTS sellers (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
platform TEXT NOT NULL,
|
|
platform_seller_id TEXT NOT NULL,
|
|
username TEXT NOT NULL,
|
|
account_age_days INTEGER,
|
|
feedback_count INTEGER NOT NULL DEFAULT 0,
|
|
feedback_ratio DOUBLE PRECISION NOT NULL DEFAULT 0,
|
|
category_history_json TEXT NOT NULL DEFAULT '{}',
|
|
fetched_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
UNIQUE (platform, platform_seller_id)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS market_comps (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
platform TEXT NOT NULL,
|
|
query_hash TEXT NOT NULL,
|
|
median_price DOUBLE PRECISION NOT NULL,
|
|
sample_count INTEGER NOT NULL,
|
|
fetched_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
expires_at TIMESTAMPTZ NOT NULL,
|
|
UNIQUE (platform, query_hash)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS reported_sellers (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
platform TEXT NOT NULL,
|
|
platform_seller_id TEXT NOT NULL,
|
|
username TEXT,
|
|
reported_by TEXT NOT NULL DEFAULT 'user',
|
|
reported_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
UNIQUE (platform, platform_seller_id)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS scammer_blocklist (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
platform TEXT NOT NULL,
|
|
platform_seller_id TEXT NOT NULL,
|
|
username TEXT NOT NULL,
|
|
reason TEXT,
|
|
source TEXT NOT NULL DEFAULT 'manual',
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
UNIQUE (platform, platform_seller_id)
|
|
);
|
|
|