-- -----------------------------------------------------
-- Table structure for table `{{TABLE_PREFIX}}__tenant_influencers`
-- -----------------------------------------------------

CREATE TABLE IF NOT EXISTS `{{TABLE_PREFIX}}_tenant_influencers` (
  `id` int NOT NULL AUTO_INCREMENT,
  `influencer_name` text NOT NULL,
  `profession` varchar(100) DEFAULT NULL,
  `job_role` varchar(100) DEFAULT NULL,
  `gender` varchar(50) DEFAULT NULL,
  `age` int DEFAULT NULL,
  `religion` varchar(100) DEFAULT NULL,
  `caste` varchar(100) DEFAULT NULL,
  `phone` text,
  `whatsapp` text,
  `political_front` varchar(100) DEFAULT NULL,
  `political_party` varchar(100) DEFAULT NULL,
  `place` varchar(100) DEFAULT NULL,
  `localbody` varchar(100) DEFAULT NULL,
  `digipin` text,
  `landmark` text,
  `google_location` text,
  `priority` enum('High','Medium') DEFAULT NULL,
  `remarks` text,
  `photopath` text,
  `created_on` datetime DEFAULT CURRENT_TIMESTAMP,
  `created_by` int DEFAULT NULL,
  `modified_on` datetime DEFAULT NULL,
  `modified_by` int DEFAULT NULL,
  `bookmarked` tinyint(1) DEFAULT '0',
  `bookmarked_on` datetime DEFAULT NULL,
  `soft_deleted` tinyint(1) DEFAULT '0',
  `deleted_on` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_{{TABLE_PREFIX}}_influencers_created_by` (`created_by`),
  KEY `fk_{{TABLE_PREFIX}}_influencers_modified_by` (`modified_by`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;


ALTER TABLE `{{TABLE_PREFIX}}_tenant_influencers`
  ADD CONSTRAINT `fk_{{TABLE_PREFIX}}_influencers_created_by` FOREIGN KEY (`created_by`) REFERENCES `{{TABLE_PREFIX}}_tenant_users` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_{{TABLE_PREFIX}}_influencers_modified_by` FOREIGN KEY (`modified_by`) REFERENCES `{{TABLE_PREFIX}}_tenant_users` (`id`) ON DELETE SET NULL;
COMMIT;


CREATE TABLE IF NOT EXISTS `{{TABLE_PREFIX}}_influencer_bookmarks` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `influencer_id` INT NOT NULL,
  `user_id` INT NOT NULL,
  `bookmarked_on` DATETIME DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_user_influencer` (`user_id`, `influencer_id`),
  FOREIGN KEY (`influencer_id`) REFERENCES `{{TABLE_PREFIX}}_tenant_influencers`(`id`) ON DELETE CASCADE,
  FOREIGN KEY (`user_id`) REFERENCES `{{TABLE_PREFIX}}_tenant_users`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

ALTER TABLE `{{TABLE_PREFIX}}_voter_data`
  ADD CONSTRAINT `fk_{{TABLE_PREFIX}}_voter_influencer` FOREIGN KEY (`influencer_id`) REFERENCES `{{TABLE_PREFIX}}_tenant_influencers` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `{{TABLE_PREFIX}}_voter_data_ibfk_1` FOREIGN KEY (`house_id`) REFERENCES `{{TABLE_PREFIX}}_voter_house` (`id`);

