This commit is contained in:
greeneclipse committed 2026-10-16 00:34:06 +02:00
1 parent 6586722652
commit 1e7c7bbfbb
65 files changed
+1345 -640

No files matched your search

@@ -0,0 +1,23 @@
-- +goose Up
-- Effective credit rules: company > assigned plan > global defaults.
-- These affect future debits only. Existing credit history is never repriced.
CREATE TABLE IF NOT EXISTS plan_processing_costs (
plan_id BIGINT NOT NULL REFERENCES plans(id) ON DELETE CASCADE,
feature_name TEXT NOT NULL,
cost_per_unit INTEGER NOT NULL CHECK (cost_per_unit >= 1 AND cost_per_unit <= 1000000),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (plan_id, feature_name)
);
CREATE TABLE IF NOT EXISTS company_processing_costs (
company_id UUID NOT NULL REFERENCES companies(id) ON DELETE CASCADE,
feature_name TEXT NOT NULL,
cost_per_unit INTEGER NOT NULL CHECK (cost_per_unit >= 1 AND cost_per_unit <= 1000000),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (company_id, feature_name)
);
CREATE INDEX IF NOT EXISTS plan_processing_costs_feature_idx ON plan_processing_costs(feature_name);
CREATE INDEX IF NOT EXISTS company_processing_costs_feature_idx ON company_processing_costs(feature_name);
-- +goose Down
DROP TABLE IF EXISTS company_processing_costs;
DROP TABLE IF EXISTS plan_processing_costs;
@@ -0,0 +1,14 @@
-- +goose Up
-- USD per 1M standard text tokens, OpenAI published rates, 2026-10-16.
-- The platform's cost ledger records USD at call time; never reprice history.
-- Existing/admin-custom pricing remains authoritative.
INSERT INTO ai_model_prices (model,input_micros_per_mtok,cached_input_micros_per_mtok,output_micros_per_mtok,source)
VALUES
('gpt-5.4-mini',750000,75000,4500000,'https://developers.openai.com/api/docs/models/gpt-5.4-mini'),
('gpt-5-mini',250000,25000,2000000,'https://developers.openai.com/api/docs/models/gpt-5-mini'),
('gpt-6-luna',100000,10000,500000,'https://developers.openai.com/api/docs/pricing')
ON CONFLICT(model) DO NOTHING;
-- +goose Down
-- Price rows may be in active use and cost history cannot be re-priced.
SELECT 1;
@@ -0,0 +1,14 @@
-- +goose Up
-- Make API-origin processing visible in the existing catalog, without changing the
-- review/approval lifecycle of dashboard and feed-initiated jobs.
ALTER TABLE processing_jobs
ADD COLUMN IF NOT EXISTS origin TEXT NOT NULL DEFAULT 'dashboard';
ALTER TABLE processed_products
ADD COLUMN IF NOT EXISTS processing_origin TEXT NOT NULL DEFAULT 'dashboard';
-- Old jobs have no trustworthy origin tag; leave their review state intact.
-- The unique (company_id,raw_product_id) index remains the product identity.
-- +goose Down
ALTER TABLE processed_products DROP COLUMN IF EXISTS processing_origin;
ALTER TABLE processing_jobs DROP COLUMN IF EXISTS origin;