nxtgauge-backend-rust/crates/db/migrations/20260402140000_discounts_table.up.sql
Ashwin Kumar d900c361d8 Add reviews, coupons, discounts, pricing packages, and reports handlers
- handlers/reviews.rs: admin CRUD for /api/admin/reviews (list, create, patch status, delete)
- handlers/coupons.rs: admin CRUD for /api/admin/coupons and /api/admin/discounts
- handlers/pricing.rs: admin CRUD for /api/admin/tracecoin-packages + /api/admin/reports/{users,revenue}
- handlers/dashboard.rs: replace all hardcoded fake data with real DB queries (registrations per day, revenue per week, live KPIs including pending approvals and total revenue)
- Migrations: extend reviews table (nullable FKs + admin fields), add coupons.title/role_keys, create discounts table
- gateway: route new admin paths to users service

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-02 18:09:50 +02:00

12 lines
555 B
SQL

-- Admin-managed automatic discounts (applied before coupon codes)
CREATE TABLE IF NOT EXISTS discounts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title VARCHAR(255) NOT NULL,
scope VARCHAR(20) NOT NULL DEFAULT 'ROLE', -- ROLE, PACKAGE
role_key VARCHAR(50),
package_id UUID REFERENCES pricing_packages(id) ON DELETE SET NULL,
discount_type VARCHAR(20) NOT NULL, -- PERCENT, FIXED
discount_value INTEGER NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);