Completed
Push — update-to-php-71 ( f475af )
by Alexander
15:41 queued 04:41
created

Migration   B

Complexity

Total Complexity 44

Size/Duplication

Total Lines 507
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 17.74%

Importance

Changes 0
Metric Value
wmc 44
lcom 1
cbo 5
dl 0
loc 507
ccs 33
cts 186
cp 0.1774
rs 8.3396
c 0
b 0
f 0

30 Methods

Rating   Name   Duplication   Size   Complexity  
A safeDown() 0 3 1
A batchInsert() 0 7 1
A init() 0 7 1
A getDb() 0 4 1
A up() 0 17 3
A down() 0 17 3
A printException() 0 5 1
A safeUp() 0 3 1
A execute() 0 12 2
A insert() 0 7 1
A update() 0 7 1
A delete() 0 7 1
A createTable() 0 12 4
A renameTable() 0 7 1
A dropTable() 0 7 1
A truncateTable() 0 7 1
A addColumn() 0 10 3
A dropColumn() 0 7 1
A renameColumn() 0 7 1
A alterColumn() 0 10 3
A addPrimaryKey() 0 7 2
A dropPrimaryKey() 0 7 1
A addForeignKey() 0 7 1
A dropForeignKey() 0 7 1
A createIndex() 0 7 2
A dropIndex() 0 7 1
A addCommentOnColumn() 0 7 1
A addCommentOnTable() 0 7 1
A dropCommentFromColumn() 0 7 1
A dropCommentFromTable() 0 7 1

How to fix   Complexity   

Complex Class

Complex classes like Migration often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Migration, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace yii\db;
9
10
use yii\base\Component;
11
use yii\di\Instance;
12
use yii\helpers\StringHelper;
13
14
/**
15
 * Migration is the base class for representing a database migration.
16
 *
17
 * Migration is designed to be used together with the "yii migrate" command.
18
 *
19
 * Each child class of Migration represents an individual database migration which
20
 * is identified by the child class name.
21
 *
22
 * Within each migration, the [[up()]] method should be overridden to contain the logic
23
 * for "upgrading" the database; while the [[down()]] method for the "downgrading"
24
 * logic. The "yii migrate" command manages all available migrations in an application.
25
 *
26
 * If the database supports transactions, you may also override [[safeUp()]] and
27
 * [[safeDown()]] so that if anything wrong happens during the upgrading or downgrading,
28
 * the whole migration can be reverted in a whole.
29
 *
30
 * Note that some DB queries in some DBMS cannot be put into a transaction. For some examples,
31
 * please refer to [implicit commit](http://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,
32
 * you should still implement `up()` and `down()`, instead.
33
 *
34
 * Migration provides a set of convenient methods for manipulating database data and schema.
35
 * For example, the [[insert()]] method can be used to easily insert a row of data into
36
 * a database table; the [[createTable()]] method can be used to create a database table.
37
 * Compared with the same methods in [[Command]], these methods will display extra
38
 * information showing the method parameters and execution time, which may be useful when
39
 * applying migrations.
40
 *
41
 * For more details and usage information on Migration, see the [guide article on Migration](guide:db-migrations).
42
 *
43
 * @author Qiang Xue <[email protected]>
44
 * @since 2.0
45
 */
46
class Migration extends Component implements MigrationInterface
47
{
48
    use SchemaBuilderTrait;
49
50
    /**
51
     * @var Connection|array|string the DB connection object or the application component ID of the DB connection
52
     * that this migration should work with. Starting from version 2.0.2, this can also be a configuration array
53
     * for creating the object.
54
     *
55
     * Note that when a Migration object is created by the `migrate` command, this property will be overwritten
56
     * by the command. If you do not want to use the DB connection provided by the command, you may override
57
     * the [[init()]] method like the following:
58
     *
59
     * ```php
60
     * public function init()
61
     * {
62
     *     $this->db = 'db2';
63
     *     parent::init();
64
     * }
65
     * ```
66
     */
67
    public $db = 'db';
68
69
    /**
70
     * @var int max number of characters of the SQL outputted. Useful for reduction of long statements and making
71
     * console output more compact.
72
     * @since 2.0.13
73
     */
74
    public $maxSqlOutputLength;
75
76
    /**
77
     * Initializes the migration.
78
     * This method will set [[db]] to be the 'db' application component, if it is `null`.
79
     */
80 20
    public function init()
81
    {
82 20
        parent::init();
83 20
        $this->db = Instance::ensure($this->db, Connection::class);
84 20
        $this->db->getSchema()->refresh();
85 20
        $this->db->enableSlaves = false;
86 20
    }
87
88
    /**
89
     * @inheritdoc
90
     * @since 2.0.6
91
     */
92 7
    protected function getDb()
93
    {
94 7
        return $this->db;
95
    }
96
97
    /**
98
     * This method contains the logic to be executed when applying this migration.
99
     * Child classes may override this method to provide actual migration logic.
100
     * @return bool return a false value to indicate the migration fails
101
     * and should not proceed further. All other return values mean the migration succeeds.
102
     */
103 1
    public function up()
104
    {
105 1
        $transaction = $this->db->beginTransaction();
106
        try {
107 1
            if ($this->safeUp() === false) {
108
                $transaction->rollBack();
109
                return false;
110
            }
111 1
            $transaction->commit();
112
        } catch (\Throwable $e) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
113
            $this->printException($e);
114
            $transaction->rollBack();
115
            return false;
116
        }
117
118 1
        return null;
119
    }
