17
17
use Doctrine \DBAL \Schema \AbstractSchemaManager ;
18
18
use Doctrine \DBAL \Schema \Column ;
19
19
use Doctrine \DBAL \Schema \Index ;
20
+ use Doctrine \DBAL \Schema \Schema ;
20
21
use Doctrine \DBAL \Schema \View ;
21
22
use Doctrine \DBAL \Types \Type ;
22
- use const CASE_LOWER ;
23
23
use function array_change_key_case ;
24
24
use function array_filter ;
25
25
use function array_key_exists ;
35
35
use function strpos ;
36
36
use function strtolower ;
37
37
use function trim ;
38
+ use const CASE_LOWER ;
38
39
39
40
/**
40
41
* Schema manager for the ClickHouse DBMS.
@@ -59,10 +60,26 @@ protected function _getPortableViewDefinition($view)
59
60
return new View ($ view ['name ' ], $ statement );
60
61
}
61
62
63
+ /**
64
+ * Returns a list of all tables in the current database.
65
+ *
66
+ * @return string[]
67
+ */
68
+ public function listTableNames ()
69
+ {
70
+ $ database = ($ this ->_conn ->getParams ()['stick_to_default ' ] ?? false ) ? $ this ->_conn ->getDatabase () : null ;
71
+ $ sql = $ this ->_platform ->getListTablesSQL ($ database );
72
+
73
+ $ tables = $ this ->_conn ->fetchAll ($ sql );
74
+ $ tableNames = $ this ->_getPortableTablesList ($ tables );
75
+
76
+ return $ this ->filterAssetNames ($ tableNames );
77
+ }
78
+
62
79
/**
63
80
* {@inheritdoc}
64
81
*/
65
- public function listTableIndexes ($ table ) : array
82
+ public function listTableIndexes ($ table ): array
66
83
{
67
84
$ tableView = $ this ->_getPortableViewDefinition (['name ' => $ table ]);
68
85
@@ -96,33 +113,33 @@ function (string $column) {
96
113
/**
97
114
* {@inheritdoc}
98
115
*/
99
- protected function _getPortableTableColumnDefinition ($ tableColumn ) : Column
116
+ protected function _getPortableTableColumnDefinition ($ tableColumn ): Column
100
117
{
101
118
$ tableColumn = array_change_key_case ($ tableColumn , CASE_LOWER );
102
119
103
- $ dbType = $ columnType = trim ($ tableColumn ['type ' ]);
104
- $ length = null ;
105
- $ fixed = false ;
120
+ $ dbType = $ columnType = trim ($ tableColumn ['type ' ]);
121
+ $ length = null ;
122
+ $ fixed = false ;
106
123
$ notnull = true ;
107
124
108
125
if (preg_match ('/(Nullable\((\w+)\))/i ' , $ columnType , $ matches )) {
109
126
$ columnType = str_replace ($ matches [1 ], $ matches [2 ], $ columnType );
110
- $ notnull = false ;
127
+ $ notnull = false ;
111
128
}
112
129
113
130
if (stripos ($ columnType , 'fixedstring ' ) === 0 ) {
114
131
// get length from FixedString definition
115
132
$ length = preg_replace ('~.*\(([0-9]*)\).*~ ' , '$1 ' , $ columnType );
116
133
$ dbType = 'fixedstring ' ;
117
- $ fixed = true ;
134
+ $ fixed = true ;
118
135
}
119
136
120
137
$ unsigned = false ;
121
138
if (stripos ($ columnType , 'uint ' ) === 0 ) {
122
139
$ unsigned = true ;
123
140
}
124
141
125
- if (! isset ($ tableColumn ['name ' ])) {
142
+ if (!isset ($ tableColumn ['name ' ])) {
126
143
$ tableColumn ['name ' ] = '' ;
127
144
}
128
145
@@ -133,14 +150,14 @@ protected function _getPortableTableColumnDefinition($tableColumn) : Column
133
150
}
134
151
135
152
$ options = [
136
- 'length ' => $ length ,
137
- 'notnull ' => $ notnull ,
138
- 'default ' => $ default ,
139
- 'primary ' => false ,
140
- 'fixed ' => $ fixed ,
141
- 'unsigned ' => $ unsigned ,
153
+ 'length ' => $ length ,
154
+ 'notnull ' => $ notnull ,
155
+ 'default ' => $ default ,
156
+ 'primary ' => false ,
157
+ 'fixed ' => $ fixed ,
158
+ 'unsigned ' => $ unsigned ,
142
159
'autoincrement ' => false ,
143
- 'comment ' => null ,
160
+ 'comment ' => null ,
144
161
];
145
162
146
163
return new Column (
0 commit comments