|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace rhertogh\Yii2Oauth2Server\migrations\base; |
|
4
|
|
|
|
|
5
|
|
|
use rhertogh\Yii2Oauth2Server\helpers\DiHelper; |
|
6
|
|
|
use rhertogh\Yii2Oauth2Server\Oauth2Module; |
|
7
|
|
|
use yii\base\InvalidConfigException; |
|
8
|
|
|
use yii\db\ColumnSchema; |
|
9
|
|
|
use yii\db\ColumnSchemaBuilder; |
|
10
|
|
|
use yii\db\Migration; |
|
11
|
|
|
use yii\db\Schema; |
|
12
|
|
|
use yii\db\TableSchema; |
|
13
|
|
|
|
|
14
|
|
|
abstract class Oauth2BaseMigration extends Migration |
|
15
|
|
|
{ |
|
16
|
|
|
public const RESTRICT = 'RESTRICT'; |
|
17
|
|
|
public const CASCADE = 'CASCADE'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $config = []; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Determines if the migration should be generated for the current module configuration. |
|
26
|
|
|
* @param Oauth2Module $module |
|
27
|
|
|
* @return bool |
|
28
|
|
|
* @since 1.0.0 |
|
29
|
|
|
*/ |
|
30
|
|
|
abstract public static function generationIsActive($module); |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Get the table name for a model. |
|
34
|
|
|
* @param string $tableClass |
|
35
|
|
|
* @return string |
|
36
|
|
|
* @throws InvalidConfigException |
|
37
|
|
|
* @since 1.0.0 |
|
38
|
|
|
*/ |
|
39
|
1 |
|
protected function getTableName($tableClass) |
|
40
|
|
|
{ |
|
41
|
1 |
|
return call_user_func([DiHelper::getValidatedClassName($tableClass), 'tableName']); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get the table schema for a model. |
|
46
|
|
|
* @param string $tableClass |
|
47
|
|
|
* @return TableSchema |
|
48
|
|
|
* @throws InvalidConfigException |
|
49
|
|
|
* @since 1.0.0 |
|
50
|
|
|
*/ |
|
51
|
1 |
|
protected function getTableSchema($tableClass) |
|
52
|
|
|
{ |
|
53
|
1 |
|
return call_user_func([DiHelper::getValidatedClassName($tableClass), 'getTableSchema']); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param ColumnSchema $columnSchema |
|
58
|
|
|
* @return ColumnSchemaBuilder |
|
59
|
|
|
*/ |
|
60
|
9 |
|
protected function getColumnSchemaBuilder($columnSchema): ColumnSchemaBuilder |
|
61
|
|
|
{ |
|
62
|
9 |
|
$typeFunction = str_replace( |
|
63
|
9 |
|
[ |
|
64
|
9 |
|
Schema::TYPE_TINYINT, |
|
65
|
9 |
|
Schema::TYPE_SMALLINT, |
|
66
|
9 |
|
Schema::TYPE_BIGINT, |
|
67
|
9 |
|
], |
|
68
|
9 |
|
[ |
|
69
|
9 |
|
'tinyInteger', |
|
70
|
9 |
|
'smallInteger', |
|
71
|
9 |
|
'bigInteger', |
|
72
|
9 |
|
], |
|
73
|
9 |
|
$columnSchema->type, |
|
74
|
9 |
|
); |
|
75
|
9 |
|
return $this->{$typeFunction}(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
protected function deferredForeignKeyCreationSupported() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->getDb()->getDriverName() !== 'sqlite'; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
protected function commentsSupported() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->getDb()->getDriverName() !== 'sqlite'; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
protected function deferredPrimaryKeyCreationSupported() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->getDb()->getDriverName() !== 'sqlite'; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|