120
121
    /**
122
     * This method contains the logic to be executed when removing this migration.
123
     * The default implementation throws an exception indicating the migration cannot be removed.
124
     * Child classes may override this method if the corresponding migrations can be removed.
125
     * @return bool return a false value to indicate the migration fails
126
     * and should not proceed further. All other return values mean the migration succeeds.
127
     */
128
    public function down()
129
    {
130
        $transaction = $this->db->beginTransaction();
131
        try {
132
            if ($this->safeDown() === false) {
133
                $transaction->rollBack();
134
                return false;
135
            }
136
            $transaction->commit();
137
        } catch (\Throwable $e) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
138
            $this->printException($e);
139
            $transaction->rollBack();
140
            return false;
141
        }
142
143
        return null;
144
    }
145
146
    /**
147
     * @param \Throwable $e
148
     */
149
    private function printException($e)
150
    {
151
        echo 'Exception: ' . $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ")\n";
152
        echo $e->getTraceAsString() . "\n";
153
    }
154
155
    /**
156
     * This method contains the logic to be executed when applying this migration.
157
     * This method differs from [[up()]] in that the DB logic implemented here will
158
     * be enclosed within a DB transaction.
159
     * Child classes may implement this method instead of [[up()]] if the DB logic
160
     * needs to be within a transaction.
161
     *
162
     * Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,
163
     * please refer to [implicit commit](http://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,
164
     * you should still implement `up()` and `down()`, instead.
165
     *
166
     * @return bool return a false value to indicate the migration fails
167
     * and should not proceed further. All other return values mean the migration succeeds.
168
     */
169
    public function safeUp()
170
    {
171
    }
172
173
    /**
174
     * This method contains the logic to be executed when removing this migration.
175
     * This method differs from [[down()]] in that the DB logic implemented here will
176
     * be enclosed within a DB transaction.
177
     * Child classes may implement this method instead of [[down()]] if the DB logic
178
     * needs to be within a transaction.
179
     *
180
     * Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,
181
     * please refer to [implicit commit](http://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,
182
     * you should still implement `up()` and `down()`, instead.
183
     *
184
     * @return bool return a false value to indicate the migration fails
185
     * and should not proceed further. All other return values mean the migration succeeds.
186
     */
187
    public function safeDown()
188
    {
189
    }
190
191
    /**
192
     * Executes a SQL statement.
193
     * This method executes the specified SQL statement using [[db]].
194
     * @param string $sql the SQL statement to be executed
195
     * @param array $params input parameters (name => value) for the SQL execution.
196
     * See [[Command::execute()]] for more details.
197
     */
198
    public function execute($sql, $params = [])
199
    {
200
        $sqlOutput = $sql;
201
        if ($this->maxSqlOutputLength !== null) {
202
            $sqlOutput = StringHelper::truncate($sql, $this->maxSqlOutputLength, '[... hidden]');
203
        }
204
205
        echo "    > execute SQL: $sqlOutput ...";
206
        $time = microtime(true);
207
        $this->db->createCommand($sql)->bindValues($params)->execute();
208
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
209
    }
210
211
    /**
212
     * Creates and executes an INSERT SQL statement.
213
     * The method will properly escape the column names, and bind the values to be inserted.
214
     * @param string $table the table that new rows will be inserted into.
215
     * @param array $columns the column data (name => value) to be inserted into the table.
216
     */
217
    public function insert($table, $columns)
