niki/donate_app/repository/migrations/1775633805_donation_campaig...

29 lines
1.5 KiB
SQL

-- +migrate Up
CREATE TABLE `donation_flows` (
`id` BIGINT PRIMARY KEY AUTO_INCREMENT,
`campaign_id` BIGINT NOT NULL,
`user_id` BIGINT NULL,
`source_type` VARCHAR(50) NOT NULL, -- e.g., "affiliate", "app", "qr", "sms"
`source_name` VARCHAR(100) NOT NULL, -- e.g., "instagram", "donate_app"
`referral_code` VARCHAR(100),
`link` VARCHAR(255) NOT NULL,
`clicks` BIGINT DEFAULT 0,
`conversions` BIGINT DEFAULT 0,
`donations_total` DECIMAL(15,2) DEFAULT 0.00,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`campaign_id`)
REFERENCES `campaigns`(`id`)
ON DELETE CASCADE,
FOREIGN KEY (`user_id`)
REFERENCES `users`(`id`)
ON DELETE SET NULL
);
CREATE INDEX `idx_flow_campaign_id` ON `donation_flows`(`campaign_id`);
CREATE INDEX `idx_flow_source` ON `donation_flows`(`source_type`, `source_name`);
-- +migrate Down
DROP TABLE IF EXISTS `donation_flows`;