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

This commit is contained in:
Deon George 2024-07-07 19:10:00 +10:00
parent d96924bc65
commit 67824d4ab5
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\Database\Eloquent\Model;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use App\Casts\CollectionOrNull;
use App\Traits\SiteID; use App\Traits\SiteID;
/** /**
@ -19,7 +20,7 @@ class Charge extends Model
use SiteID; use SiteID;
protected $casts = [ protected $casts = [
'attributes' => 'json', 'attributes' => CollectionOrNull::class,
]; ];
protected $dates = [ protected $dates = [

View File

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

View File

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

View File

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

View File

@ -26,7 +26,7 @@ return new class extends Migration
$table->float('amount', 10, 0)->nullable(); $table->float('amount', 10, 0)->nullable();
$table->float('quantity', 10, 0)->nullable(); $table->float('quantity', 10, 0)->nullable();
$table->boolean('taxable')->default(true); $table->boolean('taxable')->default(true);
$table->binary('attributes', 65535)->nullable(); $table->jsonb('attributes')->nullable();
$table->string('description', 128)->nullable(); $table->string('description', 128)->nullable();
$table->date('start_at')->nullable(); $table->date('start_at')->nullable();

View File

@ -60,7 +60,7 @@ return new class extends Migration
$table->string('host_password',45)->nullable(); $table->string('host_password',45)->nullable();
$table->string('ftp_username',16)->nullable(); $table->string('ftp_username',16)->nullable();
$table->string('ftp_password',16)->nullable(); $table->string('ftp_password',16)->nullable();
$table->binary('server_data',65535)->nullable(); $table->jsonb('server_data')->nullable();
$table->date('expire_at')->nullable(); $table->date('expire_at')->nullable();
$table->integer('service_id')->unsigned(); $table->integer('service_id')->unsigned();

View File

@ -27,7 +27,7 @@ return new class extends Migration
$table->boolean('print_status')->default(false); $table->boolean('print_status')->default(false);
$table->integer('account_billing_id')->nullable(); $table->integer('account_billing_id')->nullable();
$table->float('discount_amt',10,0)->nullable(); $table->float('discount_amt',10,0)->nullable();
$table->binary('reminders', 65535)->nullable(); $table->jsonb('reminders')->nullable();
$table->integer('account_id')->unsigned(); $table->integer('account_id')->unsigned();
$table->foreign(['account_id','site_id'])->references(['id','site_id'])->on('accounts'); $table->foreign(['account_id','site_id'])->references(['id','site_id'])->on('accounts');

View File

@ -20,7 +20,7 @@ return new class extends Migration
$table->integer('site_id')->unsigned(); $table->integer('site_id')->unsigned();
$table->string('userid',128); $table->string('userid',128);
$table->binary('oauth_data', 65535)->nullable(); $table->jsonb('oauth_data')->nullable();
$table->integer('user_id')->unsigned()->nullable(); $table->integer('user_id')->unsigned()->nullable();