218
    {
219
        echo "    > insert into $table ...";
220
        $time = microtime(true);
221
        $this->db->createCommand()->insert($table, $columns)->execute();
222
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
223
    }
224
225
    /**
226
     * Creates and executes an batch INSERT SQL statement.
227
     * The method will properly escape the column names, and bind the values to be inserted.
228
     * @param string $table the table that new rows will be inserted into.
229
     * @param array $columns the column names.
230
     * @param array $rows the rows to be batch inserted into the table
231
     */
232
    public function batchInsert($table, $columns, $rows)
233
    {
234
        echo "    > insert into $table ...";
235
        $time = microtime(true);
236
        $this->db->createCommand()->batchInsert($table, $columns, $rows)->execute();
237
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
238
    }
239
240
    /**
241
     * Creates and executes an UPDATE SQL statement.
242
     * The method will properly escape the column names and bind the values to be updated.
243
     * @param string $table the table to be updated.
244
     * @param array $columns the column data (name => value) to be updated.
245
     * @param array|string $condition the conditions that will be put in the WHERE part. Please
246
     * refer to [[Query::where()]] on how to specify conditions.
247
     * @param array $params the parameters to be bound to the query.
248
     */
249
    public function update($table, $columns, $condition = '', $params = [])
250
    {
251
        echo "    > update $table ...";
252
        $time = microtime(true);
253
        $this->db->createCommand()->update($table, $columns, $condition, $params)->execute();
254
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
255
    }
256
257
    /**
258
     * Creates and executes a DELETE SQL statement.
259
     * @param string $table the table where the data will be deleted from.
260
     * @param array|string $condition the conditions that will be put in the WHERE part. Please
261
     * refer to [[Query::where()]] on how to specify conditions.
262
     * @param array $params the parameters to be bound to the query.
263
     */
264
    public function delete($table, $condition = '', $params = [])
265
    {
266
        echo "    > delete from $table ...";
267
        $time = microtime(true);
268
        $this->db->createCommand()->delete($table, $condition, $params)->execute();
269
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
270
    }
271
272
    /**
273
     * Builds and executes a SQL statement for creating a new DB table.
274
     *
275
     * The columns in the new  table should be specified as name-definition pairs (e.g. 'name' => 'string'),
276
     * where name stands for a column name which will be properly quoted by the method, and definition
277
     * stands for the column type which can contain an abstract DB type.
278
     *
279
     * The [[QueryBuilder::getColumnType()]] method will be invoked to convert any abstract type into a physical one.
280
     *
281
     * If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly
282
     * put into the generated SQL.
283
     *
284
     * @param string $table the name of the table to be created. The name will be properly quoted by the method.
285
     * @param array $columns the columns (name => definition) in the new table.
286
     * @param string $options additional SQL fragment that will be appended to the generated SQL.
287
     */
288 7
    public function createTable($table, $columns, $options = null)
289
    {
290 7
        echo "    > create table $table ...";
291 7
        $time = microtime(true);
292 7
        $this->db->createCommand()->createTable($table, $columns, $options)->execute();
293 7
        foreach ($columns as $column => $type) {
294 7
            if ($type instanceof ColumnSchemaBuilder && $type->comment !== null) {
295
                $this->db->createCommand()->addCommentOnColumn($table, $column, $type->comment)->execute();
296
            }
297
        }
298 7
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
299 7
    }
300
301
    /**
302
     * Builds and executes a SQL statement for renaming a DB table.
303
     * @param string $table the table to be renamed. The name will be properly quoted by the method.
304
     * @param string $newName the new table name. The name will be properly quoted by the method.
305
     */
306
    public function renameTable($table, $newName)
307
    {
308
        echo "    > rename table $table to $newName ...";
309
        $time = microtime(true);
310
        $this->db->createCommand()->renameTable($table, $newName)->execute();
311
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
312
    }
313
314
    /**
315
     * Builds and executes a SQL statement for dropping a DB table.
316
     * @param string $table the table to be dropped. The name will be properly quoted by the method.
317
     */
318 7
    public function dropTable($table)
319
    {
320 7
        echo "    > drop table $table ...";
321 7
        $time = microtime(true);
322 7
        $this->db->createCommand()->dropTable($table)->execute();
323 7
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
324 7
    }
325
326
    /**
327
     * Builds and executes a SQL statement for truncating a DB table.
328
     * @param string $table the table to be truncated. The name will be properly quoted by the method.
329
     */
330
    public function truncateTable($table)
