Issues (265)

src/Driver/HandlerInterface.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * This file is part of Cycle ORM package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\Database\Driver;
13
14
use Cycle\Database\Exception\HandlerException;
15
use Cycle\Database\Schema\AbstractColumn;
0 ignored issues
show
The type Cycle\Database\Schema\AbstractColumn was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Cycle\Database\Schema\AbstractForeignKey;
17
use Cycle\Database\Schema\AbstractIndex;
18
use Cycle\Database\Schema\AbstractTable;
19
20
/**
21
 * Manages database schema.
22
 *
23
 * @method void enableForeignKeyConstraints() Enable foreign key constraints. Will be added the next major release.
24
 * @method void disableForeignKeyConstraints() Disable foreign key constraints. Will be added the next major release.
25
 */
26
interface HandlerInterface
27
{
28
    //Foreign key modification behaviours
29
    public const DROP_FOREIGN_KEYS = 0b000000001;
30
    public const CREATE_FOREIGN_KEYS = 0b000000010;
31
    public const ALTER_FOREIGN_KEYS = 0b000000100;
32
33
    //All foreign keys related operations
34
    public const DO_FOREIGN_KEYS = self::DROP_FOREIGN_KEYS | self::ALTER_FOREIGN_KEYS | self::CREATE_FOREIGN_KEYS;
35
36
    //Column modification behaviours
37
    public const DROP_COLUMNS = 0b000001000;
38
    public const CREATE_COLUMNS = 0b000010000;
39
    public const ALTER_COLUMNS = 0b000100000;
40
41
    //All columns related operations
42
    public const DO_COLUMNS = self::DROP_COLUMNS | self::ALTER_COLUMNS | self::CREATE_COLUMNS;
43
44
    //Index modification behaviours
45
    public const DROP_INDEXES = 0b001000000;
46
    public const CREATE_INDEXES = 0b010000000;
47
    public const ALTER_INDEXES = 0b100000000;
48
49
    //All index related operations
50
    public const DO_INDEXES = self::DROP_INDEXES | self::ALTER_INDEXES | self::CREATE_INDEXES;
51
52
    //General purpose schema operations
53
    public const DO_RENAME = 0b10000000000;
54
    public const DO_DROP = 0b01000000000;
55
56
    //All operations
57
    public const DO_ALL = self::DO_FOREIGN_KEYS | self::DO_INDEXES | self::DO_COLUMNS | self::DO_DROP | self::DO_RENAME;
58
59
    public function withDriver(DriverInterface $driver): self;
60
61
    /**
62
     * Get all available table names.
63
     *
64
     * @param string|null $prefix
65
     *
66
     */
67
    public function getTableNames(string $prefix = ''): array;
68
69
    /**
70
     * Check if given table exists in database.
71
     *
72
     */
73
    public function hasTable(string $table): bool;
74
75
    /**
76
     * Get or create table schema.
77
     *
78
     * @throws HandlerException
79
     *
80
     */
81
    public function getSchema(string $table, ?string $prefix = null): AbstractTable;
82
83
    /**
84
     * Create table based on a given schema.
85
     *
86
     * @throws HandlerException
87
     */
88
    public function createTable(AbstractTable $table): void;
89
90
    /**
91
     * Truncate table.
92
     *
93
     * @throws HandlerException
94
     */
95
    public function eraseTable(AbstractTable $table): void;
96
97
    /**
98
     * Drop table from database.
99
     *
100
     * @throws HandlerException
101
     */
102
    public function dropTable(AbstractTable $table): void;
103
104
    /**
105
     * Sync given table schema.
106
     *
107
     * @param int           $operation See behaviour constants.
108
     */
109
    public function syncTable(AbstractTable $table, int $operation = self::DO_ALL): void;
110
111
    /**
112
     * Rename table from one name to another.
113
     *
114
     * @throws HandlerException
115
     */
116
    public function renameTable(string $table, string $name): void;
117
118
    /**
119
     * Driver specific column add command.
120
     *
121
     * @throws HandlerException
122
     */
123
    public function createColumn(AbstractTable $table, AbstractColumn $column): void;
124
125
    /**
126
     * Driver specific column remove (drop) command.
127
     *
128
     */
129
    public function dropColumn(AbstractTable $table, AbstractColumn $column): void;
130
131
    /**
132
     * Driver specific column alter command.
133
     *
134
     * @throws HandlerException
135
     */
136
    public function alterColumn(
137
        AbstractTable $table,
138
        AbstractColumn $initial,
139
        AbstractColumn $column,
140
    ): void;
141
142
    /**
143
     * Driver specific index adding command.
144
     *
145
     * @throws HandlerException
146
     */
147
    public function createIndex(AbstractTable $table, AbstractIndex $index): void;
148
149
    /**
150
     * Driver specific index remove (drop) command.
151
     *
152
     * @throws HandlerException
153
     */
154
    public function dropIndex(AbstractTable $table, AbstractIndex $index): void;
155
156
    /**
157
     * Driver specific index alter command, by default it will remove and add index.
158
     *
159
     * @throws HandlerException
160
     */
161
    public function alterIndex(
162
        AbstractTable $table,
163
        AbstractIndex $initial,
164
        AbstractIndex $index,
165
    ): void;
166
167
    /**
168
     * Driver specific foreign key adding command.
169
     *
170
     * @throws HandlerException
171
     */
172
    public function createForeignKey(AbstractTable $table, AbstractForeignKey $foreignKey): void;
173
174
    /**
175
     * Driver specific foreign key remove (drop) command.
176
     *
177
     * @throws HandlerException
178
     */
179
    public function dropForeignKey(AbstractTable $table, AbstractForeignKey $foreignKey): void;
180
181
    /**
182
     * Driver specific foreign key alter command, by default it will remove and add foreign key.
183
     *
184
     * @throws HandlerException
185
     */
186
    public function alterForeignKey(
187
        AbstractTable $table,
188
        AbstractForeignKey $initial,
189
        AbstractForeignKey $foreignKey,
190
    ): void;
191
192
    /**
193
     * Drop column constraint using it's name.
194
     *
195
     * @throws HandlerException
196
     */
197
    public function dropConstrain(AbstractTable $table, string $constraint): void;
198
}
199