Skip to content

Commit bc4db3f

Browse files
committed
fix(schema): drop SQLite Feature\ForeignKeys (ALTER FK not supported)
The shared Schema\Trait\ForeignKeys emits ALTER TABLE ADD CONSTRAINT and ALTER TABLE DROP FOREIGN KEY — neither is valid SQLite. Schema\SQLite should not implement Feature\ForeignKeys; users that need foreign keys on SQLite declare them inline at CREATE TABLE time via the Table-level \$table->foreignKey() helper, which Table\SQLite still supports. Removes the schema-level addForeignKey/dropForeignKey from SQLite and the corresponding tests that asserted invalid SQLite DDL.
1 parent 31c95b6 commit bc4db3f

2 files changed

Lines changed: 1 addition & 48 deletions

File tree

src/Query/Schema/SQLite.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
use Utopia\Query\Builder\Statement;
66
use Utopia\Query\Exception\UnsupportedException;
7-
use Utopia\Query\Schema\Feature\ForeignKeys;
87
use Utopia\Query\Schema\Feature\Views;
98

10-
class SQLite extends SQL implements ForeignKeys, Views
9+
class SQLite extends SQL implements Views
1110
{
12-
use Trait\ForeignKeys;
1311
use Trait\Views;
1412

1513
#[\Override]

tests/Query/Schema/SQLiteTest.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@
99
use Utopia\Query\Exception\ValidationException;
1010
use Utopia\Query\Query;
1111
use Utopia\Query\Schema\ColumnType;
12-
use Utopia\Query\Schema\Feature\ForeignKeys;
1312
use Utopia\Query\Schema\ForeignKeyAction;
1413
use Utopia\Query\Schema\SQLite as Schema;
1514

1615
class SQLiteTest extends TestCase
1716
{
1817
use AssertsBindingCount;
1918

20-
public function testImplementsForeignKeys(): void
21-
{
22-
$this->assertInstanceOf(ForeignKeys::class, new Schema());
23-
}
24-
2519
public function testCreateTableBasic(): void
2620
{
2721
$schema = new Schema();
@@ -355,45 +349,6 @@ public function testDropView(): void
355349
$this->assertSame('DROP VIEW `active_users`', $result->query);
356350
}
357351

358-
public function testAddForeignKeyStandalone(): void
359-
{
360-
$schema = new Schema();
361-
$result = $schema->addForeignKey(
362-
'orders',
363-
'fk_user',
364-
'user_id',
365-
'users',
366-
'id',
367-
onDelete: ForeignKeyAction::Cascade,
368-
onUpdate: ForeignKeyAction::SetNull
369-
);
370-
371-
$this->assertSame(
372-
'ALTER TABLE `orders` ADD CONSTRAINT `fk_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE SET NULL',
373-
$result->query
374-
);
375-
}
376-
377-
public function testAddForeignKeyNoActions(): void
378-
{
379-
$schema = new Schema();
380-
$result = $schema->addForeignKey('orders', 'fk_user', 'user_id', 'users', 'id');
381-
382-
$this->assertStringNotContainsString('ON DELETE', $result->query);
383-
$this->assertStringNotContainsString('ON UPDATE', $result->query);
384-
}
385-
386-
public function testDropForeignKeyStandalone(): void
387-
{
388-
$schema = new Schema();
389-
$result = $schema->dropForeignKey('orders', 'fk_user');
390-
391-
$this->assertSame(
392-
'ALTER TABLE `orders` DROP FOREIGN KEY `fk_user`',
393-
$result->query
394-
);
395-
}
396-
397352
public function testCreateTableWithMultiplePrimaryKeys(): void
398353
{
399354
$schema = new Schema();

0 commit comments

Comments
 (0)