331
    {
332
        echo "    > truncate table $table ...";
333
        $time = microtime(true);
334
        $this->db->createCommand()->truncateTable($table)->execute();
335
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
336
    }
337
338
    /**
339
     * Builds and executes a SQL statement for adding a new DB column.
340
     * @param string $table the table that the new column will be added to. The table name will be properly quoted by the method.
341
     * @param string $column the name of the new column. The name will be properly quoted by the method.
342
     * @param string $type the column type. The [[QueryBuilder::getColumnType()]] method will be invoked to convert abstract column type (if any)
343
     * into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL.
344
     * For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.
345
     */
346
    public function addColumn($table, $column, $type)
347
    {
348
        echo "    > add column $column $type to table $table ...";
349
        $time = microtime(true);
350
        $this->db->createCommand()->addColumn($table, $column, $type)->execute();
351
        if ($type instanceof ColumnSchemaBuilder && $type->comment !== null) {
352
            $this->db->createCommand()->addCommentOnColumn($table, $column, $type->comment)->execute();
353
        }
354
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
355
    }
356
357
    /**
358
     * Builds and executes a SQL statement for dropping a DB column.
359
     * @param string $table the table whose column is to be dropped. The name will be properly quoted by the method.
360
     * @param string $column the name of the column to be dropped. The name will be properly quoted by the method.
361
     */
362
    public function dropColumn($table, $column)
363
    {
364
        echo "    > drop column $column from table $table ...";
365
        $time = microtime(true);
366
        $this->db->createCommand()->dropColumn($table, $column)->execute();
367
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
368
    }
369
370
    /**
371
     * Builds and executes a SQL statement for renaming a column.
372
     * @param string $table the table whose column is to be renamed. The name will be properly quoted by the method.
373
     * @param string $name the old name of the column. The name will be properly quoted by the method.
374
     * @param string $newName the new name of the column. The name will be properly quoted by the method.
375
     */
376
    public function renameColumn($table, $name, $newName)
377
    {
378
        echo "    > rename column $name in table $table to $newName ...";
379
        $time = microtime(true);
380
        $this->db->createCommand()->renameColumn($table, $name, $newName)->execute();
381
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
382
    }
383
384
    /**
385
     * Builds and executes a SQL statement for changing the definition of a column.
386
     * @param string $table the table whose column is to be changed. The table name will be properly quoted by the method.
387
     * @param string $column the name of the column to be changed. The name will be properly quoted by the method.
388
     * @param string $type the new column type. The [[QueryBuilder::getColumnType()]] method will be invoked to convert abstract column type (if any)
389
     * into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL.
390
     * For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.
391
     */
392
    public function alterColumn($table, $column, $type)
393
    {
394
        echo "    > alter column $column in table $table to $type ...";
395
        $time = microtime(true);
396
        $this->db->createCommand()->alterColumn($table, $column, $type)->execute();
397
        if ($type instanceof ColumnSchemaBuilder && $type->comment !== null) {
398
            $this->db->createCommand()->addCommentOnColumn($table, $column, $type->comment)->execute();
399
        }
400
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
401
    }
402
403
    /**
404
     * Builds and executes a SQL statement for creating a primary key.
405
     * The method will properly quote the table and column names.
406
     * @param string $name the name of the primary key constraint.
407
     * @param string $table the table that the primary key constraint will be added to.
408
     * @param string|array $columns comma separated string or array of columns that the primary key will consist of.
409
     */
410
    public function addPrimaryKey($name, $table, $columns)
411
    {
412
        echo "    > add primary key $name on $table (" . (is_array($columns) ? implode(',', $columns) : $columns) . ') ...';
413
        $time = microtime(true);
414
        $this->db->createCommand()->addPrimaryKey($name, $table, $columns)->execute();
415
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
416
    }
417
418
    /**
419
     * Builds and executes a SQL statement for dropping a primary key.
420
     * @param string $name the name of the primary key constraint to be removed.
421
     * @param string $table the table that the primary key constraint will be removed from.
422
     */
423
    public function dropPrimaryKey($name, $table)
424
    {
425
        echo "    > drop primary key $name ...";
426
        $time = microtime(true);
427
        $this->db->createCommand()->dropPrimaryKey($name, $table)->execute();
428
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
429
    }
