diff --git a/app/TermsOfUseVersion.php b/app/TermsOfUseVersion.php index e4472407..1d40439c 100644 --- a/app/TermsOfUseVersion.php +++ b/app/TermsOfUseVersion.php @@ -13,8 +13,14 @@ class TermsOfUseVersion extends Model { use HasFactory; + protected $primaryKey = 'version'; + + protected $keyType = 'string'; + protected $table = 'tou_versions'; + public $incrementing = false; + const FIELDS = [ 'version', 'active', diff --git a/database/migrations/2025_10_14_091126_tou_versions.php b/database/migrations/2026_01_06_131233_tou_version.php similarity index 95% rename from database/migrations/2025_10_14_091126_tou_versions.php rename to database/migrations/2026_01_06_131233_tou_version.php index c7aa71d9..07c41480 100644 --- a/database/migrations/2025_10_14_091126_tou_versions.php +++ b/database/migrations/2026_01_06_131233_tou_version.php @@ -10,7 +10,6 @@ */ public function up(): void { Schema::create('tou_versions', function (Blueprint $table) { - $table->id(); $table->string('version')->unique(); $table->boolean('active')->default(false); $table->timestamps(); diff --git a/database/migrations/2025_09_29_194758_tou_acceptances.php b/database/migrations/2026_01_06_131319_tou_acceptances.php similarity index 76% rename from database/migrations/2025_09_29_194758_tou_acceptances.php rename to database/migrations/2026_01_06_131319_tou_acceptances.php index bbc1e76c..57041849 100644 --- a/database/migrations/2025_09_29_194758_tou_acceptances.php +++ b/database/migrations/2026_01_06_131319_tou_acceptances.php @@ -12,11 +12,16 @@ public function up(): void { Schema::create('tou_acceptances', function (Blueprint $table) { $table->id(); $table->unsignedInteger('user_id'); - $table->string('tou_version', 10); + $table->string('tou_version'); $table->timestamp('tou_accepted_at'); $table->timestamps(); $table->unique(['user_id', 'tou_version']); $table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete(); + $table->foreign('tou_version') + ->references('version') + ->on('tou_versions') + ->cascadeOnUpdate() + ->restrictOnDelete(); }); }