diff --git a/app/TermsOfUseVersion.php b/app/TermsOfUseVersion.php index e4472407..25f9b027 100644 --- a/app/TermsOfUseVersion.php +++ b/app/TermsOfUseVersion.php @@ -13,6 +13,12 @@ class TermsOfUseVersion extends Model { use HasFactory; + protected $primaryKey = 'version'; + + protected $keyType = 'string'; + + public $incrementing = false; + protected $table = 'tou_versions'; const FIELDS = [ @@ -24,11 +30,6 @@ class TermsOfUseVersion extends Model { protected $visible = self::FIELDS; - protected $casts = [ - 'version' => 'string', - 'active' => 'boolean', - ]; - public static function latestActiveVersion(): ?self { return self::query()->where('active', true)->latest()->first(); } diff --git a/app/UserTermsOfUseAcceptance.php b/app/UserTermsOfUseAcceptance.php index 3a13bcf9..5a6de0d4 100644 --- a/app/UserTermsOfUseAcceptance.php +++ b/app/UserTermsOfUseAcceptance.php @@ -20,7 +20,6 @@ class UserTermsOfUseAcceptance extends Model { protected $visible = self::FIELDS; protected $casts = [ - 'tou_version' => 'string', 'tou_accepted_at' => 'datetime', ]; diff --git a/database/migrations/2026_01_08_144222_update_tou_versions_and_tou_acceptances_tables.php.php b/database/migrations/2026_01_08_144222_update_tou_versions_and_tou_acceptances_tables.php.php new file mode 100644 index 00000000..80e32517 --- /dev/null +++ b/database/migrations/2026_01_08_144222_update_tou_versions_and_tou_acceptances_tables.php.php @@ -0,0 +1,34 @@ +dropColumn('id'); + $table->char('version', 10)->primary()->change(); + }); + + Schema::table('tou_acceptances', function (Blueprint $table) { + $table->char('tou_version', 10)->change(); + $table->foreign('tou_version') + ->references('version') + ->on('tou_versions') + ->cascadeOnUpdate() + ->restrictOnDelete(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void { + Schema::dropIfExists('tou_versions'); + Schema::dropIfExists('tou_acceptances'); + } +};