Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make love_reactant_id & love_reacter_id columns nullable by default #231

Merged
merged 2 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ All notable changes to `laravel-love` will be documented in this file.

### Changed

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

[#231]: https://github.com/cybercog/laravel-love/pull/231
[#222]: https://github.com/cybercog/laravel-love/pull/222
[#218]: https://github.com/cybercog/laravel-love/pull/218
[#217]: https://github.com/cybercog/laravel-love/pull/217
Expand Down
6 changes: 3 additions & 3 deletions src/Console/Commands/SetupReactable.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function handle(
$model = $this->resolveModel();
$model = $this->sanitizeName($model);
$foreignColumn = 'love_reactant_id';
$isForeignColumnNullable = boolval($this->option('nullable'));
$isForeignColumnNullable = boolval($this->option('not-nullable')) === false;

if (!class_exists($model)) {
$this->error(
Expand Down Expand Up @@ -140,9 +140,9 @@ protected function getOptions(): array
description: 'The name of the reactable model',
),
new InputOption(
name: 'nullable',
name: 'not-nullable',
mode: InputOption::VALUE_NONE,
description: 'Indicate if foreign column allows null values',
description: 'Indicate if foreign column does not allow null values',
),
];
}
Expand Down
6 changes: 3 additions & 3 deletions src/Console/Commands/SetupReacterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function handle(
$model = $this->resolveModel();
$model = $this->sanitizeName($model);
$foreignColumn = 'love_reacter_id';
$isForeignColumnNullable = boolval($this->option('nullable'));
$isForeignColumnNullable = boolval($this->option('not-nullable')) === false;

if (!class_exists($model)) {
$this->error(
Expand Down Expand Up @@ -140,9 +140,9 @@ protected function getOptions(): array
description: 'The name of the reacterable model',
),
new InputOption(
name: 'nullable',
name: 'not-nullable',
mode: InputOption::VALUE_NONE,
description: 'Indicate if foreign column allows null values',
description: 'Indicate if foreign column does not allow null values',
),
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Database/Stubs/AddForeignColumn.stub
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ return new class extends Migration
public function up(): void
{
Schema::table('DummyTable', function (Blueprint $table) {
$table->unsignedBigInteger('DummyForeignColumn');
$table->foreignId('DummyForeignColumn');

$table
->foreign('DummyForeignColumn')
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Database/Stubs/AddForeignNullableColumn.stub
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ return new class extends Migration
public function up(): void
{
Schema::table('DummyTable', function (Blueprint $table) {
$table->unsignedBigInteger('DummyForeignColumn')->nullable();
$table->foreignId('DummyForeignColumn')->nullable();

$table
->foreign('DummyForeignColumn')
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Console/Commands/SetupReactableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public function it_can_create_migration_for_reactable_model(): void
}

/** @test */
public function it_can_create_migration_for_reactable_model_with_nullable_column(): void
public function it_can_create_migration_for_reactable_model_with_not_nullable_column(): void
{
$status = $this->artisan('love:setup-reactable', [
'--model' => Person::class,
'--nullable' => true,
'--not-nullable' => true,
]);

$this->assertSame(0, $status);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Console/Commands/SetupReacterableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public function it_can_create_migration_for_reacterable_model(): void
}

/** @test */
public function it_can_create_migration_for_reacterable_model_with_nullable_column(): void
public function it_can_create_migration_for_reacterable_model_with_not_nullable_column(): void
{
$status = $this->artisan('love:setup-reacterable', [
'--model' => Person::class,
'--nullable' => true,
'--not-nullable' => true,
]);

$this->assertSame(0, $status);
Expand Down