You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @var string The name and signature of the console command.
25
-
*/
21
+
/** @var string The name and signature of the console command. */
26
22
protected$signature = 'database:find-invalid-values {connection=default} {--check=* : Check only specific types of issues. Available types: {null, datetime, long_text, long_string}}';
27
23
28
-
/**
29
-
* @var string The console command description.
30
-
*/
24
+
/** @var string The console command description. */
31
25
protected$description = 'Find invalid data created in non-strict SQL mode.';
32
26
33
27
privateint$valuesWithIssuesFound = 0;
34
28
35
-
/**
36
-
* @throws \Doctrine\DBAL\Exception
37
-
*/
38
29
publicfunctionhandle(ConnectionResolverInterface$connections): int
$nullsOnNotNullableColumnCount = DB::selectOne("SELECT COUNT(`{$columnName}`) AS `count` FROM {$connection->getDatabaseName()}.`{$table->getName()}` WHERE `{$columnName}` IS NULL")->count;
93
+
$nullsOnNotNullableColumnCount = DB::selectOne("SELECT COUNT(`{$columnName}`) AS `count` FROM {$connection->getDatabaseName()}.`{$tableName}` WHERE `{$columnName}` IS NULL")->count;
103
94
if ($nullsOnNotNullableColumnCount > 0) {
104
-
$this->error("{$table->getName()}.{$columnName} has {$nullsOnNotNullableColumnCount} NULLs but the column is not nullable.");
95
+
$this->error("{$tableName}.{$columnName} has {$nullsOnNotNullableColumnCount} NULLs but the column is not nullable.");
$invalidDatetimeRecordsCount = DB::selectOne("SELECT COUNT(`{$columnName}`) AS `count` FROM {$connection->getDatabaseName()}.`{$table->getName()}` WHERE `{$columnName}` <= 1")->count;
113
+
$invalidDatetimeRecordsCount = DB::selectOne("SELECT COUNT(`{$columnName}`) AS `count` FROM {$connection->getDatabaseName()}.`{$tableName}` WHERE `{$columnName}` <= 1")->count;
121
114
if ($invalidDatetimeRecordsCount > 0) {
122
-
$this->error("{$table->getName()}.{$columnName} has {$invalidDatetimeRecordsCount} invalid datetime values.");
115
+
$this->error("{$tableName}.{$columnName} has {$invalidDatetimeRecordsCount} invalid datetime values.");
if ($column->getType()->getName() === Types::TEXT) {
125
+
if ($column->getType()->getName() === 'text') {
133
126
$columnName = $column->getName();
134
127
135
-
$tooLongTextValuesCount = DB::selectOne("SELECT COUNT(`{$columnName}`) AS `count` FROM {$connection->getDatabaseName()}.`{$table->getName()}` WHERE LENGTH(`{$columnName}`) > @@max_allowed_packet;")->count;
128
+
$tooLongTextValuesCount = DB::selectOne("SELECT COUNT(`{$columnName}`) AS `count` FROM {$connection->getDatabaseName()}.`{$tableName}` WHERE LENGTH(`{$columnName}`) > @@max_allowed_packet;")->count;
136
129
if ($tooLongTextValuesCount > 0) {
137
-
$this->error("{$table->getName()}.{$columnName} has {$tooLongTextValuesCount} too long text values.");
130
+
$this->error("{$tableName}.{$columnName} has {$tooLongTextValuesCount} too long text values.");
if (in_array($column->getType()->getName(), [Types::STRING, Types::ASCII_STRING], true)) {
140
+
if (in_array($column->getType()->getName(), ['string', 'ascii_string'], true)) {
148
141
$columnName = $column->getName();
149
142
150
143
$maxLength = $column->getLength();
151
144
152
145
if (is_int($maxLength) && $maxLength !== 0) {
153
-
$tooLongStringValuesCount = DB::selectOne("SELECT COUNT(`{$columnName}`) AS `count` FROM {$connection->getDatabaseName()}.`{$table->getName()}` WHERE LENGTH(`{$columnName}`) > {$maxLength};")->count;
146
+
$tooLongStringValuesCount = DB::selectOne("SELECT COUNT(`{$columnName}`) AS `count` FROM {$connection->getDatabaseName()}.`{$tableName}` WHERE LENGTH(`{$columnName}`) > {$maxLength};")->count;
154
147
if ($tooLongStringValuesCount > 0) {
155
-
$this->error("{$table->getName()}.{$columnName} has {$tooLongStringValuesCount} too long string values (longer than {$maxLength} chars).");
148
+
$this->error("{$tableName}.{$columnName} has {$tooLongStringValuesCount} too long string values (longer than {$maxLength} chars).");
* @var string The name and signature of the console command.
32
-
*/
28
+
/** @var string The name and signature of the console command. */
33
29
protected$signature = 'database:find-risky-columns {connection=default} {--threshold=70 : Percentage occupied rows number on which the command should treat it as an issue}';
34
30
35
-
/**
36
-
* @var string The console command description.
37
-
*/
31
+
/** @var string The console command description. */
38
32
protected$description = 'Find risky auto-incremental columns on databases which values are close to max possible values.';
0 commit comments