@@ -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 );
0 commit comments