Skip to content

Commit

Permalink
Merge pull request #27 from harishdurga/26-quiz-question-soft-delete
Browse files Browse the repository at this point in the history
26 quiz question soft delete - Removing unique constraint from quiz questions table
  • Loading branch information
harishdurga authored Sep 7, 2022
2 parents cc4b6f7 + 4fad53c commit b681d49
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
21 changes: 19 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.0]
php: [8.0, 8.1]
laravel: [9.*]
stability: [prefer-stable]
include:
- laravel: 9.*
testbench: ^7.0
env:
DB_CONNECTION: testing
DB_DATABASE: laravel
DB_USERNAME: root
DB_PASSWORD: TestDB@1234
services:
mysql:
image: mysql:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: TestDB@1234
MYSQL_DATABASE: laravel
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand All @@ -30,7 +45,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysql, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
Expand All @@ -43,3 +58,5 @@ jobs:
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public function up()
$table->unsignedInteger('order')->default(0);
$table->timestamps();
$table->softDeletes();
$table->unique(['quiz_id', 'question_id']);
});

// Quiz Attempts Table
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

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

return new class extends Migration
{
public array $tableNames;
public function __construct()
{
$this->tableNames = config('laravel-quiz.table_names');
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table($this->tableNames['quiz_questions'], function (Blueprint $table) {
$sm = Schema::getConnection()->getDoctrineSchemaManager();
$indexesFound = $sm->listTableIndexes($this->tableNames['quiz_questions']);
if (array_key_exists($this->tableNames['quiz_questions'] . "_quiz_id_question_id_unique", $indexesFound)) {
$table->dropForeign($this->tableNames['quiz_questions'] . '_question_id_foreign');
$table->dropForeign($this->tableNames['quiz_questions'] . '_quiz_id_foreign');
$table->dropUnique($this->tableNames['quiz_questions'] . "_quiz_id_question_id_unique");
$table->foreignId('quiz_id')->change()->constrained($this->tableNames['quizzes'])->cascadeOnDelete();
$table->foreignId('question_id')->change()->constrained($this->tableNames['questions'])->cascadeOnDelete();
}
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('quiz_questions', function (Blueprint $table) {
//
});
}
};

0 comments on commit b681d49

Please sign in to comment.