feat: add referral

This commit is contained in:
2026-06-06 13:10:53 +03:30
parent c930c26589
commit 9080cf866e
6 changed files with 144 additions and 7 deletions
@@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
// Own shareable code, mirrored from approagency (source of truth).
if (!Schema::hasColumn('users', 'referral_code')) {
$table->string('referral_code', 12)->nullable()->after('identifier');
}
// Local meditation user who referred this user (resolved from approagency's referrer_uuid).
if (!Schema::hasColumn('users', 'referred_by')) {
$table->foreignId('referred_by')->nullable()->after('referral_code')
->constrained('users')->nullOnDelete();
}
// Points earned through referrals (100 per invite + 10% of friends' xp).
if (!Schema::hasColumn('users', 'referral_points')) {
$table->unsignedInteger('referral_points')->default(0)->after('referred_by');
}
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
if (Schema::hasColumn('users', 'referred_by')) {
$table->dropForeign(['referred_by']);
$table->dropColumn('referred_by');
}
foreach (['referral_code', 'referral_points'] as $column) {
if (Schema::hasColumn('users', $column)) {
$table->dropColumn($column);
}
}
});
}
};