Remove binary attributes from DB, should be json columns
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 33s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s

This commit is contained in:
2024-07-07 19:10:00 +10:00
parent 76889728cd
commit 09f2eb8d9d
9 changed files with 46 additions and 8 deletions

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;
class CollectionOrNull implements CastsAttributes
{
/**
* Cast the given value.
*
* @param array<string, mixed> $attributes
*/
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
{
return collect(json_decode($value, true));
}
/**
* Prepare the given value for storage.
*
* @param array<string, mixed> $attributes
*/
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
{
return $value->count() ? json_encode($value) : NULL;
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use App\Casts\CollectionOrNull;
use App\Traits\SiteID;
/**
@@ -19,7 +20,7 @@ class Charge extends Model
use SiteID;
protected $casts = [
'attributes' => 'json',
'attributes' => CollectionOrNull::class,
];
protected $dates = [

View File

@@ -7,8 +7,10 @@ use Clarkeash\Doorman\Facades\Doorman;
use Clarkeash\Doorman\Models\Invite;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Leenooks\Casts\LeenooksCarbon;
use Leenooks\Traits\ScopeActive;
use App\Casts\CollectionOrNull;
use App\Interfaces\IDs;
use App\Traits\PushNew;
@@ -37,8 +39,8 @@ class Invoice extends Model implements IDs
protected $casts = [
'created_at' => 'datetime:Y-m-d',
'due_at' => 'datetime:Y-m-d',
'reminders' => 'json',
'due_at' => LeenooksCarbon::class,
'reminders' => CollectionOrNull::class,
'_paid_at' => 'datetime:Y-m-d',
];

View File

@@ -2,6 +2,7 @@
namespace App\Models\Service;
use App\Casts\CollectionOrNull;
use App\Models\SupplierHostServer;
use App\Traits\ServiceDomains;
@@ -13,6 +14,10 @@ class Host extends Type
{
use ServiceDomains;
protected $casts = [
'server_data' => CollectionOrNull::class,
];
protected $table = 'service_host';
protected $with = [
'tld',

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Casts\CollectionOrNull;
use App\Traits\SiteID;
class UserOauth extends Model
@@ -13,7 +14,7 @@ class UserOauth extends Model
protected $table = 'user_oauth';
protected $casts = [
'oauth_data'=>'json',
'oauth_data' => CollectionOrNull::class,
];
public function User()