-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathAbstractMigration.php
More file actions
84 lines (75 loc) · 2.43 KB
/
AbstractMigration.php
File metadata and controls
84 lines (75 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
declare(strict_types=1);
/**
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Migrations;
use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Migration\AbstractMigration as BaseAbstractMigration;
use Phinx\Migration\MigrationInterface;
use function Cake\Core\deprecationWarning;
/**
* @deprecated 4.5.0 You should use Migrations\BaseMigration for new migrations.
*/
class AbstractMigration extends BaseAbstractMigration
{
/**
* Whether the tables created in this migration
* should auto-create an `id` field or not
*
* This option is global for all tables created in the migration file.
* If you set it to false, you have to manually add the primary keys for your
* tables using the Migrations\Table::addPrimaryKey() method
*
* @var bool
*/
public bool $autoId = true;
/**
* @inheritDoc
*/
public function setAdapter(AdapterInterface $adapter): MigrationInterface
{
deprecationWarning(
'4.5.0',
'Migrations\AbstractMigration is deprecated. Use Migrations\BaseMigration instead.',
);
return parent::setAdapter($adapter);
}
/**
* Hook method to decide if this migration should use transactions
*
* By default, if your driver supports transactions, a transaction will be opened
* before the migration begins, and commit when the migration completes.
*
* @return bool
*/
public function useTransactions(): bool
{
return $this->getAdapter()->hasTransactions();
}
/**
* Returns an instance of the Table class.
*
* You can use this class to create and manipulate tables.
*
* @param string $tableName Table Name
* @param array $options Options
* @return \Migrations\Table
*/
public function table(string $tableName, array $options = []): Table
{
if ($this->autoId === false) {
$options['id'] = false;
}
$table = new Table($tableName, $options, $this->getAdapter());
$this->tables[] = $table;
return $table;
}
}