CREATE TABLE IF NOT EXISTS PartnerHistory
(
     id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,

     Client BIGINT UNSIGNED NOT NULL,

     Partner BIGINT UNSIGNED NOT NULL,
     IsPrimary TINYINT UNSIGNED DEFAULT 0,

     IsActive TINYINT UNSIGNED DEFAULT 1,

     Type BIGINT UNSIGNED NOT NULL,
     Start BIGINT UNSIGNED NOT NULL,
     End BIGINT UNSIGNED DEFAULT NULL,
     Notes TEXT DEFAULT NULL,

     Field ENUM( "Referer", "TechSupport", "Agent" ),
     User BIGINT UNSIGNED NOT NULL,

     RecurringPercent DECIMAL(5,2) DEFAULT NULL,
     ServicePercent DECIMAL(5,2) DEFAULT NULL,
     FirstYearPercent DECIMAL( 5, 2 ) DEFAULT 0,

     /* Only one primary partner is possible */
     UNIQUE KEY( Client, IsPrimary, IsActive, End )
)
