- 6 tables: structures, ranks, nodes, commissions, bonuses, rank_history - 5 enums: structure_type, node_status, commission_type, commission_status, bonus_type - LTREE extension for hierarchical path queries - 24 RLS policies for multi-tenancy - GIST index for LTREE path column Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
56 lines
1.8 KiB
SQL
56 lines
1.8 KiB
SQL
-- =============================================
|
|
-- Enums: mlm
|
|
-- Module: SAAS-021 MLM (Multi-Level Marketing)
|
|
-- =============================================
|
|
|
|
-- Structure type
|
|
CREATE TYPE mlm.structure_type AS ENUM (
|
|
'unilevel', -- Unlimited width, limited depth
|
|
'binary', -- Max 2 children per node
|
|
'matrix', -- Fixed width x depth
|
|
'hybrid' -- Custom configuration
|
|
);
|
|
|
|
COMMENT ON TYPE mlm.structure_type IS 'Types of MLM network structures';
|
|
|
|
-- Node status
|
|
CREATE TYPE mlm.node_status AS ENUM (
|
|
'pending', -- Awaiting activation
|
|
'active', -- Active in network
|
|
'inactive', -- Temporarily inactive
|
|
'suspended' -- Administratively suspended
|
|
);
|
|
|
|
COMMENT ON TYPE mlm.node_status IS 'Status of a node in the network';
|
|
|
|
-- Commission type
|
|
CREATE TYPE mlm.commission_type AS ENUM (
|
|
'level', -- Direct level commission (1st gen, 2nd gen, etc.)
|
|
'matching', -- Matching bonus from downline earnings
|
|
'infinity', -- Infinity bonus (unlimited depth after rank)
|
|
'leadership', -- Leadership bonus for qualified ranks
|
|
'pool' -- Pool share bonus
|
|
);
|
|
|
|
COMMENT ON TYPE mlm.commission_type IS 'Types of MLM commissions';
|
|
|
|
-- Commission status
|
|
CREATE TYPE mlm.commission_status AS ENUM (
|
|
'pending', -- Awaiting approval
|
|
'approved', -- Approved for payment
|
|
'paid', -- Paid out
|
|
'cancelled' -- Cancelled
|
|
);
|
|
|
|
COMMENT ON TYPE mlm.commission_status IS 'Status of a commission entry';
|
|
|
|
-- Bonus type
|
|
CREATE TYPE mlm.bonus_type AS ENUM (
|
|
'rank_achievement', -- One-time bonus for reaching rank
|
|
'rank_maintenance', -- Monthly bonus for maintaining rank
|
|
'fast_start', -- Fast start bonus for quick enrollments
|
|
'pool_share' -- Share of global pool
|
|
);
|
|
|
|
COMMENT ON TYPE mlm.bonus_type IS 'Types of bonuses in MLM';
|