-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add JSON type CF Add JSON type CF * Apply fixes from StyleCI * Update 2024_11_12_073145_add_json_type_to_custom_field_plain_types_table.php a * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
- Loading branch information
1 parent
1fa1cab
commit b48891a
Showing
7 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
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
56 changes: 56 additions & 0 deletions
56
migrations/2024_11_12_073145_add_json_type_to_custom_field_plain_types_table.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Str; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
$exists = DB::table('custom_field_plain_types')->where('name', 'json')->exists(); | ||
if ($exists) { | ||
// already exists | ||
return; | ||
} | ||
|
||
$types = ['json']; | ||
|
||
$plainTypes = []; | ||
foreach ($types as $type) { | ||
if (config('asseco-custom-fields.migrations.uuid')) { | ||
$plainTypes[] = [ | ||
'id' => Str::uuid(), | ||
'name' => $type, | ||
'created_at' => now(), | ||
'updated_at' => now(), | ||
]; | ||
} else { | ||
$plainTypes[] = [ | ||
'name' => $type, | ||
'created_at' => now(), | ||
'updated_at' => now(), | ||
]; | ||
} | ||
} | ||
|
||
DB::table('custom_field_plain_types')->insert($plainTypes); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
DB::table('custom_field_plain_types') | ||
->where('name', 'json') | ||
->delete(); | ||
} | ||
}; |
32 changes: 32 additions & 0 deletions
32
migrations/2024_11_12_073245_add_json_to_custom_field_values_table.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('custom_field_values', function (Blueprint $table) { | ||
$table->json('json')->nullable()->default(null)->after('time'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('custom_field_values', function (Blueprint $table) { | ||
$table->dropColumn('json'); | ||
}); | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Asseco\CustomFields\App\Contracts\PlainTypes; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @mixin Model|\Asseco\CustomFields\App\PlainTypes\TimeType | ||
*/ | ||
interface JsonType | ||
{ | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Asseco\CustomFields\App\PlainTypes; | ||
|
||
use Asseco\CustomFields\App\Contracts\Mappable; | ||
use Asseco\CustomFields\App\Models\PlainType; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
class JsonType extends PlainType implements Mappable, \Asseco\CustomFields\App\Contracts\PlainTypes\JsonType | ||
{ | ||
protected static function booted() | ||
{ | ||
static::addGlobalScope('name', function (Builder $builder) { | ||
$builder->where('name', 'json'); | ||
}); | ||
} | ||
|
||
public static function mapToValueColumn(): string | ||
{ | ||
return 'json'; | ||
} | ||
} |