Remove binary attributes from DB, should be json columns
This commit is contained in:
parent
76889728cd
commit
09f2eb8d9d
29
app/Casts/CollectionOrNull.php
Normal file
29
app/Casts/CollectionOrNull.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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 = [
|
||||
|
@ -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',
|
||||
];
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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()
|
||||
|
@ -26,7 +26,7 @@ return new class extends Migration
|
||||
$table->float('amount', 10, 0)->nullable();
|
||||
$table->float('quantity', 10, 0)->nullable();
|
||||
$table->boolean('taxable')->default(true);
|
||||
$table->binary('attributes', 65535)->nullable();
|
||||
$table->jsonb('attributes')->nullable();
|
||||
$table->string('description', 128)->nullable();
|
||||
|
||||
$table->date('start_at')->nullable();
|
||||
|
@ -60,7 +60,7 @@ return new class extends Migration
|
||||
$table->string('host_password',45)->nullable();
|
||||
$table->string('ftp_username',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->integer('service_id')->unsigned();
|
||||
|
@ -27,7 +27,7 @@ return new class extends Migration
|
||||
$table->boolean('print_status')->default(false);
|
||||
$table->integer('account_billing_id')->nullable();
|
||||
$table->float('discount_amt',10,0)->nullable();
|
||||
$table->binary('reminders', 65535)->nullable();
|
||||
$table->jsonb('reminders')->nullable();
|
||||
|
||||
$table->integer('account_id')->unsigned();
|
||||
$table->foreign(['account_id','site_id'])->references(['id','site_id'])->on('accounts');
|
||||
|
@ -20,7 +20,7 @@ return new class extends Migration
|
||||
$table->integer('site_id')->unsigned();
|
||||
|
||||
$table->string('userid',128);
|
||||
$table->binary('oauth_data', 65535)->nullable();
|
||||
$table->jsonb('oauth_data')->nullable();
|
||||
|
||||
$table->integer('user_id')->unsigned()->nullable();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user