430
431
    /**
432
     * Builds a SQL statement for adding a foreign key constraint to an existing table.
433
     * The method will properly quote the table and column names.
434
     * @param string $name the name of the foreign key constraint.
435
     * @param string $table the table that the foreign key constraint will be added to.
436
     * @param string|array $columns the name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas or use an array.
437
     * @param string $refTable the table that the foreign key references to.
438
     * @param string|array $refColumns the name of the column that the foreign key references to. If there are multiple columns, separate them with commas or use an array.
439
     * @param string $delete the ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
440
     * @param string $update the ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
441
     */
442
    public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
443
    {
444
        echo "    > add foreign key $name: $table (" . implode(',', (array) $columns) . ") references $refTable (" . implode(',', (array) $refColumns) . ') ...';
445
        $time = microtime(true);
446
        $this->db->createCommand()->addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete, $update)->execute();
447
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
448
    }
449
450
    /**
451
     * Builds a SQL statement for dropping a foreign key constraint.
452
     * @param string $name the name of the foreign key constraint to be dropped. The name will be properly quoted by the method.
453
     * @param string $table the table whose foreign is to be dropped. The name will be properly quoted by the method.
454
     */
455
    public function dropForeignKey($name, $table)
456
    {
457
        echo "    > drop foreign key $name from table $table ...";
458
        $time = microtime(true);
459
        $this->db->createCommand()->dropForeignKey($name, $table)->execute();
460
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
461
    }
462
463
    /**
464
     * Builds and executes a SQL statement for creating a new index.
465
     * @param string $name the name of the index. The name will be properly quoted by the method.
466
     * @param string $table the table that the new index will be created for. The table name will be properly quoted by the method.
467
     * @param string|array $columns the column(s) that should be included in the index. If there are multiple columns, please separate them
468
     * by commas or use an array. Each column name will be properly quoted by the method. Quoting will be skipped for column names that
469
     * include a left parenthesis "(".
470
     * @param bool $unique whether to add UNIQUE constraint on the created index.
471
     */
472 6
    public function createIndex($name, $table, $columns, $unique = false)
473
    {
474 6
        echo '    > create' . ($unique ? ' unique' : '') . " index $name on $table (" . implode(',', (array) $columns) . ') ...';
475 6
        $time = microtime(true);
476 6
        $this->db->createCommand()->createIndex($name, $table, $columns, $unique)->execute();
477 6
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
478 6
    }
479
480
    /**
481
     * Builds and executes a SQL statement for dropping an index.
482
     * @param string $name the name of the index to be dropped. The name will be properly quoted by the method.
483
     * @param string $table the table whose index is to be dropped. The name will be properly quoted by the method.
484
     */
485
    public function dropIndex($name, $table)
486
    {
487
        echo "    > drop index $name on $table ...";
488
        $time = microtime(true);
489
        $this->db->createCommand()->dropIndex($name, $table)->execute();
490
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
491
    }
492
493
    /**
494
     * Builds and execute a SQL statement for adding comment to column
495
     *
496
     * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method.
497
     * @param string $column the name of the column to be commented. The column name will be properly quoted by the method.
498
     * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method.
499
     * @since 2.0.8
500
     */
501
    public function addCommentOnColumn($table, $column, $comment)
502
    {
503
        echo "    > add comment on column $column ...";
504
        $time = microtime(true);
505
        $this->db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute();
506
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
507
    }
508
509
    /**
510
     * Builds a SQL statement for adding comment to table
511
     *
512
     * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method.
513
     * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method.
514
     * @since 2.0.8
515
     */
516
    public function addCommentOnTable($table, $comment)
517
    {
518
        echo "    > add comment on table $table ...";
519
        $time = microtime(true);
520
        $this->db->createCommand()->addCommentOnTable($table, $comment)->execute();
521
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
522
    }
523
524
    /**
525
     * Builds and execute a SQL statement for dropping comment from column
526
     *
527
     * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method.
528
     * @param string $column the name of the column to be commented. The column name will be properly quoted by the method.
529
     * @since 2.0.8
530
     */
531
    public function dropCommentFromColumn($table, $column)
532
    {
533
        echo "    > drop comment from column $column ...";
534
        $time = microtime(true);
535
        $this->db->createCommand()->dropCommentFromColumn($table, $column)->execute();
536
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
537
    }
538
539
    /**
540
     * Builds a SQL statement for dropping comment from table
541
     *
542
     * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method.
543
     * @since 2.0.8
544
     */
545
    public function dropCommentFromTable($table)
546
    {
547
        echo "    > drop comment from table $table ...";
548
        $time = microtime(true);
549
        $this->db->createCommand()->dropCommentFromTable($table)->execute();
550
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
551
    }
552
}
553