first commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateWebSocketsStatisticsEntriesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('websockets_statistics_entries', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('app_id');
|
||||
$table->integer('peak_connection_count');
|
||||
$table->integer('websocket_message_count');
|
||||
$table->integer('api_message_count');
|
||||
$table->nullableTimestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('websockets_statistics_entries');
|
||||
}
|
||||
}
|
||||
55
database/migrations/2014_10_12_000000_create_users_table.php
Normal file
55
database/migrations/2014_10_12_000000_create_users_table.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('full_name');
|
||||
$table->string('first_name');
|
||||
$table->string('last_name');
|
||||
$table->string('email', 100)->unique();
|
||||
$table->string('url');
|
||||
$table->integer('company_id');
|
||||
$table->string('level');
|
||||
$table->integer('payroll_access');
|
||||
$table->integer('billing_access');
|
||||
$table->string('avatar');
|
||||
$table->integer('screenshots_active');
|
||||
$table->integer('manual_time');
|
||||
$table->integer('permanent_tasks');
|
||||
$table->integer('computer_time_popup');
|
||||
$table->string('poor_time_popup');
|
||||
$table->integer('blur_screenshots');
|
||||
$table->integer('web_and_app_monitoring');
|
||||
$table->integer('webcam_shots');
|
||||
$table->integer('screenshots_interval');
|
||||
$table->string('user_role_value');
|
||||
$table->string('active');
|
||||
$table->string('password');
|
||||
$table->softDeletes();
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreatePasswordResetsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('password_resets', function (Blueprint $table) {
|
||||
$table->string('email', 100)->index();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('password_resets');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateProjectsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('projects', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('company_id');
|
||||
$table->string('name');
|
||||
$table->text('description');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('projects');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateProjectsUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('projects_users', function (Blueprint $table) {
|
||||
$table->integer('project_id')->unsigned();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('role');
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
$table->foreign('project_id')->references('id')->on('projects');
|
||||
|
||||
$table->primary(['project_id', 'user_id'], 'projects_users_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('projects_users');
|
||||
}
|
||||
}
|
||||
41
database/migrations/2018_02_26_111407_create_tasks_table.php
Normal file
41
database/migrations/2018_02_26_111407_create_tasks_table.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateTasksTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('tasks', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('project_id')->unsigned();
|
||||
$table->string('task_name');
|
||||
$table->text('description');
|
||||
$table->boolean('active');
|
||||
$table->integer('user_id');
|
||||
$table->integer('assigned_by');
|
||||
$table->string('url', 500)->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->foreign('project_id')->references('id')->on('projects');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('tasks');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateTimeIntervalsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('time_intervals', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('task_id')->unsigned();
|
||||
$table->dateTime('start_at');
|
||||
$table->dateTime('end_at');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->foreign('task_id')->references('id')->on('tasks');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('time_intervals');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateScreenshotsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('screenshots', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('time_interval_id')->unsigned();
|
||||
$table->string('path');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->foreign('time_interval_id')->references('id')->on('time_intervals');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('screenshots');
|
||||
}
|
||||
}
|
||||
59
database/migrations/2018_03_07_141643_create_roles.php
Normal file
59
database/migrations/2018_03_07_141643_create_roles.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use App\Models\Role;
|
||||
use App\Models\Rule;
|
||||
|
||||
class CreateRoles extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('role', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name', 255);
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->unsignedInteger('role_id');
|
||||
$table->foreign('role_id')->references('id')->on('role');
|
||||
});
|
||||
|
||||
|
||||
Schema::create('rule', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('role_id');
|
||||
$table->string('object', 50);
|
||||
$table->string('action', 50);
|
||||
$table->boolean('allow')->default(false);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['role_id', 'object', 'action']);
|
||||
$table->foreign('role_id')->references('id')->on('role')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropForeign('users_role_id_foreign');
|
||||
$table->dropColumn('role_id');
|
||||
});
|
||||
|
||||
Schema::dropIfExists('rule');
|
||||
Schema::dropIfExists('role');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreatePropertiesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('properties', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('entity_id');
|
||||
$table->string('entity_type', 15);
|
||||
$table->string('name', 150);
|
||||
$table->text('value');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->unique(['entity_id', 'entity_type', 'name']);
|
||||
$table->index(['entity_id', 'entity_type'], 'properties_index');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('properties', function (Blueprint $table) {
|
||||
$table->dropIndex('properties_index');
|
||||
});
|
||||
|
||||
Schema::dropIfExists('properties');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddMouseAndKeyboardCountersToTimeInterval extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('time_intervals', function (Blueprint $table) {
|
||||
$table->integer('count_mouse');
|
||||
$table->integer('count_keyboard');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('time_intervals', function(Blueprint $table) {
|
||||
$table->dropColumn('count_mouse');
|
||||
$table->dropColumn('count_keyboard');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddUserIdToTimeInterval extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('time_intervals', function (Blueprint $table) {
|
||||
$table->integer('user_id')->unsigned();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('time_intervals', function (Blueprint $table) {
|
||||
$table->dropForeign(['user_id']);
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class ModifireColumnsUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('first_name')->nullable()->change();
|
||||
$table->string('last_name')->nullable()->change();
|
||||
$table->string('url')->nullable()->change();
|
||||
$table->integer('company_id')->nullable()->change();
|
||||
$table->string('level')->nullable()->change();
|
||||
$table->integer('payroll_access')->nullable()->change();
|
||||
$table->integer('billing_access')->nullable()->change();
|
||||
$table->string('avatar')->nullable()->change();
|
||||
$table->integer('screenshots_active')->nullable()->change();
|
||||
$table->integer('manual_time')->nullable()->change();
|
||||
$table->integer('permanent_tasks')->nullable()->change();
|
||||
$table->integer('computer_time_popup')->nullable()->change();
|
||||
$table->string('poor_time_popup')->nullable()->change();
|
||||
$table->integer('blur_screenshots')->nullable()->change();
|
||||
$table->integer('web_and_app_monitoring')->nullable()->change();
|
||||
$table->integer('webcam_shots')->nullable()->change();
|
||||
$table->integer('screenshots_interval')->nullable()->change();
|
||||
$table->string('user_role_value')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('first_name')->change();
|
||||
$table->string('last_name')->change();
|
||||
$table->string('url')->change();
|
||||
$table->integer('company_id')->change();
|
||||
$table->string('level')->change();
|
||||
$table->integer('payroll_access')->change();
|
||||
$table->integer('billing_access')->change();
|
||||
$table->string('avatar')->change();
|
||||
$table->integer('screenshots_active')->change();
|
||||
$table->integer('manual_time')->change();
|
||||
$table->integer('permanent_tasks')->change();
|
||||
$table->integer('computer_time_popup')->change();
|
||||
$table->string('poor_time_popup')->change();
|
||||
$table->integer('blur_screenshots')->change();
|
||||
$table->integer('web_and_app_monitoring')->change();
|
||||
$table->integer('webcam_shots')->change();
|
||||
$table->integer('screenshots_interval')->change();
|
||||
$table->string('user_role_value')->change();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateRelationsUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('relations_users', function (Blueprint $table) {
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->integer('attached_user_id')->unsigned();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
$table->foreign('attached_user_id')->references('id')->on('users');
|
||||
|
||||
$table->primary(['user_id', 'attached_user_id'], 'user_attached_user_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('relations_users');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class DropColumnRoleProjectsUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('projects_users', function (Blueprint $table) {
|
||||
$table->dropColumn('role');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('projects_users', function (Blueprint $table) {
|
||||
$table->string('role');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddDeletedAtColumnToRuleTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('rule', function (Blueprint $table) {
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('rule', function (Blueprint $table) {
|
||||
$table->dropColumn('deleted_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class ChangeCompanyIdColumnProjectsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('projects', function (Blueprint $table) {
|
||||
$table->integer('company_id')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('projects', function (Blueprint $table) {
|
||||
$table->integer('company_id')->change();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddTimezoneColumnToUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('timezone')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('timezone');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateProjectsRolesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('projects_roles', function (Blueprint $table) {
|
||||
$table->integer('project_id')->unsigned();
|
||||
$table->integer('role_id')->unsigned();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('role_id')->references('id')->on('role');
|
||||
$table->foreign('project_id')->references('id')->on('projects');
|
||||
|
||||
$table->primary(['project_id', 'role_id'], 'projects_roles_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('projects_roles');
|
||||
}
|
||||
}
|
||||
164
database/migrations/2018_09_11_100952_add_index.php
Normal file
164
database/migrations/2018_09_11_100952_add_index.php
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddIndex extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('time_intervals', function (Blueprint $table) {
|
||||
$table->index('start_at');
|
||||
$table->index('end_at');
|
||||
$table->index(['end_at', 'start_at']);
|
||||
});
|
||||
|
||||
DB::unprepared('CREATE OR REPLACE VIEW `time_durations` AS SELECT DATE(`start_at`) AS `date`, SUM(TIME_TO_SEC(TIMEDIFF(`end_at`, `start_at`))) AS `duration`, `user_id` FROM `time_intervals` GROUP BY `date`,`user_id` ');
|
||||
|
||||
|
||||
|
||||
Schema::create('time_durations_cache', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->date('date');
|
||||
$table->integer('duration')->unsigned();
|
||||
$table->integer('user_id')->unsigned();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
});
|
||||
|
||||
|
||||
DB::unprepared('CREATE TRIGGER `time_durations_cache_insert_trigger` AFTER INSERT ON `time_intervals`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE `interval` INT UNSIGNED;
|
||||
DECLARE `current_date` DATE;
|
||||
SET
|
||||
`interval` = TIME_TO_SEC(TIMEDIFF(NEW.`end_at`, NEW.`start_at`)),
|
||||
`current_date` = DATE(NEW.`start_at`);
|
||||
|
||||
IF (
|
||||
SELECT 1
|
||||
FROM `time_durations_cache`
|
||||
WHERE
|
||||
`time_durations_cache`.`date` = `current_date`
|
||||
AND
|
||||
`time_durations_cache`.`user_id` = NEW.`user_id`
|
||||
) = 1
|
||||
THEN
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` + `interval`
|
||||
WHERE `date` = `current_date`;
|
||||
ELSE
|
||||
INSERT INTO `time_durations_cache` (`date`, `duration`, `user_id`)
|
||||
VALUES (`current_date`, `interval`, NEW.`user_id`);
|
||||
END IF;
|
||||
END'
|
||||
);
|
||||
|
||||
|
||||
DB::unprepared('CREATE TRIGGER `time_durations_cache_update_trigger` AFTER UPDATE ON `time_intervals`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE `new_interval` INT UNSIGNED;
|
||||
DECLARE `old_interval` INT UNSIGNED;
|
||||
DECLARE `old_date` DATE;
|
||||
DECLARE `new_date` DATE;
|
||||
SET
|
||||
`new_interval` = TIME_TO_SEC(TIMEDIFF(NEW.`end_at`, NEW.`start_at`)),
|
||||
`old_interval` = TIME_TO_SEC(TIMEDIFF(OLD.`end_at`, OLD.`start_at`)),
|
||||
`new_date` = DATE(NEW.`start_at`),
|
||||
`old_date` = DATE(OLD.`start_at`);
|
||||
|
||||
UPDATE `time_durations_cache`
|
||||
SET
|
||||
`duration` = `duration` - `old_interval`
|
||||
WHERE
|
||||
`date` = `old_date`
|
||||
AND
|
||||
`user_id` = OLD.`user_id`;
|
||||
|
||||
|
||||
IF (
|
||||
SELECT 1
|
||||
FROM `time_durations_cache`
|
||||
WHERE
|
||||
`time_durations_cache`.`date` = `new_date`
|
||||
AND
|
||||
`time_durations_cache`.`user_id` = NEW.`user_id`
|
||||
) = 1
|
||||
THEN
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` + `new_interval`
|
||||
WHERE
|
||||
`date` = `new_date`
|
||||
AND
|
||||
`time_durations_cache`.`user_id` = NEW.`user_id`;
|
||||
ELSE
|
||||
INSERT INTO `time_durations_cache` (`date`, `duration`, `user_id`)
|
||||
VALUES (`new_date`, `new_interval`, NEW.`user_id`);
|
||||
END IF;
|
||||
END'
|
||||
);
|
||||
|
||||
|
||||
DB::unprepared('CREATE TRIGGER `time_durations_cache_delete_trigger` AFTER DELETE ON `time_intervals`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE `interval` INT UNSIGNED;
|
||||
DECLARE `current_date` DATE;
|
||||
SET
|
||||
`interval` = TIME_TO_SEC(TIMEDIFF(OLD.`end_at`, OLD.`start_at`)),
|
||||
`current_date` = DATE(OLD.`start_at`);
|
||||
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` - `interval`
|
||||
WHERE `date` = `current_date`;
|
||||
END'
|
||||
);
|
||||
|
||||
|
||||
DB::unprepared('DROP PROCEDURE IF EXISTS `time_durations_cache_refresh`;');
|
||||
DB::unprepared('CREATE PROCEDURE `time_durations_cache_refresh` ()
|
||||
BEGIN
|
||||
DELETE FROM `time_durations_cache`;
|
||||
|
||||
INSERT INTO `time_durations_cache` (`date`, `duration`, `user_id`)
|
||||
SELECT
|
||||
`time_durations`.`date`,
|
||||
`time_durations`.`duration`,
|
||||
`time_durations`.`user_id`
|
||||
FROM `time_durations`;
|
||||
|
||||
END
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
DB::unprepared( 'DROP TRIGGER IF EXISTS `time_durations_cache_insert_trigger`' );
|
||||
DB::unprepared( 'DROP TRIGGER IF EXISTS `time_durations_cache_update_trigger`' );
|
||||
DB::unprepared( 'DROP TRIGGER IF EXISTS `time_durations_cache_delete_trigger`' );
|
||||
DB::unprepared( 'DROP PROCEDURE IF EXISTS `time_durations_cache_refresh`' );
|
||||
|
||||
Schema::dropIfExists('time_durations_cache');
|
||||
|
||||
DB::unprepared( 'DROP VIEW IF EXISTS `time_durations`' );
|
||||
|
||||
Schema::table('time_intervals', function (Blueprint $table) {
|
||||
$table->dropIndex('time_intervals_start_at_index');
|
||||
$table->dropIndex('time_intervals_end_at_index');
|
||||
$table->dropIndex('time_intervals_end_at_start_at_index');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddThumbnailPathToScreenshotsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('screenshots', function (Blueprint $table) {
|
||||
$table->string('thumbnail_path')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('screenshots', function (Blueprint $table) {
|
||||
$table->dropColumn('thumbnail_path');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ConvertUserActiveToBoolean extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::table('users')
|
||||
->where('active', 'active')
|
||||
->update(['active' => true]);
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->boolean('active')->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('active')->change();
|
||||
});
|
||||
}
|
||||
}
|
||||
88
database/migrations/2018_09_27_100017_update_rules.php
Normal file
88
database/migrations/2018_09_27_100017_update_rules.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use App\Models\Role;
|
||||
use App\Models\Rule;
|
||||
|
||||
class UpdateRules extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$user_role_id = 2;
|
||||
$manager_role_id = 5;
|
||||
$blocked_role_id = 255;
|
||||
|
||||
$role_ids = Role::where('id', '<>', $blocked_role_id)
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
|
||||
if (in_array($user_role_id, $role_ids)) {
|
||||
// Allows users to edit time intervals.
|
||||
// (Needed to change tasks on programmer's dashboard.)
|
||||
Rule::updateOrCreate([
|
||||
'role_id' => $user_role_id,
|
||||
'object' => 'time-intervals',
|
||||
'action' => 'edit',
|
||||
], [
|
||||
'allow' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
if (in_array($manager_role_id, $role_ids)) {
|
||||
// Allows manager access to the dashboard,
|
||||
// project report, screenshots, time intervals.
|
||||
$new_manager_rules = [
|
||||
['dashboard', 'manager_access'],
|
||||
['project-report', 'manager_access'],
|
||||
['screenshots', 'manager_access'],
|
||||
['time-intervals', 'manager_access'],
|
||||
];
|
||||
foreach ($new_manager_rules as $rule) {
|
||||
[$object, $action] = $rule;
|
||||
Rule::updateOrCreate([
|
||||
'role_id' => $manager_role_id,
|
||||
'object' => $object,
|
||||
'action' => $action,
|
||||
], [
|
||||
'allow' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Allows all roles to show time use report and time duration.
|
||||
$new_rules = [
|
||||
['time-use-report', 'list'],
|
||||
['time-duration', 'list'],
|
||||
];
|
||||
foreach ($role_ids as $role_id) {
|
||||
foreach ($new_rules as $rule) {
|
||||
[$object, $action] = $rule;
|
||||
Rule::updateOrCreate([
|
||||
'role_id' => $role_id,
|
||||
'object' => $object,
|
||||
'action' => $action,
|
||||
], [
|
||||
'allow' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddProjectReportView extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::unprepared('
|
||||
CREATE OR REPLACE VIEW `project_report` AS
|
||||
SELECT
|
||||
`time_intervals`.`user_id` as `user_id`,
|
||||
`users`.`full_name` as `user_name`,
|
||||
`time_intervals`.`task_id` as `task_id`,
|
||||
`tasks`.`project_id` as `project_id`,
|
||||
`tasks`.`task_name` as `task_name`,
|
||||
`projects`.`name` as `project_name`,
|
||||
DATE(`time_intervals`.`start_at`) as `date`,
|
||||
SUM(TIME_TO_SEC(TIMEDIFF(`time_intervals`.`end_at`, `time_intervals`.`start_at`))) AS `duration`
|
||||
FROM
|
||||
`time_intervals`
|
||||
INNER JOIN
|
||||
`tasks`
|
||||
ON
|
||||
`tasks`.`id` = `time_intervals`.`task_id`
|
||||
INNER JOIN
|
||||
`projects`
|
||||
ON
|
||||
`tasks`.`project_id` = `projects`.`id`
|
||||
INNER JOIN
|
||||
`users`
|
||||
ON
|
||||
`users`.`id` = `time_intervals`.`user_id`
|
||||
GROUP BY
|
||||
`date`,
|
||||
`user_id`,
|
||||
`user_name`,
|
||||
`task_id`,
|
||||
`task_name`,
|
||||
`project_id`,
|
||||
`project_name`
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
DB::unprepared('DROP VIEW IF EXISTS `project_report`');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class FixTimeDurationsCache extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Adds soft-delete handling.
|
||||
// Fixes error with an update affects time durations of all users.
|
||||
|
||||
DB::unprepared('DROP TRIGGER IF EXISTS `time_durations_cache_insert_trigger`');
|
||||
DB::unprepared('DROP TRIGGER IF EXISTS `time_durations_cache_update_trigger`');
|
||||
DB::unprepared('DROP TRIGGER IF EXISTS `time_durations_cache_delete_trigger`');
|
||||
DB::unprepared('DROP VIEW IF EXISTS `time_durations`');
|
||||
|
||||
DB::unprepared('CREATE VIEW `time_durations` AS
|
||||
SELECT
|
||||
DATE(`start_at`) AS `date`,
|
||||
SUM(TIME_TO_SEC(TIMEDIFF(`end_at`, `start_at`))) AS `duration`,
|
||||
`user_id`
|
||||
FROM `time_intervals`
|
||||
WHERE `deleted_at` IS NULL
|
||||
GROUP BY
|
||||
`date`,
|
||||
`user_id`');
|
||||
|
||||
DB::unprepared('CREATE TRIGGER `time_durations_cache_insert_trigger` AFTER INSERT ON `time_intervals`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE `interval` INT UNSIGNED;
|
||||
DECLARE `current_date` DATE;
|
||||
SET
|
||||
`interval` = TIME_TO_SEC(TIMEDIFF(NEW.`end_at`, NEW.`start_at`)),
|
||||
`current_date` = DATE(NEW.`start_at`);
|
||||
|
||||
IF NEW.`deleted_at` IS NULL THEN
|
||||
IF (SELECT 1
|
||||
FROM `time_durations_cache`
|
||||
WHERE `time_durations_cache`.`date` = `current_date`
|
||||
AND `time_durations_cache`.`user_id` = NEW.`user_id`
|
||||
) = 1
|
||||
THEN
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` + `interval`
|
||||
WHERE `time_durations_cache`.`date` = `current_date`
|
||||
AND `time_durations_cache`.`user_id` = NEW.`user_id`;
|
||||
ELSE
|
||||
INSERT INTO `time_durations_cache` (`date`, `duration`, `user_id`)
|
||||
VALUES (`current_date`, `interval`, NEW.`user_id`);
|
||||
END IF;
|
||||
END IF;
|
||||
END');
|
||||
|
||||
DB::unprepared('CREATE TRIGGER `time_durations_cache_update_trigger` AFTER UPDATE ON `time_intervals`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE `new_interval` INT UNSIGNED;
|
||||
DECLARE `old_interval` INT UNSIGNED;
|
||||
DECLARE `new_date` DATE;
|
||||
DECLARE `old_date` DATE;
|
||||
SET
|
||||
`new_interval` = TIME_TO_SEC(TIMEDIFF(NEW.`end_at`, NEW.`start_at`)),
|
||||
`old_interval` = TIME_TO_SEC(TIMEDIFF(OLD.`end_at`, OLD.`start_at`)),
|
||||
`new_date` = DATE(NEW.`start_at`),
|
||||
`old_date` = DATE(OLD.`start_at`);
|
||||
|
||||
IF OLD.`deleted_at` IS NULL THEN
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` - `old_interval`
|
||||
WHERE `date` = `old_date`
|
||||
AND `user_id` = OLD.`user_id`;
|
||||
END IF;
|
||||
|
||||
IF NEW.`deleted_at` IS NULL THEN
|
||||
IF (SELECT 1
|
||||
FROM `time_durations_cache`
|
||||
WHERE `time_durations_cache`.`date` = `new_date`
|
||||
AND `time_durations_cache`.`user_id` = NEW.`user_id`
|
||||
) = 1
|
||||
THEN
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` + `new_interval`
|
||||
WHERE `date` = `new_date`
|
||||
AND `time_durations_cache`.`user_id` = NEW.`user_id`;
|
||||
ELSE
|
||||
INSERT INTO `time_durations_cache` (`date`, `duration`, `user_id`)
|
||||
VALUES (`new_date`, `new_interval`, NEW.`user_id`);
|
||||
END IF;
|
||||
END IF;
|
||||
END');
|
||||
|
||||
DB::unprepared('CREATE TRIGGER `time_durations_cache_delete_trigger` AFTER DELETE ON `time_intervals`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE `interval` INT UNSIGNED;
|
||||
DECLARE `current_date` DATE;
|
||||
SET
|
||||
`interval` = TIME_TO_SEC(TIMEDIFF(OLD.`end_at`, OLD.`start_at`)),
|
||||
`current_date` = DATE(OLD.`start_at`);
|
||||
|
||||
IF OLD.`deleted_at` IS NULL THEN
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` - `interval`
|
||||
WHERE `time_durations_cache`.`date` = `current_date`
|
||||
AND `time_durations_cache`.`user_id` = OLD.`user_id`;
|
||||
END IF;
|
||||
END');
|
||||
|
||||
//DB::unprepared('CALL time_durations_cache_refresh()');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// Restores old view and triggers.
|
||||
// Copied from the 2018_09_11_100952_add_index.php
|
||||
|
||||
DB::unprepared('DROP TRIGGER IF EXISTS `time_durations_cache_insert_trigger`');
|
||||
DB::unprepared('DROP TRIGGER IF EXISTS `time_durations_cache_update_trigger`');
|
||||
DB::unprepared('DROP TRIGGER IF EXISTS `time_durations_cache_delete_trigger`');
|
||||
DB::unprepared('DROP VIEW IF EXISTS `time_durations`');
|
||||
|
||||
DB::unprepared('CREATE VIEW `time_durations` AS SELECT DATE(`start_at`) AS `date`, SUM(TIME_TO_SEC(TIMEDIFF(`end_at`, `start_at`))) AS `duration`, `user_id` FROM `time_intervals` GROUP BY `date`,`user_id` ');
|
||||
|
||||
DB::unprepared('CREATE TRIGGER `time_durations_cache_insert_trigger` AFTER INSERT ON `time_intervals`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE `interval` INT UNSIGNED;
|
||||
DECLARE `current_date` DATE;
|
||||
SET
|
||||
`interval` = TIME_TO_SEC(TIMEDIFF(NEW.`end_at`, NEW.`start_at`)),
|
||||
`current_date` = DATE(NEW.`start_at`);
|
||||
|
||||
IF (
|
||||
SELECT 1
|
||||
FROM `time_durations_cache`
|
||||
WHERE
|
||||
`time_durations_cache`.`date` = `current_date`
|
||||
AND
|
||||
`time_durations_cache`.`user_id` = NEW.`user_id`
|
||||
) = 1
|
||||
THEN
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` + `interval`
|
||||
WHERE `date` = `current_date`;
|
||||
ELSE
|
||||
INSERT INTO `time_durations_cache` (`date`, `duration`, `user_id`)
|
||||
VALUES (`current_date`, `interval`, NEW.`user_id`);
|
||||
END IF;
|
||||
END');
|
||||
|
||||
DB::unprepared('CREATE TRIGGER `time_durations_cache_update_trigger` AFTER UPDATE ON `time_intervals`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE `new_interval` INT UNSIGNED;
|
||||
DECLARE `old_interval` INT UNSIGNED;
|
||||
DECLARE `old_date` DATE;
|
||||
DECLARE `new_date` DATE;
|
||||
SET
|
||||
`new_interval` = TIME_TO_SEC(TIMEDIFF(NEW.`end_at`, NEW.`start_at`)),
|
||||
`old_interval` = TIME_TO_SEC(TIMEDIFF(OLD.`end_at`, OLD.`start_at`)),
|
||||
`new_date` = DATE(NEW.`start_at`),
|
||||
`old_date` = DATE(OLD.`start_at`);
|
||||
|
||||
UPDATE `time_durations_cache`
|
||||
SET
|
||||
`duration` = `duration` - `old_interval`
|
||||
WHERE
|
||||
`date` = `old_date`
|
||||
AND
|
||||
`user_id` = OLD.`user_id`;
|
||||
|
||||
|
||||
IF (
|
||||
SELECT 1
|
||||
FROM `time_durations_cache`
|
||||
WHERE
|
||||
`time_durations_cache`.`date` = `new_date`
|
||||
AND
|
||||
`time_durations_cache`.`user_id` = NEW.`user_id`
|
||||
) = 1
|
||||
THEN
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` + `new_interval`
|
||||
WHERE
|
||||
`date` = `new_date`
|
||||
AND
|
||||
`time_durations_cache`.`user_id` = NEW.`user_id`;
|
||||
ELSE
|
||||
INSERT INTO `time_durations_cache` (`date`, `duration`, `user_id`)
|
||||
VALUES (`new_date`, `new_interval`, NEW.`user_id`);
|
||||
END IF;
|
||||
END');
|
||||
|
||||
DB::unprepared('CREATE TRIGGER `time_durations_cache_delete_trigger` AFTER DELETE ON `time_intervals`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE `interval` INT UNSIGNED;
|
||||
DECLARE `current_date` DATE;
|
||||
SET
|
||||
`interval` = TIME_TO_SEC(TIMEDIFF(OLD.`end_at`, OLD.`start_at`)),
|
||||
`current_date` = DATE(OLD.`start_at`);
|
||||
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` - `interval`
|
||||
WHERE `date` = `current_date`;
|
||||
END');
|
||||
|
||||
//DB::unprepared('CALL time_durations_cache_refresh()');
|
||||
}
|
||||
}
|
||||
34
database/migrations/2018_10_08_072020_add_task_priority.php
Normal file
34
database/migrations/2018_10_08_072020_add_task_priority.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddTaskPriority extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->string('priority');
|
||||
$table->integer('priority_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->dropColumn('priority');
|
||||
$table->dropColumn('priority_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreatePrioritiesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Remove priority column from the tasks table.
|
||||
if (Schema::hasTable('tasks')
|
||||
&& Schema::hasColumn('tasks', 'priority')) {
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->dropColumn('priority');
|
||||
});
|
||||
}
|
||||
|
||||
// Add priorities table.
|
||||
if (!Schema::hasTable('priorities')) {
|
||||
Schema::create('priorities', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// Add priority column to the tasks table.
|
||||
if (Schema::hasTable('tasks')
|
||||
&& !Schema::hasColumn('tasks', 'priority')) {
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->string('priority');
|
||||
});
|
||||
}
|
||||
|
||||
// Remove priorities table.
|
||||
Schema::dropIfExists('priorities');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateTokensTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!Schema::hasTable('tokens')) {
|
||||
Schema::create('tokens', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('user_id');
|
||||
$table->string('token', 512);
|
||||
$table->dateTime('expires_at');
|
||||
|
||||
//$table->primary(['user_id', 'token']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('tokens');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class RemoveTokensCompositeKey extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('tokens', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('tokens', 'id')) {
|
||||
$table->dropPrimary();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddTokensAutoincrementKey extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('tokens', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('tokens', 'id')) {
|
||||
$table->increments('id');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\Rule;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateRegistrationsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!Schema::hasTable('registrations')) {
|
||||
Schema::create('registrations', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->uuid('key')->unique();
|
||||
$table->string('email');
|
||||
$table->dateTime('expires_at');
|
||||
});
|
||||
}
|
||||
|
||||
// Allow root to register users.
|
||||
$root_role_id = 1;
|
||||
$blocked_role_id = 255;
|
||||
$role_ids = Role::where('id', '<>', $blocked_role_id)
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
if (in_array($root_role_id, $role_ids)) {
|
||||
Rule::updateOrCreate([
|
||||
'role_id' => $root_role_id,
|
||||
'object' => 'register',
|
||||
'action' => 'create',
|
||||
], [
|
||||
'allow' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('registrations');
|
||||
}
|
||||
}
|
||||
56
database/migrations/2019_01_22_062511_add_important_flag.php
Normal file
56
database/migrations/2019_01_22_062511_add_important_flag.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddImportantFlag extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('screenshots', function (Blueprint $table) {
|
||||
$table->boolean('important')->default(false);
|
||||
});
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->boolean('important')->default(false);
|
||||
});
|
||||
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->boolean('important')->default(false);
|
||||
});
|
||||
|
||||
Schema::table('projects', function (Blueprint $table) {
|
||||
$table->boolean('important')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('screenshots', function (Blueprint $table) {
|
||||
$table->dropColumn('important');
|
||||
});
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('important');
|
||||
});
|
||||
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->dropColumn('important');
|
||||
});
|
||||
|
||||
Schema::table('projects', function (Blueprint $table) {
|
||||
$table->dropColumn('important');
|
||||
});
|
||||
}
|
||||
}
|
||||
32
database/migrations/2019_01_23_064646_add_removed_flag.php
Normal file
32
database/migrations/2019_01_23_064646_add_removed_flag.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddRemovedFlag extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('screenshots', function (Blueprint $table) {
|
||||
$table->boolean('is_removed')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('screenshots', function (Blueprint $table) {
|
||||
$table->dropColumn('is_removed');
|
||||
});
|
||||
}
|
||||
}
|
||||
53
database/migrations/2019_01_25_092401_fix_roles.php
Normal file
53
database/migrations/2019_01_25_092401_fix_roles.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use App\Models\Rule;
|
||||
use App\Models\Role;
|
||||
|
||||
class FixRoles extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$manager_role_id = 5;
|
||||
$blocked_role_id = 255;
|
||||
|
||||
$role_ids = Role::where('id', '<>', $blocked_role_id)
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
|
||||
if (in_array($manager_role_id, $role_ids)) {
|
||||
// Allows manager access to the role list, user list.
|
||||
$new_manager_rules = [
|
||||
['roles', 'list'],
|
||||
['users', 'manager_access'],
|
||||
];
|
||||
foreach ($new_manager_rules as $rule) {
|
||||
[$object, $action] = $rule;
|
||||
Rule::withTrashed()->updateOrCreate([
|
||||
'role_id' => $manager_role_id,
|
||||
'object' => $object,
|
||||
'action' => $action,
|
||||
], [
|
||||
'allow' => true,
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class MakeDescriptionNullable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->text('description')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->text('description')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddCommentToTask extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('task_comment', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('task_id')->unsigned();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->text('content');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->foreign('task_id')->references('id')->on('tasks')->onDelete('cascade')->onUpdate('cascade');
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('task_comment');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class RemoveFirstnameAndLastname extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('first_name');
|
||||
$table->dropColumn('last_name');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('first_name')->nullable();
|
||||
$table->string('last_name')->nullable();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class DropRelationsUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::create('relations_users', function (Blueprint $table) {
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->integer('attached_user_id')->unsigned();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
$table->foreign('attached_user_id')->references('id')->on('users');
|
||||
|
||||
$table->primary(['user_id', 'attached_user_id'], 'user_attached_user_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::dropIfExists('relations_users');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddChangePasswordToUser extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->boolean('change_password')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('change_password');
|
||||
});
|
||||
}
|
||||
}
|
||||
64
database/migrations/2019_09_04_050531_add_multiply_roles.php
Normal file
64
database/migrations/2019_09_04_050531_add_multiply_roles.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddMultiplyRoles extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('user_role', function (Blueprint $table) {
|
||||
$table->unsignedInteger('user_id')->index();
|
||||
$table->unsignedInteger('role_id')->index();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->foreign('role_id')->references('id')->on('role')->onDelete('cascade');
|
||||
|
||||
$table->unique(['user_id', 'role_id']);
|
||||
});
|
||||
|
||||
$users = User::query()->select(['id', 'role_id'])->get();
|
||||
$usersTotal = $users->count();
|
||||
|
||||
if ($usersTotal) {
|
||||
echo "\n";
|
||||
foreach ($users as $index => $user) {
|
||||
/** @var User $user */
|
||||
$user->role()->associate($user->role_id)->save();
|
||||
echo "\rAttaching latests roles to users..." . ($index + 1) . "/" . $usersTotal . " (" . floor($usersTotal / ($index + 1) * 100.0) . "%)";
|
||||
}
|
||||
echo "\nAll roles attached to users!\n\n";
|
||||
}
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropForeign('users_role_id_foreign');
|
||||
$table->dropColumn('role_id');
|
||||
$table->dropColumn('user_role_value');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->unsignedInteger('role_id')->default(1);
|
||||
$table->unsignedInteger('user_role_value')->default(1);
|
||||
$table->foreign('role_id')->references('id')->on('role');
|
||||
});
|
||||
|
||||
Schema::disableForeignKeyConstraints();
|
||||
Schema::dropIfExists('user_role');
|
||||
Schema::enableForeignKeyConstraints();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class FixProjectReportView extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::unprepared('
|
||||
CREATE OR REPLACE VIEW `project_report` AS
|
||||
SELECT
|
||||
`time_intervals`.`user_id` as `user_id`,
|
||||
`users`.`full_name` as `user_name`,
|
||||
`time_intervals`.`task_id` as `task_id`,
|
||||
`tasks`.`project_id` as `project_id`,
|
||||
`tasks`.`task_name` as `task_name`,
|
||||
`projects`.`name` as `project_name`,
|
||||
`time_intervals`.`start_at` as `date`,
|
||||
SUM(TIME_TO_SEC(TIMEDIFF(`time_intervals`.`end_at`, `time_intervals`.`start_at`))) AS `duration`
|
||||
FROM
|
||||
`time_intervals`
|
||||
INNER JOIN
|
||||
`tasks`
|
||||
ON
|
||||
`tasks`.`id` = `time_intervals`.`task_id`
|
||||
INNER JOIN
|
||||
`projects`
|
||||
ON
|
||||
`tasks`.`project_id` = `projects`.`id`
|
||||
INNER JOIN
|
||||
`users`
|
||||
ON
|
||||
`users`.`id` = `time_intervals`.`user_id`
|
||||
WHERE
|
||||
`time_intervals`.`deleted_at` is null
|
||||
GROUP BY
|
||||
`date`,
|
||||
`user_id`,
|
||||
`user_name`,
|
||||
`task_id`,
|
||||
`task_name`,
|
||||
`project_id`,
|
||||
`project_name`
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
DB::unprepared( 'DROP VIEW IF EXISTS `project_report`' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class DropLevelColumnFromUsers extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('level');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('level');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddIsAdministratorColumnToUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if (!Schema::hasColumn('users', 'is_admin')) {
|
||||
Schema::table('users', static function (Blueprint $table) {
|
||||
$table->boolean('is_admin')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
// Updating users
|
||||
$users = User::with('role')->get();
|
||||
foreach ($users as $user) {
|
||||
/** @var User $user */
|
||||
if ($user->role && $user->role->name === 'root') {
|
||||
$user->is_admin = true;
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', static function (Blueprint $table) {
|
||||
$table->dropColumn('is_admin');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddIsManualToTimeIntervals extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('time_intervals', function($table) {
|
||||
$table->tinyInteger('is_manual');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('time_intervals', function($table) {
|
||||
$table->dropColumn('is_manual');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddForeignKeyToTokens extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('tokens', function (Blueprint $table) {
|
||||
$table->integer('user_id')->unsigned()->change();
|
||||
$table->foreign('user_id')
|
||||
->references('id')
|
||||
->on('users')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('tokens', function (Blueprint $table) {
|
||||
$table->dropForeign('tokens_user_id_foreign');
|
||||
});
|
||||
|
||||
// Drop foreign and change column don't work in the same call to Schema::table
|
||||
Schema::table('tokens', function (Blueprint $table) {
|
||||
$table->integer('user_id')->change();
|
||||
});
|
||||
}
|
||||
}
|
||||
145
database/migrations/2019_11_29_071129_add_role_to_users.php
Normal file
145
database/migrations/2019_11_29_071129_add_role_to_users.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\Rule;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddRoleToUsers extends Migration
|
||||
{
|
||||
protected function updateRules(int $roleID, array $rules, bool $allow)
|
||||
{
|
||||
foreach ($rules as $object => $actions) {
|
||||
foreach ($actions as $action) {
|
||||
Rule::updateOrCreate([
|
||||
'role_id' => $roleID,
|
||||
'object' => $object,
|
||||
'action' => $action,
|
||||
], ['allow' => $allow]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function updateData()
|
||||
{
|
||||
$userRoles = DB::table('user_role')->select(['user_id', 'role_id'])->get();
|
||||
$total = $userRoles->count();
|
||||
|
||||
foreach ($userRoles as $index => $userRole) {
|
||||
DB::table('users')->where('id', $userRole->user_id)->update(['role_id' => $userRole->role_id]);
|
||||
echo "\nSetting roles to users..." . ($index + 1) . "/" . $total;
|
||||
echo " (" . floor(($index + 1) / $total * 100.0) . "%)";
|
||||
}
|
||||
|
||||
echo "\nAll roles set to users.\n";
|
||||
|
||||
$userRole = Role::where(['name' => 'user'])->first();
|
||||
if (isset($userRole)) {
|
||||
$allow = [
|
||||
'screenshots' => ['create', 'bulk-create'],
|
||||
'time-intervals' => ['create', 'bulk-create'],
|
||||
];
|
||||
$disallow = [
|
||||
'users' => ['manager_access', 'list', 'show', 'create', 'edit', 'remove'],
|
||||
'projects' => ['list', 'show', 'create', 'edit', 'remove'],
|
||||
'tasks' => ['dashboard', 'list', 'show', 'create', 'edit', 'remove'],
|
||||
'screenshots' => ['manager_access', 'dashboard', 'list', 'show', 'edit', 'remove'],
|
||||
'time-intervals' => ['manager_access', 'list', 'show', 'edit', 'remove'],
|
||||
'dashboard' => ['manager_access'],
|
||||
'project-report' => ['manager_access'],
|
||||
'time-use-report' => ['manager_access'],
|
||||
];
|
||||
|
||||
$this->updateRules($userRole->id, $allow, true);
|
||||
$this->updateRules($userRole->id, $disallow, false);
|
||||
|
||||
echo "\nUpdated user rules.\n";
|
||||
}
|
||||
|
||||
$auditorRole = Role::where(['name' => 'auditor'])->first();
|
||||
if (isset($auditorRole)) {
|
||||
$allow = [
|
||||
'users' => ['manager_access', 'list', 'show'],
|
||||
'projects' => ['list', 'show'],
|
||||
'tasks' => ['dashboard', 'list', 'show', 'create'],
|
||||
'screenshots' => ['manager_access', 'dashboard', 'list', 'show', 'create', 'bulk-create'],
|
||||
'time-intervals' => ['manager_access', 'list', 'show', 'create', 'bulk-create'],
|
||||
'project-report' => ['manager_access'],
|
||||
'time-use-report' => ['manager_access'],
|
||||
];
|
||||
$disallow = [
|
||||
'users' => ['create', 'edit', 'remove'],
|
||||
'projects' => ['create', 'edit', 'remove'],
|
||||
'tasks' => ['edit', 'remove'],
|
||||
'screenshots' => ['edit', 'remove'],
|
||||
'time-intervals' => ['edit', 'remove', 'bulk-remove'],
|
||||
];
|
||||
|
||||
$this->updateRules($auditorRole->id, $allow, true);
|
||||
$this->updateRules($auditorRole->id, $disallow, false);
|
||||
|
||||
echo "\nUpdated auditor rules.\n";
|
||||
}
|
||||
|
||||
$managerRole = Role::where(['name' => 'manager'])->first();
|
||||
if (isset($managerRole)) {
|
||||
$allow = [
|
||||
'users' => ['manager_access', 'list', 'show', 'create', 'edit'],
|
||||
'projects' => ['list', 'show', 'create', 'edit', 'remove'],
|
||||
'tasks' => ['dashboard', 'list', 'show', 'create', 'edit', 'remove'],
|
||||
'screenshots' => ['manager_access', 'dashboard', 'list', 'show', 'create', 'bulk-create', 'edit', 'remove'],
|
||||
'time-intervals' => ['manager_access', 'list', 'show', 'create', 'bulk-create', 'edit', 'remove', 'bulk-remove'],
|
||||
'project-report' => ['manager_access'],
|
||||
'time-use-report' => ['manager_access'],
|
||||
];
|
||||
$disallow = [
|
||||
'users' => ['remove'],
|
||||
];
|
||||
|
||||
$this->updateRules($managerRole->id, $allow, true);
|
||||
$this->updateRules($managerRole->id, $disallow, false);
|
||||
|
||||
echo "\nUpdated manager rules.\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->unsignedInteger('role_id')->default(2);
|
||||
$table->foreign('role_id')->references('id')->on('role');
|
||||
});
|
||||
|
||||
Schema::table('projects_users', function (Blueprint $table) {
|
||||
$table->unsignedInteger('role_id')->default(2);
|
||||
$table->foreign('role_id')->references('id')->on('role');
|
||||
});
|
||||
|
||||
$this->updateData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropForeign(['role_id']);
|
||||
$table->dropColumn('role_id');
|
||||
});
|
||||
|
||||
Schema::table('projects_users', function (Blueprint $table) {
|
||||
$table->dropForeign(['role_id']);
|
||||
$table->dropColumn('role_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreatePersonalAccessTokensTable extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('personal_access_tokens', static function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->morphs('tokenable');
|
||||
$table->string('name');
|
||||
$table->string('token', 64)->unique();
|
||||
$table->text('abilities')->nullable();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('personal_access_tokens');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddIndexToRoleTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('role', function (Blueprint $table) {
|
||||
$table->index('name');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('role', function (Blueprint $table) {
|
||||
$table->dropIndex('role_name_index');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class FixForProjectReportView extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::unprepared("
|
||||
CREATE OR REPLACE ALGORITHM=MERGE VIEW `project_report` AS
|
||||
SELECT
|
||||
`users`.id as `user_id`,
|
||||
`tasks`.id as `task_id`,
|
||||
`projects`.id as `project_id`,
|
||||
`time_intervals`.`start_at` as `date`,
|
||||
SUM(TIME_TO_SEC(TIMEDIFF(`time_intervals`.`end_at`, `time_intervals`.`start_at`))) AS `duration`
|
||||
FROM
|
||||
`time_intervals`
|
||||
INNER JOIN
|
||||
`tasks`
|
||||
ON
|
||||
`tasks`.`id` = `time_intervals`.`task_id`
|
||||
INNER JOIN
|
||||
`projects`
|
||||
ON
|
||||
`tasks`.`project_id` = `projects`.`id`
|
||||
INNER JOIN
|
||||
`users`
|
||||
ON
|
||||
`users`.`id` = `time_intervals`.`user_id`
|
||||
GROUP BY
|
||||
`date`,
|
||||
`user_id`,
|
||||
`task_id`,
|
||||
`project_id`
|
||||
");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddEntityTypeEntityNameIndexToPropertiesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('properties', function (Blueprint $table) {
|
||||
$table->index(['entity_type', 'name']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('properties', function (Blueprint $table) {
|
||||
$table->dropIndex('properties_entity_type_name_index');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddIndexToDeletedAtToScreenshotsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('screenshots', function (Blueprint $table) {
|
||||
$table->index('deleted_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('screenshots', function (Blueprint $table) {
|
||||
$table->dropIndex('screenshots_deleted_at_index');
|
||||
});
|
||||
}
|
||||
}
|
||||
63
database/migrations/2019_12_20_073840_fix_project_report.php
Normal file
63
database/migrations/2019_12_20_073840_fix_project_report.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class FixProjectReport extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::unprepared('
|
||||
CREATE OR REPLACE VIEW `project_report` AS
|
||||
SELECT
|
||||
`time_intervals`.`user_id` as `user_id`,
|
||||
`users`.`full_name` as `user_name`,
|
||||
`time_intervals`.`task_id` as `task_id`,
|
||||
`tasks`.`project_id` as `project_id`,
|
||||
`tasks`.`task_name` as `task_name`,
|
||||
`projects`.`name` as `project_name`,
|
||||
`time_intervals`.`start_at` as `date`,
|
||||
SUM(TIME_TO_SEC(TIMEDIFF(`time_intervals`.`end_at`, `time_intervals`.`start_at`))) AS `duration`
|
||||
FROM
|
||||
`time_intervals`
|
||||
INNER JOIN
|
||||
`tasks`
|
||||
ON
|
||||
`tasks`.`id` = `time_intervals`.`task_id`
|
||||
INNER JOIN
|
||||
`projects`
|
||||
ON
|
||||
`tasks`.`project_id` = `projects`.`id`
|
||||
INNER JOIN
|
||||
`users`
|
||||
ON
|
||||
`users`.`id` = `time_intervals`.`user_id`
|
||||
WHERE
|
||||
`time_intervals`.`deleted_at` is null
|
||||
GROUP BY
|
||||
`date`,
|
||||
`user_id`,
|
||||
`user_name`,
|
||||
`task_id`,
|
||||
`task_name`,
|
||||
`project_id`,
|
||||
`project_name`
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddForeignKeyAndIndexToTasksTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->unsignedInteger('user_id')->change();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
$table->index('deleted_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->dropForeign('tasks_user_id_foreign');
|
||||
$table->dropIndex('tasks_deleted_at_index');
|
||||
});
|
||||
}
|
||||
}
|
||||
61
database/migrations/2020_01_14_061358_fixes_for_roles.php
Normal file
61
database/migrations/2020_01_14_061358_fixes_for_roles.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\Rule;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class FixesForRoles extends Migration
|
||||
{
|
||||
protected function updateRules(int $roleID, array $rules, bool $allow)
|
||||
{
|
||||
foreach ($rules as $object => $actions) {
|
||||
foreach ($actions as $action) {
|
||||
Rule::updateOrCreate([
|
||||
'role_id' => $roleID,
|
||||
'object' => $object,
|
||||
'action' => $action,
|
||||
], ['allow' => $allow]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$userRole = Role::where(['name' => 'user'])->first();
|
||||
|
||||
if (isset($userRole)) {
|
||||
$allow = [
|
||||
'projects' => ['show'],
|
||||
'tasks' => ['show'],
|
||||
];
|
||||
|
||||
$this->updateRules($userRole->id, $allow, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$userRole = Role::where(['name' => 'user'])->first();
|
||||
|
||||
if (isset($userRole)) {
|
||||
$disallow = [
|
||||
'projects' => ['show'],
|
||||
'tasks' => ['show'],
|
||||
];
|
||||
|
||||
$this->updateRules($userRole->id, $disallow, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddUserLanguageColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->text('user_language');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('user_language');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\Rule;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddRoleToUserRole extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$userRole = Role::where(['name' => 'user'])->first();
|
||||
|
||||
if ($userRole) {
|
||||
Rule::updateOrCreate([
|
||||
'role_id' => $userRole->id,
|
||||
'object' => 'time-intervals',
|
||||
'action' => 'bulk-edit',
|
||||
], ['allow' => true]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
}
|
||||
}
|
||||
59
database/migrations/2020_02_04_080909_fix_user_roles.php
Normal file
59
database/migrations/2020_02_04_080909_fix_user_roles.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\Rule;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class FixUserRoles extends Migration
|
||||
{
|
||||
protected function updateRules(int $roleID, array $rules, bool $allow)
|
||||
{
|
||||
foreach ($rules as $object => $actions) {
|
||||
foreach ($actions as $action) {
|
||||
Rule::updateOrCreate([
|
||||
'role_id' => $roleID,
|
||||
'object' => $object,
|
||||
'action' => $action,
|
||||
], ['allow' => $allow]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$userRole = Role::where(['name' => 'user'])->first();
|
||||
|
||||
if (isset($userRole)) {
|
||||
$disallow = [
|
||||
'projects' => ['show'],
|
||||
'tasks' => ['show'],
|
||||
];
|
||||
|
||||
$this->updateRules($userRole->id, $disallow, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$userRole = Role::where(['name' => 'user'])->first();
|
||||
|
||||
if (isset($userRole)) {
|
||||
$allow = [
|
||||
'projects' => ['show'],
|
||||
'tasks' => ['show'],
|
||||
];
|
||||
|
||||
$this->updateRules($userRole->id, $allow, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\Rule;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddUserPermissions extends Migration
|
||||
{
|
||||
protected function updateRules(int $roleID, array $rules, bool $allow)
|
||||
{
|
||||
foreach ($rules as $object => $actions) {
|
||||
foreach ($actions as $action) {
|
||||
Rule::updateOrCreate([
|
||||
'role_id' => $roleID,
|
||||
'object' => $object,
|
||||
'action' => $action,
|
||||
], ['allow' => $allow]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$userRole = Role::where(['name' => 'user'])->first();
|
||||
|
||||
if (isset($userRole)) {
|
||||
$allow = [
|
||||
'time-intervals' => ['bulk-remove'],
|
||||
'tasks' => ['create'],
|
||||
];
|
||||
|
||||
$this->updateRules($userRole->id, $allow, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$userRole = Role::where(['name' => 'user'])->first();
|
||||
|
||||
if (isset($userRole)) {
|
||||
$disallow = [
|
||||
'time-intervals' => ['bulk-remove'],
|
||||
'tasks' => ['create'],
|
||||
];
|
||||
|
||||
$this->updateRules($userRole->id, $disallow, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DropIndexOnDeletedAt extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('screenshots', function (Blueprint $table) {
|
||||
$sm = Schema::getConnection()->getDoctrineSchemaManager();
|
||||
$indexesFound = $sm->listTableIndexes('screenshots');
|
||||
|
||||
if (array_key_exists('screenshots_deleted_at_index', $indexesFound)) {
|
||||
$table->dropIndex('screenshots_deleted_at_index');
|
||||
}
|
||||
});
|
||||
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$sm = Schema::getConnection()->getDoctrineSchemaManager();
|
||||
$indexesFound = $sm->listTableIndexes('tasks');
|
||||
|
||||
if (array_key_exists('tasks_deleted_at_index', $indexesFound)) {
|
||||
$table->dropIndex('tasks_deleted_at_index');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('screenshots', function (Blueprint $table) {
|
||||
$table->index('deleted_at');
|
||||
});
|
||||
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->index('deleted_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\Rule;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddIntervalsBulkEditRuleToManagers extends Migration
|
||||
{
|
||||
protected function updateRules(int $roleID, array $rules, bool $allow)
|
||||
{
|
||||
foreach ($rules as $object => $actions) {
|
||||
foreach ($actions as $action) {
|
||||
Rule::updateOrCreate([
|
||||
'role_id' => $roleID,
|
||||
'object' => $object,
|
||||
'action' => $action,
|
||||
], ['allow' => $allow]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$role = Role::where(['name' => 'manager'])->first();
|
||||
|
||||
if (isset($role)) {
|
||||
$allow = [
|
||||
'time-intervals' => ['bulk-edit'],
|
||||
];
|
||||
|
||||
$this->updateRules($role->id, $allow, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$role = Role::where(['name' => 'manager'])->first();
|
||||
|
||||
if (isset($role)) {
|
||||
$disallow = [
|
||||
'time-intervals' => ['bulk-edit'],
|
||||
];
|
||||
|
||||
$this->updateRules($role->id, $disallow, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
database/migrations/2020_02_12_134247_recreate_roles.php
Normal file
32
database/migrations/2020_02_12_134247_recreate_roles.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RecreateRoles extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
/*DB::raw('SET FOREIGN_KEY_CHECKS = 0');
|
||||
DB::raw('TRUNCATE role');
|
||||
DB::raw('TRUNCATE rule');
|
||||
DB::raw('SET FOREIGN_KEY_CHECKS = 1');
|
||||
Artisan::call('db:seed', ['--class' => 'RoleSeeder']);*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
35
database/migrations/2020_02_18_104344_fix_recreate_roles.php
Normal file
35
database/migrations/2020_02_18_104344_fix_recreate_roles.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class FixRecreateRoles extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (DB::table('role')->count() > 0) {
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS = 0');
|
||||
DB::statement('TRUNCATE role');
|
||||
DB::statement('TRUNCATE rule');
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS = 1');
|
||||
|
||||
Artisan::call('db:seed', ['--class' => 'RoleSeeder']);
|
||||
|
||||
DB::statement('UPDATE users SET role_id = 2 WHERE role_id > 3');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\Rule;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddTaskEditRuleToUsers extends Migration
|
||||
{
|
||||
protected function updateRules(int $roleID, array $rules, bool $allow)
|
||||
{
|
||||
foreach ($rules as $object => $actions) {
|
||||
foreach ($actions as $action) {
|
||||
Rule::updateOrCreate([
|
||||
'role_id' => $roleID,
|
||||
'object' => $object,
|
||||
'action' => $action,
|
||||
], ['allow' => $allow]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$role = Role::where(['name' => 'user'])->first();
|
||||
|
||||
if (isset($role)) {
|
||||
$allow = [
|
||||
'tasks' => ['edit', 'remove'],
|
||||
];
|
||||
|
||||
$this->updateRules($role->id, $allow, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$role = Role::where(['name' => 'user'])->first();
|
||||
|
||||
if (isset($role)) {
|
||||
$disallow = [
|
||||
'tasks' => ['edit', 'remove'],
|
||||
];
|
||||
|
||||
$this->updateRules($role->id, $disallow, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
database/migrations/2020_03_10_065430_add_user_type.php
Normal file
32
database/migrations/2020_03_10_065430_add_user_type.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddUserType extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('type')->default('employee');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('type');
|
||||
});
|
||||
}
|
||||
}
|
||||
36
database/migrations/2020_03_21_064304_create_jobs_table.php
Normal file
36
database/migrations/2020_03_21_064304_create_jobs_table.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateJobsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateFailedJobsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
}
|
||||
78
database/migrations/2020_03_24_064952_add_project_source.php
Normal file
78
database/migrations/2020_03_24_064952_add_project_source.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Property;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddProjectSource extends Migration
|
||||
{
|
||||
protected function updateProjectSource()
|
||||
{
|
||||
$projectIds = DB::table(Property::getTableName())
|
||||
->select('entity_id')
|
||||
->where('entity_type', '=', Property::PROJECT_CODE)
|
||||
->where('name', '=', 'REDMINE_ID')
|
||||
->pluck('entity_id');
|
||||
|
||||
DB::table('projects')
|
||||
->whereIn('id', $projectIds)
|
||||
->update(['source' => 'redmine']);
|
||||
|
||||
if (Schema::hasTable('gitlab_projects_relations')) {
|
||||
$projectIds = DB::table('gitlab_projects_relations')
|
||||
->select('project_id')
|
||||
->pluck('project_id');
|
||||
|
||||
DB::table('projects')
|
||||
->whereIn('id', $projectIds)
|
||||
->update(['source' => 'gitlab']);
|
||||
}
|
||||
|
||||
if (Schema::hasTable('jira_projects_relation')) {
|
||||
$projectIds = DB::table('jira_projects_relation')
|
||||
->select('project_id')
|
||||
->pluck('project_id');
|
||||
|
||||
DB::table('projects')
|
||||
->whereIn('id', $projectIds)
|
||||
->update(['source' => 'jira']);
|
||||
}
|
||||
|
||||
if (Schema::hasTable('trello_projects_relation')) {
|
||||
$projectIds = DB::table('trello_projects_relation')
|
||||
->select('project_id')
|
||||
->pluck('project_id');
|
||||
|
||||
DB::table('projects')
|
||||
->whereIn('id', $projectIds)
|
||||
->update(['source' => 'trello']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('projects', function (Blueprint $table) {
|
||||
$table->string('source')->default('internal');
|
||||
});
|
||||
|
||||
$this->updateProjectSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('projects', function (Blueprint $table) {
|
||||
$table->dropColumn('source');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddInvitationSentColumnToUsers extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->boolean('invitation_sent')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('invitation_sent');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class RenameRegistrationTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::rename('registrations', 'invitations');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::rename('invitations', 'registrations');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddRoleIdToInvitations extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invitations', function (Blueprint $table) {
|
||||
$table->unsignedInteger('role_id')->nullable();
|
||||
$table->foreign('role_id')->references('id')->on('role');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invitations', function (Blueprint $table) {
|
||||
$table->dropForeign('invitations_role_id_foreign');
|
||||
$table->dropColumn('role_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateSettingsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('settings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('module_name');
|
||||
$table->string('key');
|
||||
$table->text('value');
|
||||
$table->unique(['module_name', 'key']);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('settings');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigrateCompanySettingsFromPropertiesToSettingsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$companySettings = DB::table('properties')
|
||||
->where('entity_type', 'company')
|
||||
->whereIn('name', ['timezone', 'language', 'work_time', 'color'])
|
||||
->get();
|
||||
|
||||
foreach ($companySettings as $property) {
|
||||
DB::table('settings')->insert([
|
||||
'module_name' => 'core',
|
||||
'key' => $property->name,
|
||||
'value' => $property->value,
|
||||
]);
|
||||
|
||||
DB::table('properties')->delete($property->id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$coreSettings = DB::table('settings')->where('module_name', 'core')->get();
|
||||
|
||||
foreach ($coreSettings as $setting) {
|
||||
DB::table('properties')->insert([
|
||||
'entity_id' => 0,
|
||||
'entity_type' => 'company',
|
||||
'name' => $setting->key,
|
||||
'value' => $setting->value
|
||||
]);
|
||||
|
||||
DB::table('settings')->delete($setting->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
42
database/migrations/2020_07_07_145309_change_users_table.php
Normal file
42
database/migrations/2020_07_07_145309_change_users_table.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ChangeUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'payroll_access',
|
||||
'billing_access',
|
||||
'permanent_tasks',
|
||||
'webcam_shots',
|
||||
'poor_time_popup'
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('poor_time_popup')->nullable();
|
||||
$table->integer('payroll_access')->nullable();
|
||||
$table->integer('billing_access')->nullable();
|
||||
$table->integer('permanent_tasks')->nullable();
|
||||
$table->integer('webcam_shots')->nullable();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DropTimeDurationsCache extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::dropIfExists('time_durations_cache');
|
||||
DB::unprepared('DROP PROCEDURE IF EXISTS time_durations_cache_refresh');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::create('time_durations_cache', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->date('date');
|
||||
$table->integer('duration')->unsigned();
|
||||
$table->integer('user_id')->unsigned();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
});
|
||||
|
||||
DB::unprepared('DROP PROCEDURE IF EXISTS `time_durations_cache_refresh`;');
|
||||
DB::unprepared('CREATE PROCEDURE `time_durations_cache_refresh` ()
|
||||
BEGIN
|
||||
DELETE FROM `time_durations_cache`;
|
||||
|
||||
INSERT INTO `time_durations_cache` (`date`, `duration`, `user_id`)
|
||||
SELECT
|
||||
`time_durations`.`date`,
|
||||
`time_durations`.`duration`,
|
||||
`time_durations`.`user_id`
|
||||
FROM `time_durations`;
|
||||
|
||||
END
|
||||
');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddActivityColumnsToTimeIntervalsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('time_intervals', function (Blueprint $table) {
|
||||
$table->integer('activity_fill')->nullable();
|
||||
$table->integer('mouse_fill')->nullable();
|
||||
$table->integer('keyboard_fill')->nullable();
|
||||
|
||||
$table->dropColumn('count_mouse');
|
||||
$table->dropColumn('count_keyboard');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('time_intervals', function (Blueprint $table) {
|
||||
$table->dropColumn('activity_fill');
|
||||
$table->dropColumn('mouse_fill');
|
||||
$table->dropColumn('keyboard_fill');
|
||||
|
||||
$table->integer('count_mouse');
|
||||
$table->integer('count_keyboard');
|
||||
});
|
||||
}
|
||||
}
|
||||
33
database/migrations/2020_07_15_074343_drop_tokens_table.php
Normal file
33
database/migrations/2020_07_15_074343_drop_tokens_table.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DropTokensTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::drop('tokens');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::create('tokens', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('user_id');
|
||||
$table->string('token', 512);
|
||||
$table->dateTime('expires_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
34
database/migrations/2020_07_15_094948_user_auth_nonce.php
Normal file
34
database/migrations/2020_07_15_094948_user_auth_nonce.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UserAuthNonce extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('remember_token');
|
||||
$table->integer('nonce')->unsigned()->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('remember_token')->nullable();
|
||||
$table->dropColumn('nonce');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UserClientInstalledFlag extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->unsignedTinyInteger('client_installed')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('client_installed');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class RenameUserPermanentField extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->boolean('permanent_screenshots')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('permanent_screenshots');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use App\Models\User;
|
||||
use App\Models\Project;
|
||||
|
||||
class SyncUsersWithProjects extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::table('users')
|
||||
->leftJoin('time_intervals', 'users.id', '=', 'time_intervals.user_id')
|
||||
->leftJoin('tasks', 'tasks.id', '=', 'time_intervals.task_id')
|
||||
->leftJoin('projects', 'projects.id', '=', 'tasks.project_id')
|
||||
->selectRaw('users.id as user_id, projects.id as project_id')
|
||||
->distinct('users.id', 'project_id')
|
||||
->get()
|
||||
->map(function ($userProject) {
|
||||
User::withoutGlobalScopes()
|
||||
->find($userProject->user_id)
|
||||
->projects()
|
||||
->syncWithoutDetaching($userProject->project_id);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Project::all()->map(function ($project) {
|
||||
/* @var App\Models\Project $project*/
|
||||
$project->users()->wherePivot('role_id', 2)->detach();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddLastActivityColumnToUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dateTime('last_activity');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('last_activity');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DropTimeDurationAndTriggers extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::unprepared('DROP TRIGGER IF EXISTS `time_durations_cache_insert_trigger`');
|
||||
DB::unprepared('DROP TRIGGER IF EXISTS `time_durations_cache_update_trigger`');
|
||||
DB::unprepared('DROP TRIGGER IF EXISTS `time_durations_cache_delete_trigger`');
|
||||
DB::unprepared('DROP VIEW IF EXISTS `time_durations`');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
DB::unprepared('CREATE VIEW `time_durations` AS
|
||||
SELECT
|
||||
DATE(`start_at`) AS `date`,
|
||||
SUM(TIME_TO_SEC(TIMEDIFF(`end_at`, `start_at`))) AS `duration`,
|
||||
`user_id`
|
||||
FROM `time_intervals`
|
||||
WHERE `deleted_at` IS NULL
|
||||
GROUP BY
|
||||
`date`,
|
||||
`user_id`');
|
||||
|
||||
DB::unprepared('CREATE TRIGGER `time_durations_cache_insert_trigger` AFTER INSERT ON `time_intervals`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE `interval` INT UNSIGNED;
|
||||
DECLARE `current_date` DATE;
|
||||
SET
|
||||
`interval` = TIME_TO_SEC(TIMEDIFF(NEW.`end_at`, NEW.`start_at`)),
|
||||
`current_date` = DATE(NEW.`start_at`);
|
||||
|
||||
IF NEW.`deleted_at` IS NULL THEN
|
||||
IF (SELECT 1
|
||||
FROM `time_durations_cache`
|
||||
WHERE `time_durations_cache`.`date` = `current_date`
|
||||
AND `time_durations_cache`.`user_id` = NEW.`user_id`
|
||||
) = 1
|
||||
THEN
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` + `interval`
|
||||
WHERE `time_durations_cache`.`date` = `current_date`
|
||||
AND `time_durations_cache`.`user_id` = NEW.`user_id`;
|
||||
ELSE
|
||||
INSERT INTO `time_durations_cache` (`date`, `duration`, `user_id`)
|
||||
VALUES (`current_date`, `interval`, NEW.`user_id`);
|
||||
END IF;
|
||||
END IF;
|
||||
END');
|
||||
|
||||
DB::unprepared('CREATE TRIGGER `time_durations_cache_update_trigger` AFTER UPDATE ON `time_intervals`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE `new_interval` INT UNSIGNED;
|
||||
DECLARE `old_interval` INT UNSIGNED;
|
||||
DECLARE `new_date` DATE;
|
||||
DECLARE `old_date` DATE;
|
||||
SET
|
||||
`new_interval` = TIME_TO_SEC(TIMEDIFF(NEW.`end_at`, NEW.`start_at`)),
|
||||
`old_interval` = TIME_TO_SEC(TIMEDIFF(OLD.`end_at`, OLD.`start_at`)),
|
||||
`new_date` = DATE(NEW.`start_at`),
|
||||
`old_date` = DATE(OLD.`start_at`);
|
||||
|
||||
IF OLD.`deleted_at` IS NULL THEN
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` - `old_interval`
|
||||
WHERE `date` = `old_date`
|
||||
AND `user_id` = OLD.`user_id`;
|
||||
END IF;
|
||||
|
||||
IF NEW.`deleted_at` IS NULL THEN
|
||||
IF (SELECT 1
|
||||
FROM `time_durations_cache`
|
||||
WHERE `time_durations_cache`.`date` = `new_date`
|
||||
AND `time_durations_cache`.`user_id` = NEW.`user_id`
|
||||
) = 1
|
||||
THEN
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` + `new_interval`
|
||||
WHERE `date` = `new_date`
|
||||
AND `time_durations_cache`.`user_id` = NEW.`user_id`;
|
||||
ELSE
|
||||
INSERT INTO `time_durations_cache` (`date`, `duration`, `user_id`)
|
||||
VALUES (`new_date`, `new_interval`, NEW.`user_id`);
|
||||
END IF;
|
||||
END IF;
|
||||
END');
|
||||
|
||||
DB::unprepared('CREATE TRIGGER `time_durations_cache_delete_trigger` AFTER DELETE ON `time_intervals`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE `interval` INT UNSIGNED;
|
||||
DECLARE `current_date` DATE;
|
||||
SET
|
||||
`interval` = TIME_TO_SEC(TIMEDIFF(OLD.`end_at`, OLD.`start_at`)),
|
||||
`current_date` = DATE(OLD.`start_at`);
|
||||
|
||||
IF OLD.`deleted_at` IS NULL THEN
|
||||
UPDATE `time_durations_cache`
|
||||
SET `duration` = `duration` - `interval`
|
||||
WHERE `time_durations_cache`.`date` = `current_date`
|
||||
AND `time_durations_cache`.`user_id` = OLD.`user_id`;
|
||||
END IF;
|
||||
END');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateTasksUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('tasks_users', function (Blueprint $table) {
|
||||
$table->unsignedInteger('task_id');
|
||||
$table->unsignedInteger('user_id');
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('task_id')->references('id')->on('tasks');
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
|
||||
$table->primary(['task_id', 'user_id'], 'tasks_users_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('tasks_users');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class MigrateTasksUsers extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::table('tasks')
|
||||
->select(['id', 'user_id'])
|
||||
->where('user_id', '!=', 0)
|
||||
->whereNotNull('user_id')
|
||||
->orderBy('id')
|
||||
->chunk(100, static function ($tasks) {
|
||||
$array = [];
|
||||
foreach ($tasks as $task) {
|
||||
$array[] = [
|
||||
'task_id' => $task->id,
|
||||
'user_id' => $task->user_id,
|
||||
];
|
||||
}
|
||||
|
||||
DB::table('tasks_users')->insert($array);
|
||||
});
|
||||
|
||||
Schema::table('tasks', static function (Blueprint $table) {
|
||||
try {
|
||||
$table->dropForeign('tasks_user_id_foreign');
|
||||
} catch(Exception $e) {}
|
||||
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::disableForeignKeyConstraints();
|
||||
|
||||
Schema::table('tasks', static function (Blueprint $table) {
|
||||
$table->unsignedInteger('user_id');
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
});
|
||||
|
||||
Schema::enableForeignKeyConstraints();
|
||||
|
||||
DB::table('tasks_users')
|
||||
->select(['task_id', 'user_id'])
|
||||
->orderBy('task_id')
|
||||
->orderBy('user_id')
|
||||
->chunk(100, static function ($taskUserRelations) {
|
||||
foreach ($taskUserRelations as $taskUserRelation) {
|
||||
DB::table('tasks')
|
||||
->where(['id' => $taskUserRelation->task_id])
|
||||
->update(['user_id' => $taskUserRelation->user_id]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
38
database/migrations/2020_10_23_105909_drop_rules_table.php
Normal file
38
database/migrations/2020_10_23_105909_drop_rules_table.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DropRulesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::dropIfExists('rule');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::create('rule', function(Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('role_id');
|
||||
$table->string('object', 50);
|
||||
$table->string('action', 50);
|
||||
$table->boolean('allow')->default(false);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['role_id', 'object', 'action']);
|
||||
$table->foreign('role_id')->references('id')->on('role')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateModulesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('modules', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->boolean('enabled')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('modules');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateUserIdColumnToTasksTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!Schema::hasColumn('tasks', 'user_id')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->unsignedInteger('user_id')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
if (!Schema::hasColumn('tasks', 'user_id')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::disableForeignKeyConstraints();
|
||||
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->unsignedInteger('user_id')->nullable(false)->change();
|
||||
});
|
||||
|
||||
Schema::enableForeignKeyConstraints();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddColorFieldToPrioritiesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('priorities', function (Blueprint $table) {
|
||||
$table->string('color')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('priorities', function (Blueprint $table) {
|
||||
$table->dropColumn('color');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddDefaultPriorityToProjects extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('projects', function (Blueprint $table) {
|
||||
$table->unsignedInteger('default_priority_id')->nullable();
|
||||
$table->foreign('default_priority_id')->references('id')->on('priorities');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('projects', function (Blueprint $table) {
|
||||
$table->dropForeign(['default_priority_id']);
|
||||
$table->dropColumn('default_priority_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use Database\Seeders\StatusSeeder;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateStatusesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('statuses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->boolean('active');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
$seeder = new StatusSeeder();
|
||||
$seeder->run();
|
||||
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->unsignedInteger('status_id')->nullable();
|
||||
});
|
||||
|
||||
DB::table('tasks')
|
||||
->where('active', 1)
|
||||
->update(['status_id' => 1]);
|
||||
|
||||
DB::table('tasks')
|
||||
->where('active', 0)
|
||||
->update(['status_id' => 2]);
|
||||
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->dropColumn('active');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->boolean('active');
|
||||
});
|
||||
|
||||
DB::table('tasks as t')
|
||||
->join('statuses as s', 't.status_id', '=', 's.id')
|
||||
->update(['t.active' => DB::raw('s.active')]);
|
||||
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->dropColumn('status_id');
|
||||
});
|
||||
|
||||
Schema::dropIfExists('statuses');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateProjectsStatusesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('projects_statuses', function (Blueprint $table) {
|
||||
$table->unsignedInteger('project_id');
|
||||
$table->unsignedBigInteger('status_id');
|
||||
$table->string('color')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('project_id')->references('id')->on('projects');
|
||||
$table->foreign('status_id')->references('id')->on('statuses');
|
||||
|
||||
$table->primary(['project_id', 'status_id'], 'projects_statuses_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('projects_statuses');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddColorFieldToStatusesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('statuses', function (Blueprint $table) {
|
||||
$table->string('color')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('statuses', function (Blueprint $table) {
|
||||
$table->dropColumn('color');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddRelativePositionToTasksTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->decimal('relative_position', 64, 30)->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->dropColumn('relative_position');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddDueDateToTasksTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->timestamp('due_date')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('tasks', function (Blueprint $table) {
|
||||
$table->dropColumn('due_date');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateTaskHistoryTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('task_history', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedInteger('task_id');
|
||||
$table->unsignedInteger('user_id');
|
||||
$table->string('field');
|
||||
$table->text('new_value');
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('task_id')->references('id')->on('tasks');
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('task_history');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use App\Contracts\ScreenshotService;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('screenshots')
|
||||
->lazyById()
|
||||
->each(static function ($screenshot) {
|
||||
rescue(static fn() => app(ScreenshotService::class)->saveScreenshot(
|
||||
Storage::path($screenshot->path),
|
||||
$screenshot->time_interval_id
|
||||
));
|
||||
});
|
||||
|
||||
Storage::deleteDirectory('uploads/screenshots');
|
||||
|
||||
Schema::drop('screenshots');
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddGeoToInterval extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('time_intervals', static function (Blueprint $table) {
|
||||
$table->point('location')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('time_intervals', static function (Blueprint $table) {
|
||||
$table->dropColumn('location');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddOldValueColumnToTaskHistoryTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('task_history', function (Blueprint $table) {
|
||||
$table->text('old_value')->nullable();
|
||||
});
|
||||
|
||||
DB::table('task_history')
|
||||
->orderBy('id')
|
||||
->chunk(100, static function ($items) {
|
||||
foreach ($items as $item) {
|
||||
$prevChange = DB::table('task_history')
|
||||
->where('task_id', $item->task_id)
|
||||
->where('field', $item->field)
|
||||
->where('created_at', '<', $item->created_at)
|
||||
->orderBy('created_at', 'desc')
|
||||
->first();
|
||||
if ($prevChange !== null) {
|
||||
DB::table('task_history')
|
||||
->where('id', $item->id)
|
||||
->update(['old_value' => $prevChange->new_value]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('task_history', function (Blueprint $table) {
|
||||
$table->dropColumn('old_value');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateTrackedApplicationsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('tracked_applications', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('title');
|
||||
$table->string('executable');
|
||||
|
||||
$table->unsignedInteger('time_interval_id')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tracked_applications');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddUserIdColumnToTrackedApplicationTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('tracked_applications', function (Blueprint $table) {
|
||||
$table->unsignedInteger('user_id')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('tracked_applications', function (Blueprint $table) {
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user