Skip to content

Commit

Permalink
Added some database tables related to Workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dansuf committed Apr 16, 2018
1 parent 06f8389 commit 1cc5d47
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Clone the repository and create your own `.env` file by copying `.env.example` a
composer install
php artisan key:generate

To create the database structure please run the following command:

php artisan migrate

You will also need to run it every time there is a new database migration available.

### How to run

Run the following command:
Expand Down
14 changes: 14 additions & 0 deletions app/Field.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Field extends Model
{

public function options()
{
return $this->hasMany('App\Option','categoricalFieldId');
}
}
10 changes: 10 additions & 0 deletions app/Option.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Option extends Model
{
//
}
31 changes: 31 additions & 0 deletions app/Step.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Step extends Model
{
const CREATED_AT = 'created';
const UPDATED_AT = 'updated';

public function workflow()
{
return $this->belongsTo('App\Workflow','workflowStepWorkflowId');
}

public function nextSteps()
{
return $this->belongsToMany('App\Step','next_steps','previousStepId','nextStepId'); //TODO pivots
}

public function previousSteps()
{
return $this->belongsToMany('App\Step','next_steps','nextStepId','previousStepId'); //TODO pivots
}

public function fields()
{
return $this->belongsToMany('App\Field','field_in_input_steps','inputStepId','fieldId');
}
}
10 changes: 10 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@ class User extends Authenticatable
protected $hidden = [
'password', 'remember_token',
];

public function createdWorkflows()
{
return $this->hasMany('App\Workflow','authorId');
}

public function verifiedWorkflows()
{
return $this->hasMany('App\Workflow','verifiedByReviewerId');
}
}
26 changes: 26 additions & 0 deletions app/Workflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Workflow extends Model
{
const CREATED_AT = 'created';
const UPDATED_AT = 'updated';

public function author()
{
return $this->belongsTo('App\User','authorId');
}

public function verifiedByReviewer()
{
return $this->belongsTo('App\User','verifiedByReviewerId');
}

public function steps()
{
return $this->hasMany('App\Step','workflowStepWorkflowId');
}
}
107 changes: 107 additions & 0 deletions database/migrations/2018_04_16_162649_basic_tables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class BasicTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('workflows', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger("authorId");
$table->timestamp("created")->useCurrent();
$table->timestamp("updated")->nullable();
$table->string("languageCode",2);
$table->string("title",30);
$table->string("description",5000)->nullable();
$table->boolean("isDraft")->nullable()->default(true);
$table->boolean("isPublished")->nullable()->default(false);
$table->boolean("isVerified")->nullable()->default(false);
$table->timestamp("verificationDate")->nullable();
$table->unsignedInteger("verifiedByReviewerId")->nullable();

$table->foreign("authorId")->references("id")->on("users");
$table->foreign("verifiedByReviewerId")->references("id")->on("users");
});

Schema::create('steps', function (Blueprint $table) {
$table->increments('id');
$table->timestamp("created")->useCurrent();
$table->timestamp("updated")->nullable();
$table->unsignedInteger("evidencioModelId");
$table->string("title",30);
$table->string("categoryName",30)->nullable();
$table->string("description",5000)->nullable();
$table->boolean("isStored")->nullable();
$table->unsignedSmallInteger("resultStepExpectedResultType")->nullable();
$table->unsignedSmallInteger("resultStepRepresentationType")->nullable();
$table->unsignedSmallInteger("workflowStepLevel")->nullable();
$table->unsignedInteger("workflowStepWorkflowId")->nullable();

$table->foreign("workflowStepWorkflowId")->references("id")->on("workflows");
});

Schema::create('fields', function (Blueprint $table) {
$table->increments('id');
$table->string("friendlyTitle",40);
$table->string("friendlyDescription")->nullable();
$table->integer("continuousFieldMax")->nullable();
$table->integer("continuousFieldMin")->nullable();
$table->integer("continuousFieldStepBy")->nullable();
$table->string("continuousFieldUnit",15)->nullable();
});

Schema::create('field_in_input_steps', function (Blueprint $table) {
$table->unsignedInteger("fieldId");
$table->unsignedInteger("inputStepId");

$table->primary(["fieldId","inputStepId"]);

$table->foreign("fieldId")->references("id")->on("fields");
$table->foreign("inputStepId")->references("id")->on("steps");

});

Schema::create('options', function (Blueprint $table) {
$table->increments('id');
$table->string("value",15);
$table->unsignedInteger("categoricalFieldId");

$table->foreign("categoricalFieldId")->references("id")->on("fields");
});

Schema::create('next_steps', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger("nextStepId");
$table->unsignedInteger("previousStepId");
$table->string("condition",10000);
$table->string("description",5000)->nullable();
$table->string("title",30)->nullable();

$table->foreign("nextStepId")->references("id")->on("steps");
$table->foreign("previousStepId")->references("id")->on("steps");
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('next_steps');
Schema::dropIfExists('options');
Schema::dropIfExists('field_in_input_steps');
Schema::dropIfExists('fields');
Schema::dropIfExists('steps');
Schema::dropIfExists('workflows');
}
}

0 comments on commit 1cc5d47

Please sign in to comment.