Add database column type validation for enum columns in Constants_Regenerate_Command

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-10-21 06:21:00 +00:00
parent b13a9cb8a5
commit fb0fedda05

View File

@@ -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";