referral tables

This commit is contained in:
Brandon Thomas committed 2026-05-13 19:33:12 -04:00
1 parent 0ec9c0ce16
commit 62250f0e3e
6 files changed
+132

No files matched your search

@@ -0,0 +1,5 @@
-- noinspection SqlDialectInspectionForFile
-- noinspection SqlNoDataSourceInspectionForFile
-- noinspection SqlResolveForFile
DROP TABLE IF EXISTS user_referrals;
@@ -0,0 +1,31 @@
-- noinspection SqlDialectInspectionForFile
-- noinspection SqlNoDataSourceInspectionForFile
-- noinspection SqlResolveForFile
CREATE TABLE user_referrals (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-- The user who was invited/referred.
invited_user_token VARCHAR(32) NOT NULL,
-- The user who referred the invited user.
referrer_user_token VARCHAR(32) NOT NULL,
-- OPTIONAL. The referral code token used, if any.
maybe_referral_code_token VARCHAR(32) DEFAULT NULL,
-- OPTIONAL. The referral URL the invited user arrived from.
maybe_referral_url VARCHAR(255) DEFAULT NULL,
-- OPTIONAL. The landing URL the invited user first visited.
maybe_landing_url VARCHAR(255) DEFAULT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
-- INDICES --
PRIMARY KEY (id),
UNIQUE KEY unique_invited_user_token (invited_user_token),
KEY index_referrer_user_token (referrer_user_token),
KEY index_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
@@ -0,0 +1,5 @@
-- noinspection SqlDialectInspectionForFile
-- noinspection SqlNoDataSourceInspectionForFile
-- noinspection SqlResolveForFile
DROP TABLE IF EXISTS user_referral_codes;
@@ -0,0 +1,31 @@
-- noinspection SqlDialectInspectionForFile
-- noinspection SqlNoDataSourceInspectionForFile
-- noinspection SqlResolveForFile
CREATE TABLE user_referral_codes (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-- Unique token identifier for this referral code record.
token VARCHAR(32) NOT NULL,
-- The human-readable referral code (e.g. a username or custom code).
-- This can be changed.
-- These must be unique.
code VARCHAR(32) NOT NULL,
-- The user who owns this referral code.
owner_user_token VARCHAR(32) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-- Soft delete.
deleted_at TIMESTAMP NULL,
-- INDICES --
PRIMARY KEY (id),
UNIQUE KEY unique_token (token),
UNIQUE KEY unique_code (code),
KEY index_owner_user_token (owner_user_token)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
@@ -0,0 +1,29 @@
-- noinspection SqlDialectInspectionForFile
-- noinspection SqlNoDataSourceInspectionForFile
-- noinspection SqlResolveForFile
CREATE TABLE user_referral_codes (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-- Unique token identifier for this referral code record.
token VARCHAR(32) NOT NULL,
-- The human-readable referral code (e.g. a username or custom code).
code VARCHAR(32) NOT NULL,
-- The user who owns this referral code.
owner_user_token VARCHAR(32) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-- Soft delete.
deleted_at TIMESTAMP NULL,
-- INDICES --
PRIMARY KEY (id),
UNIQUE KEY unique_token (token),
UNIQUE KEY unique_code (code),
KEY index_owner_user_token (owner_user_token)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
@@ -0,0 +1,31 @@
-- noinspection SqlDialectInspectionForFile
-- noinspection SqlNoDataSourceInspectionForFile
-- noinspection SqlResolveForFile
CREATE TABLE user_referrals (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-- The user who was invited/referred.
invited_user_token VARCHAR(32) NOT NULL,
-- The user who referred the invited user.
referrer_user_token VARCHAR(32) NOT NULL,
-- OPTIONAL. The referral code token used, if any.
maybe_referral_code_token VARCHAR(32) DEFAULT NULL,
-- OPTIONAL. The referral URL the invited user arrived from.
maybe_referral_url VARCHAR(255) DEFAULT NULL,
-- OPTIONAL. The landing URL the invited user first visited.
maybe_landing_url VARCHAR(255) DEFAULT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
-- INDICES --
PRIMARY KEY (id),
UNIQUE KEY unique_invited_user_token (invited_user_token),
KEY index_referrer_user_token (referrer_user_token),
KEY index_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;