Skip to content

Commit

Permalink
Slight fix to migrations and seeders (ids seem to be unsigned big int…
Browse files Browse the repository at this point in the history
…egers rather than integers)
  • Loading branch information
katsulon committed Dec 5, 2024
1 parent 5a1adad commit f339a7a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function up(): void
$table->id('id');
$table->string('name');
$table->string('color');
$table->integer('timeline');
$table->unsignedBigInteger('timeline');

$table->foreign('timeline')->references('id')->on('timelines')->onDelete('cascade');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function up(): void
$table->id();
$table->string('description');
$table->date('date');
$table->integer('node');
$table->unsignedBigInteger('node');

$table->foreign('node')->references('id')->on('nodes')->onDelete('cascade');

Expand Down
6 changes: 1 addition & 5 deletions timeliner/database/seeders/MilestoneSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ public function run(): void
];

foreach ($milestones as $milestone) {
Milestone::create(array(
'description' => $milestone['description'],
'date' => $milestone['date'],
'node' => $milestone['node']
));
Milestone::create($milestone);
}
}
}
9 changes: 4 additions & 5 deletions timeliner/database/seeders/NodeSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Node;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class NodeSeeder extends Seeder
{
Expand All @@ -14,7 +15,9 @@ class NodeSeeder extends Seeder
*/
public function run(): void
{
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
Node::truncate();
DB::statement('SET FOREIGN_KEY_CHECKS=1;');

$nodes = [
['name' => "Jules' concerts", 'color' => '#ffc0cb', 'timeline' => "1"],
Expand All @@ -24,11 +27,7 @@ public function run(): void
];

foreach ($nodes as $node) {
Node::create(array(
'name' => $node['name'],
'color' => $node['color'],
'timeline' => $node['timeline']
));
Node::create($node);
}
}
}
11 changes: 5 additions & 6 deletions timeliner/database/seeders/TimelineSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@
use App\Models\Timeline;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class TimelineSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
{
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
Timeline::truncate();
DB::statement('SET FOREIGN_KEY_CHECKS=1;');

$timelines = [
['name' => "Timeline number one", 'private' => false, 'description' => "an important timeline"],
['name' => "Anne's timeline", 'private' => true, 'description' => "Only for Anne's friends"],
];

foreach ($timelines as $timeline) {
Timeline::create(array(
'name' => $timeline['name'],
'private' => $timeline['private'],
'description' => $timeline['description']
));
Timeline::create($timeline);
}
}
}

0 comments on commit f339a7a

Please sign in to comment.