Created
February 20, 2021 15:29
-
-
Save zorca/a09b2f5fb630796f3111182ac194ea43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Support\Facades\Schema; | |
class CreateQuizModuleTables extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
// Quizzes | |
Schema::create('quiz_module_quizzes', function (Blueprint $table) { | |
$table->id(); | |
$table->string('title'); | |
$table->unsignedInteger('try_score')->nullable(); | |
$table->unsignedInteger('correct_score')->nullable(); | |
$table->json('data')->nullable(); | |
$table->timestamps(); | |
}); | |
Schema::create('quiz_module_questions', function (Blueprint $table) { | |
$table->id('id'); | |
$table->foreignId('quiz_module_quiz_id'); | |
$table->string('text'); | |
$table->string('type'); | |
$table->boolean('visible')->default(false); | |
$table->timestamps(); | |
$table->foreign('quiz_module_quiz_id')->references('id')->on('quiz_module_quizzes')->onDelete('cascade'); | |
}); | |
Schema::create('quiz_module_question_answers', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->foreignId('quiz_module_question_id'); | |
$table->string('answer'); | |
$table->boolean('correct')->default(false); | |
$table->timestamps(); | |
$table->foreign('quiz_module_question_id')->references('id')->on('quiz_module_questions')->onDelete('cascade'); | |
}); | |
// User attempts | |
Schema::create('quiz_module_user_attempts', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->foreignId('user_id'); | |
$table->foreignId('quiz_module_quiz_id'); | |
$table->unsignedInteger('total_score')->nullable(); | |
$table->timestamps(); | |
$table->foreign('user_id')->references('id')->on('users'); | |
$table->foreign('quiz_module_quiz_id')->references('id')->on('quiz_module_quizzes'); | |
}); | |
Schema::create('quiz_module_user_attempt_answers', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->foreignId('quiz_module_question_id'); | |
$table->foreignId('quiz_module_user_attempt_id'); | |
$table->foreignId('quiz_module_question_answer_id'); | |
$table->timestamps(); | |
$table->foreign('quiz_module_question_id')->references('id')->on('quiz_module_questions'); | |
$table->foreign('quiz_module_question_answer_id')->references('id')->on('quiz_module_question_answers'); | |
$table->foreign('quiz_module_user_attempt_id')->references('id')->on('quiz_module_user_attempts'); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::dropIfExists('quiz_module_quizzes'); | |
Schema::dropIfExists('quiz_module_questions'); | |
Schema::dropIfExists('quiz_module_question_answers'); | |
Schema::dropIfExists('quiz_module_user_attempts'); | |
Schema::dropIfExists('quiz_module_user_attempt_answers'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment