Skip to content

Commit

Permalink
Merge pull request #253 from pacoorozco/consolidate-database-migrations
Browse files Browse the repository at this point in the history
Release version 3.0
  • Loading branch information
pacoorozco authored Jun 21, 2022
2 parents c5e2a54 + 249b5e8 commit edd47ae
Show file tree
Hide file tree
Showing 32 changed files with 211 additions and 725 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/) and this

## Unreleased

## 3.0.0 - 2022-06-21

> NOTE: This release has **non-backwards compatible** changes.
### Added
- Improved form validation to make user's input safer. Test has been increased to ensure proper validation.
- Added a `Default` level outside the database. It could be overridden by creating a new level with `required_points = 0`

### Changed
- **Important**: This application has been upgraded to [Laravel 9.x](https://laravel.com/docs). A lot of refactors has been done in order to adopt Laravel 9.x best practices.
- **Important**: Database schema has been modified in a **non-backwards compatible way**.

### Fixed
- Broken image urls for levels.
- `- OR -` statement in the login form should not appear when social login is not enabled.

## 2.7.3 - 2022-04-06

### Changed
Expand Down
2 changes: 1 addition & 1 deletion app/Libs/Game/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function unlockBadgeFor(User $user, Badge $badge): void

$data = [
'repetitions' => $badge->required_repetitions,
'completed_on' => now(),
'unlocked_at' => now(),
];

try {
Expand Down
17 changes: 3 additions & 14 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,36 +156,25 @@ public function answeredQuestions(): BelongsToMany
public function getCompletedBadges(): Collection
{
return $this->badges()
->wherePivot('completed', true)
->wherePivotNotNull('unlocked_at')
->get();
}

/**
* These are the User's Badges relationship.
*
* It uses a pivot table with these values:
*
* amount: int - how many actions has completed
* completed: bool - true if User's has own this badge
* completed_on: Datetime - where it was completed
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function badges(): BelongsToMany
{
return $this->belongsToMany(
Badge::class,
'users_badges',
'user_id',
'badge_id')
->withPivot('repetitions', 'completed', 'completed_on');
->withPivot('repetitions', 'unlocked_at');
}

public function isBadgeUnlocked(Badge $badge): bool
{
return $this->badges()
->wherePivot('badge_id', $badge->id)
->wherePivotNotNull('completed_on')
->wherePivotNotNull('unlocked_at')
->exists();
}

Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
|
*/

'version' => '2.7.3',
'version' => '3.0.0',

/*
|--------------------------------------------------------------------------
Expand Down
39 changes: 27 additions & 12 deletions config/taggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,44 @@

return [

/*
/**
* List of characters that can delimit the tags passed to the
* tag() / untag() / etc. functions.
*/
'delimiters' => ',;',
'delimiters' => ',;',

/*
/**
* Character used to delimit tag lists returned in the
* tagList, tagListNormalized, etc. attributes.
*/
'glue' => ',',
'glue' => ',',

/*
/**
* Method used to "normalize" tag names. Can either be a global function name,
* a closure function, or a callable, e.g. ['Classname', 'method'].
*/
'normalizer' => 'mb_strtolower',
'normalizer' => 'mb_strtolower',

/*
/**
* The database connection to use for the Tag model and associated tables.
* By default, we use the default database connection, but this can be defined
* so that all the tag-related tables are stored in a different connection.
*/
'connection' => null,
'connection' => null,

/*
/**
* How to handle passing empty values to the scope queries. When set to false,
* the scope queries will return no models. When set to true, passing an empty
* value to the scope queries will throw an exception instead.
*/
'throwEmptyExceptions' => false,

/*
/**
* If you want to be able to find all the models that share a tag, you will need
* to define the inverse relations here. The array keys are the relation names
* you would use to access them (e.g. "posts") and the values are the qualified
* class names of the models that are taggable (e.g. "\App\Post). e.g. with
* the following configuration:
* the following configuration:.
*
* 'taggedModels' => [
* 'posts' => \App\Post::class
Expand All @@ -74,6 +74,21 @@
*
* to get a collection of all the Posts that are tagged "Apple".
*/

'taggedModels' => [],

/**
* The model used to store the tags in the database. You can
* create your own class that extends the package's Tag model,
* then update the configuration below.
*/
'model' => \Cviebrock\EloquentTaggable\Models\Tag::class,

/**
* The tables used to store the tags in the database. You can
* publish the package's migrations and use custom names.
*/
'tables' => [
'taggable_tags' => 'taggable_tags',
'taggable_taggables' => 'taggable_taggables',
],
];
22 changes: 8 additions & 14 deletions database/migrations/2014_10_12_000000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,31 @@
* @link https://github.com/pacoorozco/gamify-laravel
*/

use Gamify\Enums\Roles;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->id();
$table->string('name');
$table->string('username')->unique();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('role')->default(Roles::Player);
$table->unsignedInteger('experience')->default(0);
$table->rememberToken();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,9 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePasswordResetsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
Expand All @@ -43,13 +38,8 @@ public function up()
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('password_resets');
}
}
};
56 changes: 0 additions & 56 deletions database/migrations/2015_12_10_092156_add_role_to_users_table.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,31 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUserProfilesTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('user_profiles', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id')->unique();
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');

$table->id();
$table->foreignId('user_id')
->constrained()
->cascadeOnDelete();
$table->text('bio')->nullable();
$table->string('url')->nullable();
$table->string('avatar')->nullable();
$table->string('phone')->nullable();
$table->date('date_of_birth')->nullable();
$table->enum('gender', ['male', 'female', 'unspecified'])->default('unspecified');

$table->string('twitter')->nullable();
$table->string('facebook')->nullable();
$table->string('linkedin')->nullable();
$table->string('github')->nullable();

$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::drop('user_profiles');
}
}
};
26 changes: 8 additions & 18 deletions database/migrations/2015_12_10_143825_create_points_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,24 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePointsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('points', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->foreign('user_id')
->references('id')->on('users');
$table->id();
$table->foreignId('user_id')
->constrained()
->cascadeOnDelete();
$table->unsignedInteger('points');
$table->string('description');
$table->index('user_id');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::drop('points');
}
}
};
Loading

0 comments on commit edd47ae

Please sign in to comment.