File tree Expand file tree Collapse file tree 2 files changed +24
-10
lines changed
src/Tempest/Database/src/QueryStatements
tests/Integration/Database/QueryStatements Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -89,16 +89,20 @@ public function drop(QueryStatement $statement): self
8989
9090 public function compile (DatabaseDialect $ dialect ): string
9191 {
92- $ alterTable = sprintf (
93- 'ALTER TABLE %s %s; ' ,
94- new TableName ($ this ->tableName ),
95- arr ($ this ->statements )
96- ->map (fn (QueryStatement $ queryStatement ) => str ($ queryStatement ->compile ($ dialect ))->trim ()->replace (' ' , ' ' ))
97- ->filter (fn (StringHelper $ line ) => $ line ->isNotEmpty ())
98- ->implode (', ' . PHP_EOL . ' ' )
99- ->wrap (before: PHP_EOL . ' ' , after: PHP_EOL )
100- ->toString (),
101- );
92+ if ($ this ->statements !== []) {
93+ $ alterTable = sprintf (
94+ 'ALTER TABLE %s %s; ' ,
95+ new TableName ($ this ->tableName ),
96+ arr ($ this ->statements )
97+ ->map (fn (QueryStatement $ queryStatement ) => str ($ queryStatement ->compile ($ dialect ))->trim ()->replace (' ' , ' ' ))
98+ ->filter (fn (StringHelper $ line ) => $ line ->isNotEmpty ())
99+ ->implode (', ' . PHP_EOL . ' ' )
100+ ->wrap (before: PHP_EOL . ' ' , after: PHP_EOL )
101+ ->toString (),
102+ );
103+ } else {
104+ $ alterTable = '' ;
105+ }
102106
103107 if ($ this ->createIndexStatements !== []) {
104108 $ createIndices = PHP_EOL . arr ($ this ->createIndexStatements )
Original file line number Diff line number Diff line change @@ -71,6 +71,16 @@ public function test_it_can_alter_a_table_definition(): void
7171 $ this ->
assertSame (
'[email protected] ' ,
$ user->
email );
7272 }
7373
74+ public function test_alter_for_only_indexes (): void
75+ {
76+ $ statement = new AlterTableStatement ('table ' )
77+ ->index ('foo ' )
78+ ->unique ('bar ' )
79+ ->compile (DatabaseDialect::SQLITE );
80+
81+ $ this ->assertStringNotContainsString ('ALTER TABLE ' , $ statement );
82+ }
83+
7484 private function getAlterTableMigration (): mixed
7585 {
7686 return new class () implements DatabaseMigration {
You can’t perform that action at this time.
0 commit comments