Conditions | 2 |
Paths | 2 |
Total Lines | 16 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
22 | public static function isColumnNullable(string $column_name) : bool |
||
23 | { |
||
24 | // Create an instance of the model to be able to get the table name. |
||
25 | $instance = new static(); |
||
26 | $conn = DB::connection($instance->getConnectionName()); |
||
27 | $table = Config::get('database.connections.' . Config::get('database.default') . '.prefix') . $instance->getTable(); |
||
28 | // MongoDB columns are alway nullable. |
||
29 | if ($conn->getConfig()['driver'] === 'mongodb') { |
||
30 | return true; |
||
31 | } |
||
32 | // Register the enum, json, jsonb, and citext column types, because Doctrine doesn't support it. |
||
33 | $conn->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); |
||
34 | $conn->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('json', 'json_array'); |
||
35 | $conn->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('jsonb', 'json_array'); |
||
36 | $conn->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('citext', 'string'); |
||
37 | return !$conn->getDoctrineColumn($table, $column_name)->getNotnull(); |
||
38 | } |
||
40 |