Skip to content

Commit db03c07

Browse files
committed
(refactor): rename $blueprint to $table in compile* methods
1 parent 48375f1 commit db03c07

5 files changed

Lines changed: 72 additions & 72 deletions

File tree

src/Query/Schema.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ public function table(string $name): Table
4141
return new Table($this, $name);
4242
}
4343

44-
public function compileCreate(Table $blueprint, bool $ifNotExists = false): Statement
44+
public function compileCreate(Table $table, bool $ifNotExists = false): Statement
4545
{
46-
if ($blueprint->ttl !== null) {
46+
if ($table->ttl !== null) {
4747
throw new UnsupportedException('TTL is only supported in ClickHouse.');
4848
}
4949

5050
$columnDefs = [];
5151
$primaryKeys = [];
5252
$uniqueColumns = [];
5353

54-
foreach ($blueprint->columns as $column) {
54+
foreach ($table->columns as $column) {
5555
$def = $this->compileColumnDefinition($column);
5656
$columnDefs[] = $def;
5757

@@ -63,21 +63,21 @@ public function compileCreate(Table $blueprint, bool $ifNotExists = false): Stat
6363
}
6464
}
6565

66-
if (! empty($blueprint->compositePrimaryKey) && ! empty($primaryKeys)) {
66+
if (! empty($table->compositePrimaryKey) && ! empty($primaryKeys)) {
6767
throw new ValidationException('Cannot combine column-level primary() with Table::primary() composite key.');
6868
}
6969

7070
// Raw column definitions (bypass typed Column objects)
71-
foreach ($blueprint->rawColumnDefs as $rawDef) {
71+
foreach ($table->rawColumnDefs as $rawDef) {
7272
$columnDefs[] = $rawDef;
7373
}
7474

7575
// Inline PRIMARY KEY constraint
7676
if (! empty($primaryKeys)) {
7777
$columnDefs[] = 'PRIMARY KEY (' . \implode(', ', $primaryKeys) . ')';
78-
} elseif (! empty($blueprint->compositePrimaryKey)) {
78+
} elseif (! empty($table->compositePrimaryKey)) {
7979
$columnDefs[] = 'PRIMARY KEY ('
80-
. \implode(', ', \array_map(fn (string $c): string => $this->quote($c), $blueprint->compositePrimaryKey))
80+
. \implode(', ', \array_map(fn (string $c): string => $this->quote($c), $table->compositePrimaryKey))
8181
. ')';
8282
}
8383

@@ -87,12 +87,12 @@ public function compileCreate(Table $blueprint, bool $ifNotExists = false): Stat
8787
}
8888

8989
// Table-level CHECK constraints
90-
foreach ($blueprint->checks as $check) {
90+
foreach ($table->checks as $check) {
9191
$columnDefs[] = 'CONSTRAINT ' . $this->quote($check->name) . ' CHECK (' . $check->expression . ')';
9292
}
9393

9494
// Indexes
95-
foreach ($blueprint->indexes as $index) {
95+
foreach ($table->indexes as $index) {
9696
$keyword = match ($index->type) {
9797
IndexType::Unique => 'UNIQUE INDEX',
9898
IndexType::Fulltext => 'FULLTEXT INDEX',
@@ -104,12 +104,12 @@ public function compileCreate(Table $blueprint, bool $ifNotExists = false): Stat
104104
}
105105

106106
// Raw index definitions (bypass typed Index objects)
107-
foreach ($blueprint->rawIndexDefs as $rawIdx) {
107+
foreach ($table->rawIndexDefs as $rawIdx) {
108108
$columnDefs[] = $rawIdx;
109109
}
110110

111111
// Foreign keys
112-
foreach ($blueprint->foreignKeys as $fk) {
112+
foreach ($table->foreignKeys as $fk) {
113113
$def = 'FOREIGN KEY (' . $this->quote($fk->column) . ')'
114114
. ' REFERENCES ' . $this->quote($fk->refTable)
115115
. ' (' . $this->quote($fk->refColumn) . ')';
@@ -122,24 +122,24 @@ public function compileCreate(Table $blueprint, bool $ifNotExists = false): Stat
122122
$columnDefs[] = $def;
123123
}
124124

125-
$sql = 'CREATE TABLE ' . ($ifNotExists ? 'IF NOT EXISTS ' : '') . $this->quote($blueprint->name)
125+
$sql = 'CREATE TABLE ' . ($ifNotExists ? 'IF NOT EXISTS ' : '') . $this->quote($table->name)
126126
. ' (' . \implode(', ', $columnDefs) . ')';
127127

128-
if ($blueprint->partitionType !== null) {
129-
$sql .= ' PARTITION BY ' . $blueprint->partitionType->value . '(' . $blueprint->partitionExpression . ')';
130-
if ($blueprint->partitionCount !== null) {
131-
$sql .= ' PARTITIONS ' . $blueprint->partitionCount;
128+
if ($table->partitionType !== null) {
129+
$sql .= ' PARTITION BY ' . $table->partitionType->value . '(' . $table->partitionExpression . ')';
130+
if ($table->partitionCount !== null) {
131+
$sql .= ' PARTITIONS ' . $table->partitionCount;
132132
}
133133
}
134134

135135
return new Statement($sql, [], executor: $this->executor);
136136
}
137137

138-
public function compileAlter(Table $blueprint): Statement
138+
public function compileAlter(Table $table): Statement
139139
{
140140
$alterations = [];
141141

142-
foreach ($blueprint->columns as $column) {
142+
foreach ($table->columns as $column) {
143143
$keyword = $column->isModify ? 'MODIFY COLUMN' : 'ADD COLUMN';
144144
$def = $keyword . ' ' . $this->compileColumnDefinition($column);
145145
if ($column->after !== null) {
@@ -148,16 +148,16 @@ public function compileAlter(Table $blueprint): Statement
148148
$alterations[] = $def;
149149
}
150150

151-
foreach ($blueprint->renameColumns as $rename) {
151+
foreach ($table->renameColumns as $rename) {
152152
$alterations[] = 'RENAME COLUMN ' . $this->quote($rename->from)
153153
. ' TO ' . $this->quote($rename->to);
154154
}
155155

156-
foreach ($blueprint->dropColumns as $col) {
156+
foreach ($table->dropColumns as $col) {
157157
$alterations[] = 'DROP COLUMN ' . $this->quote($col);
158158
}
159159

160-
foreach ($blueprint->indexes as $index) {
160+
foreach ($table->indexes as $index) {
161161
$keyword = match ($index->type) {
162162
IndexType::Unique => 'ADD UNIQUE INDEX',
163163
IndexType::Fulltext => 'ADD FULLTEXT INDEX',
@@ -168,11 +168,11 @@ public function compileAlter(Table $blueprint): Statement
168168
. ' (' . $this->compileIndexColumns($index) . ')';
169169
}
170170

171-
foreach ($blueprint->dropIndexes as $name) {
171+
foreach ($table->dropIndexes as $name) {
172172
$alterations[] = 'DROP INDEX ' . $this->quote($name);
173173
}
174174

175-
foreach ($blueprint->foreignKeys as $fk) {
175+
foreach ($table->foreignKeys as $fk) {
176176
$def = 'ADD FOREIGN KEY (' . $this->quote($fk->column) . ')'
177177
. ' REFERENCES ' . $this->quote($fk->refTable)
178178
. ' (' . $this->quote($fk->refColumn) . ')';
@@ -185,11 +185,11 @@ public function compileAlter(Table $blueprint): Statement
185185
$alterations[] = $def;
186186
}
187187

188-
foreach ($blueprint->dropForeignKeys as $name) {
188+
foreach ($table->dropForeignKeys as $name) {
189189
$alterations[] = 'DROP FOREIGN KEY ' . $this->quote($name);
190190
}
191191

192-
$sql = 'ALTER TABLE ' . $this->quote($blueprint->name)
192+
$sql = 'ALTER TABLE ' . $this->quote($table->name)
193193
. ' ' . \implode(', ', $alterations);
194194

195195
return new Statement($sql, [], executor: $this->executor);

src/Query/Schema/ClickHouse.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,53 +102,53 @@ public function dropIndex(string $table, string $name): Statement
102102
}
103103

104104
#[\Override]
105-
public function compileAlter(Table $blueprint): Statement
105+
public function compileAlter(Table $table): Statement
106106
{
107107
$alterations = [];
108108

109-
foreach ($blueprint->columns as $column) {
109+
foreach ($table->columns as $column) {
110110
$keyword = $column->isModify ? 'MODIFY COLUMN' : 'ADD COLUMN';
111111
$alterations[] = $keyword . ' ' . $this->compileColumnDefinition($column);
112112
}
113113

114-
foreach ($blueprint->renameColumns as $rename) {
114+
foreach ($table->renameColumns as $rename) {
115115
$alterations[] = 'RENAME COLUMN ' . $this->quote($rename->from)
116116
. ' TO ' . $this->quote($rename->to);
117117
}
118118

119-
foreach ($blueprint->dropColumns as $col) {
119+
foreach ($table->dropColumns as $col) {
120120
$alterations[] = 'DROP COLUMN ' . $this->quote($col);
121121
}
122122

123-
foreach ($blueprint->dropIndexes as $name) {
123+
foreach ($table->dropIndexes as $name) {
124124
$alterations[] = 'DROP INDEX ' . $this->quote($name);
125125
}
126126

127-
if (! empty($blueprint->foreignKeys)) {
127+
if (! empty($table->foreignKeys)) {
128128
throw new UnsupportedException('Foreign keys are not supported in ClickHouse.');
129129
}
130130

131-
if (! empty($blueprint->dropForeignKeys)) {
131+
if (! empty($table->dropForeignKeys)) {
132132
throw new UnsupportedException('Foreign keys are not supported in ClickHouse.');
133133
}
134134

135135
if (empty($alterations)) {
136136
throw new ValidationException('ALTER TABLE requires at least one alteration.');
137137
}
138138

139-
$sql = 'ALTER TABLE ' . $this->quote($blueprint->name)
139+
$sql = 'ALTER TABLE ' . $this->quote($table->name)
140140
. ' ' . \implode(', ', $alterations);
141141

142142
return new Statement($sql, [], executor: $this->executor);
143143
}
144144

145145
#[\Override]
146-
public function compileCreate(Table $blueprint, bool $ifNotExists = false): Statement
146+
public function compileCreate(Table $table, bool $ifNotExists = false): Statement
147147
{
148148
$columnDefs = [];
149149
$primaryKeys = [];
150150

151-
foreach ($blueprint->columns as $column) {
151+
foreach ($table->columns as $column) {
152152
$def = $this->compileColumnDefinition($column);
153153
$columnDefs[] = $def;
154154

@@ -157,52 +157,52 @@ public function compileCreate(Table $blueprint, bool $ifNotExists = false): Stat
157157
}
158158
}
159159

160-
if (! empty($blueprint->compositePrimaryKey) && ! empty($primaryKeys)) {
160+
if (! empty($table->compositePrimaryKey) && ! empty($primaryKeys)) {
161161
throw new ValidationException('Cannot combine column-level primary() with Table::primary() composite key.');
162162
}
163163

164-
if (empty($primaryKeys) && ! empty($blueprint->compositePrimaryKey)) {
165-
$primaryKeys = \array_map(fn (string $c): string => $this->quote($c), $blueprint->compositePrimaryKey);
164+
if (empty($primaryKeys) && ! empty($table->compositePrimaryKey)) {
165+
$primaryKeys = \array_map(fn (string $c): string => $this->quote($c), $table->compositePrimaryKey);
166166
}
167167

168168
// Indexes (ClickHouse uses INDEX ... TYPE ... GRANULARITY ...)
169-
foreach ($blueprint->indexes as $index) {
169+
foreach ($table->indexes as $index) {
170170
$cols = \array_map(fn (string $c): string => $this->quote($c), $index->columns);
171171
$expr = \count($cols) === 1 ? $cols[0] : '(' . \implode(', ', $cols) . ')';
172172
$columnDefs[] = 'INDEX ' . $this->quote($index->name)
173173
. ' ' . $expr . ' TYPE minmax GRANULARITY 3';
174174
}
175175

176-
if (! empty($blueprint->foreignKeys)) {
176+
if (! empty($table->foreignKeys)) {
177177
throw new UnsupportedException('Foreign keys are not supported in ClickHouse.');
178178
}
179179

180-
if (! empty($blueprint->checks)) {
180+
if (! empty($table->checks)) {
181181
throw new UnsupportedException('CHECK constraints are not supported in ClickHouse.');
182182
}
183183

184-
$engine = $blueprint->engine ?? Engine::MergeTree;
184+
$engine = $table->engine ?? Engine::MergeTree;
185185

186-
$sql = 'CREATE TABLE ' . ($ifNotExists ? 'IF NOT EXISTS ' : '') . $this->quote($blueprint->name)
186+
$sql = 'CREATE TABLE ' . ($ifNotExists ? 'IF NOT EXISTS ' : '') . $this->quote($table->name)
187187
. ' (' . \implode(', ', $columnDefs) . ')'
188-
. ' ENGINE = ' . $this->compileEngine($engine, $blueprint->engineArgs);
188+
. ' ENGINE = ' . $this->compileEngine($engine, $table->engineArgs);
189189

190-
if ($blueprint->partitionType !== null) {
191-
$sql .= ' PARTITION BY ' . $blueprint->partitionExpression;
190+
if ($table->partitionType !== null) {
191+
$sql .= ' PARTITION BY ' . $table->partitionExpression;
192192
}
193193

194194
if ($engine->requiresOrderBy()) {
195-
$orderBy = ! empty($blueprint->orderBy)
196-
? \array_map(fn (string $c): string => $this->quote($c), $blueprint->orderBy)
195+
$orderBy = ! empty($table->orderBy)
196+
? \array_map(fn (string $c): string => $this->quote($c), $table->orderBy)
197197
: $primaryKeys;
198198

199199
$sql .= ! empty($orderBy)
200200
? ' ORDER BY (' . \implode(', ', $orderBy) . ')'
201201
: ' ORDER BY tuple()';
202202
}
203203

204-
if ($blueprint->ttl !== null) {
205-
$sql .= ' TTL ' . $blueprint->ttl;
204+
if ($table->ttl !== null) {
205+
$sql .= ' TTL ' . $table->ttl;
206206
}
207207

208208
return new Statement($sql, [], executor: $this->executor);

src/Query/Schema/MongoDB.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ protected function compileAutoIncrement(): string
4545
}
4646

4747
#[\Override]
48-
public function compileCreate(Table $blueprint, bool $ifNotExists = false): Statement
48+
public function compileCreate(Table $table, bool $ifNotExists = false): Statement
4949
{
50-
if (! empty($blueprint->compositePrimaryKey)) {
50+
if (! empty($table->compositePrimaryKey)) {
5151
throw new UnsupportedException('Composite primary keys are not supported in MongoDB; documents use "_id" implicitly.');
5252
}
5353

5454
$properties = [];
5555
$required = [];
5656

57-
foreach ($blueprint->columns as $column) {
57+
foreach ($table->columns as $column) {
5858
$bsonType = $this->compileColumnType($column);
5959

6060
$prop = ['bsonType' => $bsonType];
@@ -88,7 +88,7 @@ public function compileCreate(Table $blueprint, bool $ifNotExists = false): Stat
8888

8989
$command = [
9090
'command' => 'createCollection',
91-
'collection' => $blueprint->name,
91+
'collection' => $table->name,
9292
];
9393

9494
if (! empty($validator)) {
@@ -103,16 +103,16 @@ public function compileCreate(Table $blueprint, bool $ifNotExists = false): Stat
103103
}
104104

105105
#[\Override]
106-
public function compileAlter(Table $blueprint): Statement
106+
public function compileAlter(Table $table): Statement
107107
{
108-
if (! empty($blueprint->dropColumns) || ! empty($blueprint->renameColumns)) {
108+
if (! empty($table->dropColumns) || ! empty($table->renameColumns)) {
109109
throw new UnsupportedException('MongoDB does not support dropping or renaming columns via schema. Use $unset/$rename update operators.');
110110
}
111111

112112
$properties = [];
113113
$required = [];
114114

115-
foreach ($blueprint->columns as $column) {
115+
foreach ($table->columns as $column) {
116116
$bsonType = $this->compileColumnType($column);
117117
$prop = ['bsonType' => $bsonType];
118118

@@ -141,7 +141,7 @@ public function compileAlter(Table $blueprint): Statement
141141

142142
$command = [
143143
'command' => 'collMod',
144-
'collection' => $blueprint->name,
144+
'collection' => $table->name,
145145
];
146146

147147
if (! empty($validator)) {

0 commit comments

Comments
 (0)