32 lines
2.4 KiB
SQL
32 lines
2.4 KiB
SQL
-- +goose Up
|
|
-- Product content credits are priced per output, independently of token usage.
|
|
-- Historical integer debit columns remain intact. Fractional debit amounts are
|
|
-- accumulated separately to preserve compatibility with older integrations.
|
|
ALTER TABLE processing_costs ALTER COLUMN cost_per_unit TYPE NUMERIC(14,4);
|
|
ALTER TABLE plan_processing_costs DROP CONSTRAINT IF EXISTS plan_processing_costs_cost_per_unit_check;
|
|
ALTER TABLE company_processing_costs DROP CONSTRAINT IF EXISTS company_processing_costs_cost_per_unit_check;
|
|
ALTER TABLE plan_processing_costs ALTER COLUMN cost_per_unit TYPE NUMERIC(14,4);
|
|
ALTER TABLE company_processing_costs ALTER COLUMN cost_per_unit TYPE NUMERIC(14,4);
|
|
ALTER TABLE plan_processing_costs ADD CONSTRAINT plan_processing_costs_cost_per_unit_check CHECK (cost_per_unit >= 0 AND cost_per_unit <= 1000000);
|
|
ALTER TABLE company_processing_costs ADD CONSTRAINT company_processing_costs_cost_per_unit_check CHECK (cost_per_unit >= 0 AND cost_per_unit <= 1000000);
|
|
ALTER TABLE credit_balances ADD COLUMN fractional_credits_used NUMERIC(16,4) NOT NULL DEFAULT 0;
|
|
ALTER TABLE billing_cycles ADD COLUMN fractional_credits_used NUMERIC(16,4) NOT NULL DEFAULT 0;
|
|
ALTER TABLE processing_jobs ADD COLUMN processing_types TEXT[] NOT NULL DEFAULT '{}';
|
|
INSERT INTO processing_costs (feature_name,cost_per_unit,description,is_active) VALUES
|
|
('title_ai',0.10,'AI product title',true),
|
|
('description_ai',0.25,'AI product description',true),
|
|
('seo_meta_ai',0.10,'SEO meta title and description',true)
|
|
ON CONFLICT (feature_name) DO NOTHING;
|
|
-- Upgrade only the known legacy SEO default, preserving custom platform pricing.
|
|
UPDATE processing_costs SET cost_per_unit=0.10, description='SEO meta title and description' WHERE feature_name='seo_meta_ai' AND cost_per_unit=1;
|
|
|
|
-- +goose Down
|
|
ALTER TABLE processing_jobs DROP COLUMN IF EXISTS processing_types;
|
|
ALTER TABLE billing_cycles DROP COLUMN IF EXISTS fractional_credits_used;
|
|
ALTER TABLE credit_balances DROP COLUMN IF EXISTS fractional_credits_used;
|
|
DELETE FROM processing_costs WHERE feature_name IN ('title_ai','description_ai');
|
|
DELETE FROM plan_processing_costs WHERE feature_name IN ('title_ai','description_ai');
|
|
DELETE FROM company_processing_costs WHERE feature_name IN ('title_ai','description_ai');
|
|
-- Numeric cost columns deliberately not narrowed on rollback: old schema cannot
|
|
-- represent already-saved fractional overrides without data loss.
|