Files
backend/database/migrations/086_sms_balance_credit_units.sql
Alireza HassaniandCursor 717a203d48 Fix SMS billing build and make credit conversion idempotent.
Import the purchase-price constant for Nest build, and only convert IRT-scale balances so migrate re-runs do not divide credits again.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-09 11:12:27 +03:30

13 lines
609 B
SQL

-- Convert prepaid SMS balance from IRT to credit units (idempotent).
-- Previous billing: 400 IRT per 64-char segment.
-- New model: balance is SMS credits (1 credit = 1 segment); top-up at 500 IRT/credit.
-- Only convert rows that still look like IRT balances (>= 100_000). Already-converted
-- credit balances are below that and are left unchanged on re-run.
UPDATE businesses
SET sms_balance = sms_balance / 400
WHERE sms_balance >= 100000;
COMMENT ON COLUMN businesses.sms_balance IS
'Prepaid SMS credit units. 1 unit = one 64-character segment per recipient. Top-up adds floor(IRT / 500) credits.';