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
|
|
|
* Determines if the migration should be generated for the current module configuration. |
21
|
|
|
* @param Oauth2Module $module |
22
|
|
|
* @return bool |
23
|
|
|
* @since 1.0.0 |
24
|
|
|
*/ |
25
|
|
|
abstract public static function generationIsActive($module); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Get the table name for a model. |
29
|
|
|
* @param string $tableClass |
30
|
|
|
* @return string |
31
|
|
|
* @throws InvalidConfigException |
32
|
|
|
* @since 1.0.0 |
33
|
|
|
*/ |
34
|
1 |
|
protected function getTableName($tableClass) |
35
|
|
|
{ |
36
|
1 |
|
return call_user_func([DiHelper::getValidatedClassName($tableClass), 'tableName']); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get the table schema for a model. |
41
|
|
|
* @param string $tableClass |
42
|
|
|
* @return TableSchema |
43
|
|
|
* @throws InvalidConfigException |
44
|
|
|
* @since 1.0.0 |
45
|
|
|
*/ |
46
|
1 |
|
protected function getTableSchema($tableClass) |
47
|
|
|
{ |
48
|
1 |
|
return call_user_func([DiHelper::getValidatedClassName($tableClass), 'getTableSchema']); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param ColumnSchema $columnSchema |
53
|
|
|
* @return ColumnSchemaBuilder |
54
|
|
|
*/ |
55
|
9 |
|
protected function getColumnSchemaBuilder($columnSchema): ColumnSchemaBuilder |
56
|
|
|
{ |
57
|
9 |
|
$typeFunction = str_replace( |
58
|
9 |
|
[ |
59
|
9 |
|
Schema::TYPE_TINYINT, |
60
|
9 |
|
Schema::TYPE_SMALLINT, |
61
|
9 |
|
Schema::TYPE_BIGINT, |
62
|
9 |
|
], |
63
|
9 |
|
[ |
64
|
9 |
|
'tinyInteger', |
65
|
9 |
|
'smallInteger', |
66
|
9 |
|
'bigInteger', |
67
|
9 |
|
], |
68
|
9 |
|
$columnSchema->type |
69
|
9 |
|
); |
70
|
9 |
|
return $this->{$typeFunction}(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|