From fb0fedda056fafaedc2ab13d9a604e80c94ee6a4 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 21 Oct 2025 06:21:00 +0000 Subject: [PATCH] Add database column type validation for enum columns in Constants_Regenerate_Command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../Rsx/Constants_Regenerate_Command.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/RSpade/Commands/Rsx/Constants_Regenerate_Command.php b/app/RSpade/Commands/Rsx/Constants_Regenerate_Command.php index 9769dd7d0..8f74281ee 100755 --- a/app/RSpade/Commands/Rsx/Constants_Regenerate_Command.php +++ b/app/RSpade/Commands/Rsx/Constants_Regenerate_Command.php @@ -142,6 +142,31 @@ class Constants_Regenerate_Command extends Command // Process enum magic methods and properties foreach ($enums as $column => $enumValues) { + // Validate that the database column is an integer type + $columnType = DB::getSchemaBuilder()->getColumnType($table, $column); + $validIntegerTypes = ['integer', 'bigint', 'smallint', 'tinyint', 'mediumint']; + + if (!in_array($columnType, $validIntegerTypes)) { + throw new Exception( + "Invalid column type '{$columnType}' for enum column '{$column}' in table '{$table}' (model '{$fullClassName}').\n\n" . + "ENUM COLUMNS MUST BE INTEGER TYPES.\n\n" . + "Enum values are stored as integers in the database. The column must be defined as an " . + "integer type (INT, BIGINT, SMALLINT, TINYINT, or MEDIUMINT), not VARCHAR or other string types.\n\n" . + "Current column type: {$columnType}\n" . + "Required column types: " . implode(', ', $validIntegerTypes) . "\n\n" . + "To fix this issue:\n" . + "1. Create a migration to change the column type to an integer\n" . + "2. Example migration:\n\n" . + " public function up()\n" . + " {\n" . + " Schema::table('{$table}', function (Blueprint \$table) {\n" . + " \$table->integer('{$column}')->change();\n" . + " });\n" . + " }\n\n" . + "For more information, run: php artisan rsx:man enums" + ); + } + $docblock .= " * @method static mixed {$column}_enum()\n"; $docblock .= " * @method static mixed {$column}_enum_select()\n"; $docblock .= " * @method static mixed {$column}_enum_ids()\n";