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

Fixed one migration problem and null level handling in getLevel() & getPoints(), causing some error #59

Merged
merged 14 commits into from
Mar 1, 2024

Conversation

joydeep-bhowmik
Copy link
Contributor

@joydeep-bhowmik joydeep-bhowmik commented Feb 13, 2024

Description

1st Issue

When there is no experience record yet and getPoints() is executed, it returns the following error message:

App\Models\User::getPoints(): Return value must be of type int, null returned.

This issue was addressed by modifying two functions as follows:

//src/Concerns/GiveExperience.php
public function getLevel(): int
{
    return $this->experience->status->level ?? 0;
}

public function getPoints(): int
{
    return $this->experience->experience_points ?? 0;
}

2nd Issue

During migration, the following SQL error was encountered:

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'ended_at' (Connection: mysql, SQL: 
create table `streak_histories` (`id` bigint unsigned not null auto_increment primary key, `user_id` bigint unsigned not 
null, `activity_id` bigint unsigned not null, `count` int not null default '1', `started_at` timestamp not null, `ended_at` 
timestamp not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 
'utf8mb4_unicode_ci')

This issue was resolved by adding a nullable constraint to the ended_at column in the migration script:

//database/migrations/create_streak_histories_table.php.stub
Schema::create('streak_histories', function (Blueprint $table) {
    $table->id();
    $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
    $table->foreignId('activity_id')->constrained('streak_activities');
    $table->integer('count')->default(1);
    $table->timestamp('started_at');
    $table->timestamp('ended_at')->nullable(); // Nullable constraint added
    $table->timestamps();
});

Type of Change

  • Bug fix

Related Issues


The $table->timestamp(column: 'ended_at') shouldbe 
$table->timestamp(column: 'ended_at')->nullable()
…tLevel() & getPoints(),


public function getPoints(): int
    {
        return $this->experience->experience_points ;
    } 
  public function getLevel(): int
    {
        return $this->experience->status->level ;
    } 

to

public function getPoints(): int
    {
        return $this->experience->experience_points ?? 0;
    } 
  public function getLevel(): int
    {
        return $this->experience->status->level ?? 0;
    }
@cjmellor
Copy link
Owner

Thanks for the PR @joydeep-bhowmik

Could you write a test for point 1, just to make sure it is doing what it is supposed to do?

And the Linter is failing on GA, so can you make sure pint is ran on the code?

Thanks.

@joydeep-bhowmik
Copy link
Contributor Author

Thanks for the PR @joydeep-bhowmik

Could you write a test for point 1, just to make sure it is doing what it is supposed to do?

And the Linter is failing on GA, so can you make sure pint is ran on the code?

Thanks.

I will add it as soon as possible ... too much work load this week :(

@cjmellor cjmellor added the bug Something isn't working label Feb 19, 2024
@cjmellor cjmellor linked an issue Feb 19, 2024 that may be closed by this pull request
@cjmellor
Copy link
Owner

Warning

This will need an update in the UPGRADE.md explaining that a new Migration needs creating to make the ended_at column nullable.

@joydeep-bhowmik
Copy link
Contributor Author

joydeep-bhowmik commented Mar 1, 2024

unable to pass Linter test * [new branch] main -> origin/main error: Your local changes to the following files would be overwritten by checkout: src/Concerns/GiveExperience.php Please commit your changes or stash them before you switch branches.
i'

@cjmellor
Copy link
Owner

cjmellor commented Mar 1, 2024

Yeah don't worry about it, I dunno what is up with it

The code in `GiveExperience.php` has been refactored for improved readability and consistency. In particular, changes were made to the syntax of `if` statements and the space around the NOT operator was adjusted. The `UPGRADE.md` documentation was also updated, with versions and migration details rearranged for clearer understanding.
@cjmellor cjmellor merged commit 8887e95 into cjmellor:main Mar 1, 2024
13 of 14 checks passed
@cjmellor
Copy link
Owner

cjmellor commented Mar 1, 2024

Thanks for the work on this @joydeep-bhowmik. Appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]:
2 participants