Skip to content

Commit

Permalink
Make fk definition compatible with SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurt Friars committed Oct 7, 2024
1 parent 2e12f2a commit 2485e89
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 86 deletions.
26 changes: 26 additions & 0 deletions tests/Database/Migrations/schema/fks/create_signatures_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Plank\Snapshots\Migrator\SnapshotBlueprint;
use Plank\Snapshots\Migrator\SnapshotMigration;

return new class extends SnapshotMigration
{
public function up()
{
$this->schema->create('signatures', function (SnapshotBlueprint $table) {
$table->id();
$table->unsignedBigInteger('document_id');
$table->string('svg');
$table->timestamps();

$table->foreign('document_id')
->references('id')
->onSnapshot('documents');
});
}

public function down()
{
$this->schema->drop('signatures');
}
};
22 changes: 0 additions & 22 deletions tests/Database/Migrations/schema/fks/y_add_folders_table.php

This file was deleted.

26 changes: 0 additions & 26 deletions tests/Database/Migrations/schema/fks/z_alter_documents_table.php

This file was deleted.

29 changes: 0 additions & 29 deletions tests/Models/Folder.php

This file was deleted.

13 changes: 4 additions & 9 deletions tests/Suites/Feature/Schema/SchemaBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,26 +348,21 @@
])->run();

assertDatabaseHas('migrations', [
'migration' => 'y_add_folders_table',
'batch' => 4,
]);

assertDatabaseHas('migrations', [
'migration' => 'z_alter_documents_table',
'migration' => 'create_signatures_table',
'batch' => 4,
]);

versions()->setActive(createFirstVersion('schema/fks'));

$fks = SnapshotSchema::getForeignKeys('documents');
$fks = SnapshotSchema::getForeignKeys('signatures');

expect($fks)->toContain([
'name' => null,
'columns' => [
0 => 'folder_id',
0 => 'document_id',
],
'foreign_schema' => null,
'foreign_table' => 'v1_0_0_folders',
'foreign_table' => 'v1_0_0_documents',
'foreign_columns' => [
0 => 'id',
],
Expand Down

0 comments on commit 2485e89

Please sign in to comment.