-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathSchemaInterface.php
433 lines (417 loc) · 14.5 KB
/
SchemaInterface.php
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<?php
declare(strict_types=1);
namespace Yiisoft\Db\Schema;
use Throwable;
use Yiisoft\Db\Constant\DataType;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constant\PseudoType;
use Yiisoft\Db\Constraint\ConstraintSchemaInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
/**
* Represents the schema for a database table.
*
* It provides a set of methods for working with the schema of a database table, such as accessing the columns,
* indexes, and constraints of a table, as well as methods for creating, dropping, and altering tables.
*/
interface SchemaInterface extends ConstraintSchemaInterface
{
/**
* The metadata type for retrieving the table schema.
*/
public const SCHEMA = 'schema';
/**
* The metadata type for retrieving the primary key constraint.
*/
public const PRIMARY_KEY = 'primaryKey';
/**
* The metadata type for retrieving the index constraints.
*/
public const INDEXES = 'indexes';
/**
* The metadata type for retrieving the check constraint.
*/
public const CHECKS = 'checks';
/**
* The metadata type for retrieving the foreign key constraints.
*/
public const FOREIGN_KEYS = 'foreignKeys';
/**
* The metadata type for retrieving the default values constraint.
*/
public const DEFAULT_VALUES = 'defaultValues';
/**
* The metadata type for retrieving the unique constraints.
*/
public const UNIQUES = 'uniques';
/**
* The metadata type for retrieving the default constraint.
*/
public const DEFAULTS = 'defaults';
/**
* Define the type of the index as `UNIQUE`, it's used in {@see DDLQueryBuilderInterface::createIndex()}.
*
* Supported by `MySQL`, `MariaDB`, `MSSQL`, `Oracle`, `PostgreSQL`, `SQLite`.
*
* @deprecated Use {@see IndexType::UNIQUE} instead. Will be removed in 2.0.
*/
public const INDEX_UNIQUE = 'UNIQUE';
/**
* Define the type of the index as `BTREE`, it's used in {@see DDLQueryBuilderInterface::createIndex()}.
*
* Supported by `MySQL`, `PostgreSQL`.
*
* @deprecated Use {@see IndexType::BTREE} instead. Will be removed in 2.0.
*/
public const INDEX_BTREE = 'BTREE';
/**
* Define the type of the index as `HASH`, it's used in {@see DDLQueryBuilderInterface::createIndex()}.
*
* Supported by `MySQL`, `PostgreSQL`.
*
* @deprecated Use {@see IndexType::HASH} instead. Will be removed in 2.0.
*/
public const INDEX_HASH = 'HASH';
/**
* Define the type of the index as `FULLTEXT`, it's used in {@see DDLQueryBuilderInterface::createIndex()}.
*
* Supported by `MySQL`.
*
* @deprecated Use {@see IndexType::FULLTEXT} instead. Will be removed in 2.0.
*/
public const INDEX_FULLTEXT = 'FULLTEXT';
/**
* Define the type of the index as `SPATIAL`, it's used in {@see DDLQueryBuilderInterface::createIndex()}.
*
* Supported by `MySQL`.
*
* @deprecated Use {@see IndexType::SPATIAL} instead. Will be removed in 2.0.
*/
public const INDEX_SPATIAL = 'SPATIAL';
/**
* Define the type of the index as `GIST`, it's used in {@see DDLQueryBuilderInterface::createIndex()}.
*
* Supported by `PostgreSQL`.
*
* @deprecated Use {@see IndexMethod::GIST} instead. Will be removed in 2.0.
*/
public const INDEX_GIST = 'GIST';
/**
* Define the type of the index as `GIN`, it's used in {@see DDLQueryBuilderInterface::createIndex()}.
*
* Supported by `PostgreSQL`.
*
* @deprecated Use {@see IndexMethod::GIN} instead. Will be removed in 2.0.
*/
public const INDEX_GIN = 'GIN';
/**
* Define the type of the index as `BRIN`, it's used in {@see DDLQueryBuilderInterface::createIndex()}.
*
* Supported by `PostgreSQL`.
*
* @deprecated Use {@see IndexMethod::BRIN} instead. Will be removed in 2.0.
*/
public const INDEX_BRIN = 'BRIN';
/**
* Define the type of the index as `CLUSTERED`, it's used in {@see DDLQueryBuilderInterface::createIndex()}.
*
* Supported by `MSSQL`.
*
* @deprecated Use {@see IndexType::CLUSTERED} instead. Will be removed in 2.0.
*/
public const INDEX_CLUSTERED = 'CLUSTERED';
/**
* Define the type of the index as `NONCLUSTERED`, it's used in {@see DDLQueryBuilderInterface::createIndex()}.
*
* Supported by `MSSQL`.
*
* @deprecated Use {@see IndexType::NONCLUSTERED} instead. Will be removed in 2.0.
*/
public const INDEX_NONCLUSTERED = 'NONCLUSTERED';
/**
* Define the type of the index as `BITMAP`, it's used in {@see DDLQueryBuilderInterface::createIndex()}.
*
* Supported by `Oracle`.
*
* @deprecated Use {@see IndexType::BITMAP} instead. Will be removed in 2.0.
*/
public const INDEX_BITMAP = 'BITMAP';
/**
* Define the abstract column type as a primary key.
*
* @deprecated Use {@see PseudoType::PK} instead. Will be removed in 2.0.
*/
public const TYPE_PK = 'pk';
/**
* Define the abstract column type as an `unsigned` primary key.
*
* @deprecated Use {@see PseudoType::UPK} instead. Will be removed in 2.0.
*/
public const TYPE_UPK = 'upk';
/**
* Define the abstract column type as big primary key.
*
* @deprecated Use {@see PseudoType::BIGPK} instead. Will be removed in 2.0.
*/
public const TYPE_BIGPK = 'bigpk';
/**
* Define the abstract column type as `unsigned` big primary key.
*
* @deprecated Use {@see PseudoType::UBIGPK} instead. Will be removed in 2.0.
*/
public const TYPE_UBIGPK = 'ubigpk';
/**
* Define the abstract column type as an `uuid` primary key.
*
* @deprecated Use {@see PseudoType::UUID_PK} instead. Will be removed in 2.0.
*/
public const TYPE_UUID_PK = 'uuid_pk';
/**
* Define the abstract column type as an`uuid` primary key with a sequence.
*
* @deprecated Use {@see PseudoType::UUID_PK_SEQ} instead. Will be removed in 2.0.
*/
public const TYPE_UUID_PK_SEQ = 'uuid_pk_seq';
/**
* Define the abstract column type as `uuid`.
*
* @deprecated Use {@see ColumnType::UUID} instead. Will be removed in 2.0.
*/
public const TYPE_UUID = 'uuid';
/**
* Define the abstract column type as `char`.
*
* @deprecated Use {@see ColumnType::CHAR} instead. Will be removed in 2.0.
*/
public const TYPE_CHAR = 'char';
/**
* Define the abstract column type as `string`.
*
* @deprecated Use {@see ColumnType::STRING} instead. Will be removed in 2.0.
*/
public const TYPE_STRING = 'string';
/**
* Define the abstract column type as `text`.
*
* @deprecated Use {@see ColumnType::TEXT} instead. Will be removed in 2.0.
*/
public const TYPE_TEXT = 'text';
/**
* Define the abstract column type as `tinyint`.
*
* @deprecated Use {@see ColumnType::TINYINT} instead. Will be removed in 2.0.
*/
public const TYPE_TINYINT = 'tinyint';
/**
* Define the abstract column type as `smallint`.
*
* @deprecated Use {@see ColumnType::SMALLINT} instead. Will be removed in 2.0.
*/
public const TYPE_SMALLINT = 'smallint';
/**
* Define the abstract column type as `integer`.
*
* @deprecated Use {@see ColumnType::INTEGER} instead. Will be removed in 2.0.
*/
public const TYPE_INTEGER = 'integer';
/**
* Define the abstract column type as `bigint`.
*
* @deprecated Use {@see ColumnType::BIGINT} instead. Will be removed in 2.0.
*/
public const TYPE_BIGINT = 'bigint';
/**
* Define the abstract column type as `float`.
*
* @deprecated Use {@see ColumnType::FLOAT} instead. Will be removed in 2.0.
*/
public const TYPE_FLOAT = 'float';
/**
* Define the abstract column type as `double`.
*
* @deprecated Use {@see ColumnType::DOUBLE} instead. Will be removed in 2.0.
*/
public const TYPE_DOUBLE = 'double';
/**
* Define the abstract column type as `decimal`.
*
* @deprecated Use {@see ColumnType::DECIMAL} instead. Will be removed in 2.0.
*/
public const TYPE_DECIMAL = 'decimal';
/**
* Define the abstract column type as `datetime`.
*
* @deprecated Use {@see ColumnType::DATETIME} instead. Will be removed in 2.0.
*/
public const TYPE_DATETIME = 'datetime';
/**
* Define the abstract column type as `timestamp`.
*
* @deprecated Use {@see ColumnType::TIMESTAMP} instead. Will be removed in 2.0.
*/
public const TYPE_TIMESTAMP = 'timestamp';
/**
* Define the abstract column type as `time`.
*
* @deprecated Use {@see ColumnType::TIME} instead. Will be removed in 2.0.
*/
public const TYPE_TIME = 'time';
/**
* Define the abstract column type as `date`.
*
* @deprecated Use {@see ColumnType::DATE} instead. Will be removed in 2.0.
*/
public const TYPE_DATE = 'date';
/**
* Define the abstract column type as `binary`.
*
* @deprecated Use {@see ColumnType::BINARY} instead. Will be removed in 2.0.
*/
public const TYPE_BINARY = 'binary';
/**
* Define the abstract column type as `boolean`.
*
* @deprecated Use {@see ColumnType::BOOLEAN} instead. Will be removed in 2.0.
*/
public const TYPE_BOOLEAN = 'boolean';
/**
* Define the abstract column type as `bit`.
*
* @deprecated Use {@see ColumnType::BIT} instead. Will be removed in 2.0.
*/
public const TYPE_BIT = 'bit';
/**
* Define the abstract column type as `money`.
*
* @deprecated Use {@see ColumnType::MONEY} instead. Will be removed in 2.0.
*/
public const TYPE_MONEY = 'money';
/**
* Define the abstract column type as `json`.
*
* @deprecated Use {@see ColumnType::JSON} instead. Will be removed in 2.0.
*/
public const TYPE_JSON = 'json';
/**
* Returns the column factory for creating column instances.
*/
public function getColumnFactory(): ColumnFactoryInterface;
/**
* @return string|null The default schema name.
*/
public function getDefaultSchema(): string|null;
/**
* Determines the SQL data type for the given PHP data value.
*
* @param mixed $data The data to find a type for.
*
* @return int The type.
*
* @psalm-return DataType::*
*/
public function getDataType(mixed $data): int;
/**
* Returns all schema names in the database, except system schemas.
*
* @param bool $refresh Whether to fetch the latest available schema names. If this is `false`, schema names fetched
* before (if available) will be returned.
*
* @throws NotSupportedException
*
* @return array All schemas name in the database, except system schemas.
*/
public function getSchemaNames(bool $refresh = false): array;
/**
* Returns all table names in the database.
*
* @param string $schema The schema of the tables. Defaults to empty string, meaning the current or default schema
* name.
* If not empty, the returned table names will be prefixed with the schema name.
* @param bool $refresh Whether to fetch the latest available table names. If this is `false`, table names fetched
* before (if available) will be returned.
*
* @throws NotSupportedException
*
* @return array All tables name in the database.
*/
public function getTableNames(string $schema = '', bool $refresh = false): array;
/**
* Returns all unique indexes for the given table.
*
* Each array element is of the following structure:
*
* ```php
* [
* 'IndexName1' => ['col1' [, ...]],
* 'IndexName2' => ['col2' [, ...]],
* ]
* ```
*
* @param TableSchemaInterface $table The table metadata.
*
* @throws Exception
* @throws InvalidConfigException
* @throws Throwable
*
* @return array All unique indexes for the given table.
*/
public function findUniqueIndexes(TableSchemaInterface $table): array;
/**
* Obtains the metadata for the named table.
*
* @param string $name Table name. The table name may contain a schema name if any.
* Don't quote the table name.
* @param bool $refresh Whether to reload the table schema even if it's found in the cache.
*
* @return TableSchemaInterface|null Table metadata. `null` if the named table doesn't exist.
*/
public function getTableSchema(string $name, bool $refresh = false): TableSchemaInterface|null;
/**
* Returns the metadata for all tables in the database.
*
* @param string $schema The schema of the tables. Defaults to empty string, meaning the current or default schema
* name.
* @param bool $refresh Whether to fetch the latest available table schemas. If this is `false`, cached data may be
* returned if available.
*
* @return array The metadata for all tables in the database.
*
* @psalm-return list<TableSchemaInterface>
*/
public function getTableSchemas(string $schema = '', bool $refresh = false): array;
/**
* Refreshes the schema.
*
* This method cleans up all cached table schemas so that they can be re-created later to reflect the database
* schema change.
*/
public function refresh(): void;
/**
* Refreshes the particular table schema.
*
* This method cleans up cached table schema so that it can be re-created later to reflect the database schema
* change.
*
* @param string $name Table name.
*/
public function refreshTableSchema(string $name): void;
/**
* Enable or disable the schema cache.
*
* @param bool $value Whether to enable or disable the schema cache.
*/
public function enableCache(bool $value): void;
/**
* Returns all view names in the database.
*
* @param string $schema The schema of the views. Defaults to empty string, meaning the current or default schema
* name. If not empty, the returned view names will be prefixed with the schema name.
* @param bool $refresh Whether to fetch the latest available view names. If this is false, view names fetched
* before (if available) will be returned.
*
* @return array All view names in the database.
*/
public function getViewNames(string $schema = '', bool $refresh = false): array;
}