From 2033a3afffa3710594825ab1b3b40424830f1e8e Mon Sep 17 00:00:00 2001 From: Hubert Krzysztofiak Date: Mon, 11 Apr 2022 12:43:19 +0200 Subject: [PATCH 1/2] Change migrate in tables --- .gitignore | 3 +- ...h5p_contents_libraries_structure_table.php | 74 +++++++++++++++++++ phpunit.xml | 20 ++--- src/Models/H5PContent.php | 2 +- src/Models/H5PContentLibrary.php | 4 - src/Models/H5PLibrary.php | 1 - src/Models/H5PLibraryDependency.php | 2 - src/Models/H5PLibraryLanguage.php | 4 +- src/Models/H5PTempFile.php | 1 - 9 files changed, 88 insertions(+), 23 deletions(-) create mode 100644 database/migrations/2022_04_11_095716_change_hh5p_contents_libraries_structure_table.php diff --git a/.gitignore b/.gitignore index c4bdd567..05d17c01 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ vendor .phpunit.result.cache composer.lock -openapi.json \ No newline at end of file +openapi.json +.DS_Store diff --git a/database/migrations/2022_04_11_095716_change_hh5p_contents_libraries_structure_table.php b/database/migrations/2022_04_11_095716_change_hh5p_contents_libraries_structure_table.php new file mode 100644 index 00000000..44882dbb --- /dev/null +++ b/database/migrations/2022_04_11_095716_change_hh5p_contents_libraries_structure_table.php @@ -0,0 +1,74 @@ +dropPrimary('hh5p_contents_libraries_pkey'); + $table->unique(['content_id', 'library_id', 'dependency_type']); + }); + Schema::table('hh5p_contents_libraries', function (Blueprint $table) { + $table->id(); + }); + Schema::table('hh5p_libraries_languages', function (Blueprint $table) { + $table->dropPrimary('hh5p_libraries_languages_pkey'); + $table->unique(['library_id', 'language_code']); + }); + Schema::table('hh5p_libraries_languages', function (Blueprint $table) { + $table->id(); + }); + Schema::table('hh5p_libraries_dependencies', function (Blueprint $table) { + $table->dropPrimary('hh5p_libraries_dependencies_pkey'); + $table->unique(['library_id', 'required_library_id']); + }); + Schema::table('hh5p_libraries_dependencies', function (Blueprint $table) { + $table->id(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('hh5p_contents_libraries', function (Blueprint $table) { + $table->dropColumn('id'); + }); + Schema::table('hh5p_contents_libraries', function (Blueprint $table) { + $table->dropUnique('hh5p_contents_libraries_content_id_library_id_dependency_type_u'); + }); + Schema::table('hh5p_contents_libraries', function (Blueprint $table) { + $table->primary(['content_id', 'library_id', 'dependency_type'], 'fk_primary'); + }); + Schema::table('hh5p_libraries_languages', function (Blueprint $table) { + $table->dropColumn('id'); + }); + Schema::table('hh5p_libraries_languages', function (Blueprint $table) { + $table->dropUnique('hh5p_libraries_languages_library_id_language_code_unique'); + }); + Schema::table('hh5p_libraries_languages', function (Blueprint $table) { + $table->primary(['library_id', 'language_code'], 'fk_primary'); + }); + Schema::table('hh5p_libraries_dependencies', function (Blueprint $table) { + $table->dropColumn('id'); + }); + Schema::table('hh5p_libraries_dependencies', function (Blueprint $table) { + $table->dropUnique('hh5p_libraries_dependencies_library_id_required_library_id_uniq'); + }); + Schema::table('hh5p_libraries_dependencies', function (Blueprint $table) { + $table->primary(['library_id', 'required_library_id'], 'fk_primary'); + }); + } +} diff --git a/phpunit.xml b/phpunit.xml index 1281b423..2f3c31a3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,14 +11,14 @@ ./tests - - - - - - - - - - + + + + + + + + + + diff --git a/src/Models/H5PContent.php b/src/Models/H5PContent.php index 6a52d03b..45b4b73d 100644 --- a/src/Models/H5PContent.php +++ b/src/Models/H5PContent.php @@ -2,7 +2,7 @@ namespace EscolaLms\HeadlessH5P\Models; -use App\User; +use EscolaLms\Core\Models\User; use EscolaLms\HeadlessH5P\Database\Factories\H5PContentFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; diff --git a/src/Models/H5PContentLibrary.php b/src/Models/H5PContentLibrary.php index 1e19b888..cae2080d 100644 --- a/src/Models/H5PContentLibrary.php +++ b/src/Models/H5PContentLibrary.php @@ -3,8 +3,6 @@ namespace EscolaLms\HeadlessH5P\Models; use Illuminate\Database\Eloquent\Model; -use EscolaLms\HeadlessH5P\Models\H5PLibrary; -use EscolaLms\HeadlessH5P\Models\H5PContent; use Illuminate\Database\Eloquent\Relations\BelongsTo; class H5PContentLibrary extends Model @@ -13,8 +11,6 @@ class H5PContentLibrary extends Model public $timestamps = false; protected $table = 'hh5p_contents_libraries'; - - protected $primaryKey = ['content_id', 'library_id', 'dependency_type']; protected $fillable = [ 'content_id', diff --git a/src/Models/H5PLibrary.php b/src/Models/H5PLibrary.php index d9446d3c..fa98eff1 100644 --- a/src/Models/H5PLibrary.php +++ b/src/Models/H5PLibrary.php @@ -118,7 +118,6 @@ class H5PLibrary extends Model use HasFactory; protected $table = 'hh5p_libraries'; - //protected $primaryKey = 'id'; protected $fillable = [ 'name', 'title', diff --git a/src/Models/H5PLibraryDependency.php b/src/Models/H5PLibraryDependency.php index 790d459a..b48c4b90 100644 --- a/src/Models/H5PLibraryDependency.php +++ b/src/Models/H5PLibraryDependency.php @@ -12,8 +12,6 @@ class H5PLibraryDependency extends Model public $timestamps = false; protected $table = 'hh5p_libraries_dependencies'; - - protected $primaryKey = ['library_id', 'required_library_id']; protected $fillable = [ 'library_id', diff --git a/src/Models/H5PLibraryLanguage.php b/src/Models/H5PLibraryLanguage.php index e34b7450..921872f6 100644 --- a/src/Models/H5PLibraryLanguage.php +++ b/src/Models/H5PLibraryLanguage.php @@ -12,8 +12,6 @@ class H5PLibraryLanguage extends Model public $timestamps = false; protected $table = 'hh5p_libraries_languages'; - - protected $primaryKey = ['library_id', 'language_code']; protected $fillable = [ 'library_id', @@ -26,7 +24,7 @@ public function getTranslationAttribute($value) { return json_decode($value); } - + public function library():BelongsTo { diff --git a/src/Models/H5PTempFile.php b/src/Models/H5PTempFile.php index c56076f6..436ab3ec 100644 --- a/src/Models/H5PTempFile.php +++ b/src/Models/H5PTempFile.php @@ -7,7 +7,6 @@ class H5PTempFile extends Model { - protected $primaryKey = 'id'; protected $table = 'hh5p_temp_files'; protected $fillable = [ 'path', From 72bf7feb3c3aa50acdfc9f8cde0ba1496c3b4ce7 Mon Sep 17 00:00:00 2001 From: Hubert Krzysztofiak Date: Mon, 11 Apr 2022 13:07:59 +0200 Subject: [PATCH 2/2] Change type in column --- ...h5p_contents_libraries_structure_table.php | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/database/migrations/2022_04_11_095716_change_hh5p_contents_libraries_structure_table.php b/database/migrations/2022_04_11_095716_change_hh5p_contents_libraries_structure_table.php index 44882dbb..300c8b67 100644 --- a/database/migrations/2022_04_11_095716_change_hh5p_contents_libraries_structure_table.php +++ b/database/migrations/2022_04_11_095716_change_hh5p_contents_libraries_structure_table.php @@ -1,6 +1,7 @@ dropPrimary('hh5p_contents_libraries_pkey'); - $table->unique(['content_id', 'library_id', 'dependency_type']); + $table->unique(['content_id', 'library_id', 'dependency_type'], 'hh5p_contents_libraries_unique_key'); }); Schema::table('hh5p_contents_libraries', function (Blueprint $table) { $table->id(); }); Schema::table('hh5p_libraries_languages', function (Blueprint $table) { $table->dropPrimary('hh5p_libraries_languages_pkey'); - $table->unique(['library_id', 'language_code']); + $table->unique(['library_id', 'language_code'], 'hh5p_libraries_languages_unique_key'); }); Schema::table('hh5p_libraries_languages', function (Blueprint $table) { $table->id(); }); Schema::table('hh5p_libraries_dependencies', function (Blueprint $table) { $table->dropPrimary('hh5p_libraries_dependencies_pkey'); - $table->unique(['library_id', 'required_library_id']); + $table->unique(['library_id', 'required_library_id'], 'hh5p_libraries_dependencies_unique_key'); }); Schema::table('hh5p_libraries_dependencies', function (Blueprint $table) { $table->id(); @@ -47,7 +48,13 @@ public function down() $table->dropColumn('id'); }); Schema::table('hh5p_contents_libraries', function (Blueprint $table) { - $table->dropUnique('hh5p_contents_libraries_content_id_library_id_dependency_type_u'); + $table->dropUnique('hh5p_contents_libraries_unique_key'); + }); + Schema::table('hh5p_libraries_languages', function (Blueprint $table) { + $table->dropUnique('hh5p_libraries_languages_unique_key'); + }); + Schema::table('hh5p_libraries_dependencies', function (Blueprint $table) { + $table->dropUnique('hh5p_libraries_dependencies_unique_key'); }); Schema::table('hh5p_contents_libraries', function (Blueprint $table) { $table->primary(['content_id', 'library_id', 'dependency_type'], 'fk_primary'); @@ -55,18 +62,12 @@ public function down() Schema::table('hh5p_libraries_languages', function (Blueprint $table) { $table->dropColumn('id'); }); - Schema::table('hh5p_libraries_languages', function (Blueprint $table) { - $table->dropUnique('hh5p_libraries_languages_library_id_language_code_unique'); - }); Schema::table('hh5p_libraries_languages', function (Blueprint $table) { $table->primary(['library_id', 'language_code'], 'fk_primary'); }); Schema::table('hh5p_libraries_dependencies', function (Blueprint $table) { $table->dropColumn('id'); }); - Schema::table('hh5p_libraries_dependencies', function (Blueprint $table) { - $table->dropUnique('hh5p_libraries_dependencies_library_id_required_library_id_uniq'); - }); Schema::table('hh5p_libraries_dependencies', function (Blueprint $table) { $table->primary(['library_id', 'required_library_id'], 'fk_primary'); });