first commit
This commit is contained in:
75
app/Models/Column.php
Normal file
75
app/Models/Column.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Column extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'table_id',
|
||||
'column_name',
|
||||
'data_type',
|
||||
'udt_name',
|
||||
'ordinal_position',
|
||||
'is_nullable',
|
||||
'column_default',
|
||||
'character_maximum_length',
|
||||
'numeric_precision',
|
||||
'numeric_scale',
|
||||
'datetime_precision',
|
||||
'comment',
|
||||
'is_primary_key',
|
||||
'is_foreign_key',
|
||||
'is_indexed',
|
||||
'target_column_name',
|
||||
'target_data_type',
|
||||
'exclude_from_migration',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'ordinal_position' => 'integer',
|
||||
'is_nullable' => 'boolean',
|
||||
'is_primary_key' => 'boolean',
|
||||
'is_foreign_key' => 'boolean',
|
||||
'is_indexed' => 'boolean',
|
||||
'exclude_from_migration' => 'boolean',
|
||||
'character_maximum_length' => 'integer',
|
||||
'numeric_precision' => 'integer',
|
||||
'numeric_scale' => 'integer',
|
||||
];
|
||||
|
||||
public function table(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Table::class);
|
||||
}
|
||||
|
||||
public function getFullTypeAttribute(): string
|
||||
{
|
||||
$type = $this->data_type;
|
||||
|
||||
if ($this->character_maximum_length) {
|
||||
$type .= "({$this->character_maximum_length})";
|
||||
} elseif ($this->numeric_precision && $this->numeric_scale) {
|
||||
$type .= "({$this->numeric_precision},{$this->numeric_scale})";
|
||||
} elseif ($this->numeric_precision) {
|
||||
$type .= "({$this->numeric_precision})";
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
public function getEffectiveColumnNameAttribute(): string
|
||||
{
|
||||
return $this->target_column_name ?? $this->column_name;
|
||||
}
|
||||
|
||||
public function getEffectiveDataTypeAttribute(): string
|
||||
{
|
||||
return $this->target_data_type ?? $this->data_type;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user