Skip to content

Commit 51f3d00

Browse files
authored
Make love_reactant_id & love_reacter_id columns nullable by default (#231)
* Make love_reactant_id & love_reacter_id columns nullable by default * Use new stub method
1 parent a9b7145 commit 51f3d00

File tree

7 files changed

+17
-12
lines changed

7 files changed

+17
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ All notable changes to `laravel-love` will be documented in this file.
1212

1313
### Changed
1414

15+
- ([#231]) Console command `love:setup-reactable` generates migration with nullable column `love_reactant_id` by default
16+
- ([#231]) Console command `love:setup-reactable` option `--nullable` replaced with `--not-nullable`
17+
- ([#231]) Console command `love:setup-reacterable` generates migration with nullable column `love_reacter_id` by default
18+
- ([#231]) Console command `love:setup-reacterable` option `--nullable` replaced with `--not-nullable`
1519
- ([#222]) Removed DI usage from console commands constructors
1620
- ([#215]) Migrated to console `AsCommand` attribute
1721
- ([#215]) Package generating anonymous class migrations now
@@ -563,6 +567,7 @@ Follow [upgrade instructions](UPGRADING.md#from-v5-to-v6) to migrate database to
563567
[1.1.1]: https://github.com/cybercog/laravel-love/compare/1.1.0...1.1.1
564568
[1.1.0]: https://github.com/cybercog/laravel-love/compare/1.0.0...1.1.0
565569

570+
[#231]: https://github.com/cybercog/laravel-love/pull/231
566571
[#222]: https://github.com/cybercog/laravel-love/pull/222
567572
[#218]: https://github.com/cybercog/laravel-love/pull/218
568573
[#217]: https://github.com/cybercog/laravel-love/pull/217

src/Console/Commands/SetupReactable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function handle(
4848
$model = $this->resolveModel();
4949
$model = $this->sanitizeName($model);
5050
$foreignColumn = 'love_reactant_id';
51-
$isForeignColumnNullable = boolval($this->option('nullable'));
51+
$isForeignColumnNullable = boolval($this->option('not-nullable')) === false;
5252

5353
if (!class_exists($model)) {
5454
$this->error(
@@ -140,9 +140,9 @@ protected function getOptions(): array
140140
description: 'The name of the reactable model',
141141
),
142142
new InputOption(
143-
name: 'nullable',
143+
name: 'not-nullable',
144144
mode: InputOption::VALUE_NONE,
145-
description: 'Indicate if foreign column allows null values',
145+
description: 'Indicate if foreign column does not allow null values',
146146
),
147147
];
148148
}

src/Console/Commands/SetupReacterable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function handle(
4848
$model = $this->resolveModel();
4949
$model = $this->sanitizeName($model);
5050
$foreignColumn = 'love_reacter_id';
51-
$isForeignColumnNullable = boolval($this->option('nullable'));
51+
$isForeignColumnNullable = boolval($this->option('not-nullable')) === false;
5252

5353
if (!class_exists($model)) {
5454
$this->error(
@@ -140,9 +140,9 @@ protected function getOptions(): array
140140
description: 'The name of the reacterable model',
141141
),
142142
new InputOption(
143-
name: 'nullable',
143+
name: 'not-nullable',
144144
mode: InputOption::VALUE_NONE,
145-
description: 'Indicate if foreign column allows null values',
145+
description: 'Indicate if foreign column does not allow null values',
146146
),
147147
];
148148
}

src/Support/Database/Stubs/AddForeignColumn.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ return new class extends Migration
2020
public function up(): void
2121
{
2222
Schema::table('DummyTable', function (Blueprint $table) {
23-
$table->unsignedBigInteger('DummyForeignColumn');
23+
$table->foreignId('DummyForeignColumn');
2424

2525
$table
2626
->foreign('DummyForeignColumn')

src/Support/Database/Stubs/AddForeignNullableColumn.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ return new class extends Migration
2020
public function up(): void
2121
{
2222
Schema::table('DummyTable', function (Blueprint $table) {
23-
$table->unsignedBigInteger('DummyForeignColumn')->nullable();
23+
$table->foreignId('DummyForeignColumn')->nullable();
2424

2525
$table
2626
->foreign('DummyForeignColumn')

tests/Unit/Console/Commands/SetupReactableTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ public function it_can_create_migration_for_reactable_model(): void
5151
}
5252

5353
/** @test */
54-
public function it_can_create_migration_for_reactable_model_with_nullable_column(): void
54+
public function it_can_create_migration_for_reactable_model_with_not_nullable_column(): void
5555
{
5656
$status = $this->artisan('love:setup-reactable', [
5757
'--model' => Person::class,
58-
'--nullable' => true,
58+
'--not-nullable' => true,
5959
]);
6060

6161
$this->assertSame(0, $status);

tests/Unit/Console/Commands/SetupReacterableTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ public function it_can_create_migration_for_reacterable_model(): void
5151
}
5252

5353
/** @test */
54-
public function it_can_create_migration_for_reacterable_model_with_nullable_column(): void
54+
public function it_can_create_migration_for_reacterable_model_with_not_nullable_column(): void
5555
{
5656
$status = $this->artisan('love:setup-reacterable', [
5757
'--model' => Person::class,
58-
'--nullable' => true,
58+
'--not-nullable' => true,
5959
]);
6060

6161
$this->assertSame(0, $status);

0 commit comments

Comments
 (0)