Skip to content

Commit db07dff

Browse files
committed
Move model defaults to db migration
1 parent 613e77a commit db07dff

7 files changed

Lines changed: 70 additions & 40 deletions

File tree

app/Models/AlertRule.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ protected static function booted(): void
7171
'extra' => 'array',
7272
];
7373

74-
protected $attributes = [
75-
'extra' => '{}',
76-
'builder' => '{}',
77-
'query' => '',
78-
];
79-
8074
// ---- Query scopes ----
8175

8276
/**

app/Models/Bill.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,6 @@ class Bill extends BaseModel
4646
'bill_notes',
4747
];
4848

49-
protected $attributes = [
50-
'rate_95th_in' => 0,
51-
'rate_95th_out' => 0,
52-
'rate_95th' => 0,
53-
'dir_95th' => 'in',
54-
'total_data' => 0,
55-
'total_data_in' => 0,
56-
'total_data_out' => 0,
57-
'rate_average_in' => 0,
58-
'rate_average_out' => 0,
59-
'rate_average' => 0,
60-
'bill_last_calc' => '1970-01-01 00:00:00',
61-
'bill_custid' => '',
62-
'bill_ref' => '',
63-
'bill_notes' => '',
64-
'bill_autoadded' => 0,
65-
];
66-
6749
// ---- Query Scopes ----
6850

6951
public function scopeHasAccess(Builder $query, User $user): Builder

app/Models/Mempool.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ class Mempool extends DeviceRelatedModel implements Keyable
3636
'mempool_largestfree',
3737
'mempool_lowestfree',
3838
];
39-
protected $attributes = [
40-
'mempool_precision' => 1,
41-
];
4239

4340
public function __construct(array $attributes = [])
4441
{

app/Models/ServiceTemplate.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ class ServiceTemplate extends BaseModel
5353
'name',
5454
];
5555

56-
protected $attributes = [ // default values
57-
'ignore' => '0',
58-
'disabled' => '0',
59-
];
60-
6156
public static function boot()
6257
{
6358
parent::boot();

app/Models/Sla.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ class Sla extends DeviceRelatedModel implements Keyable
2121
'opstatus',
2222
'deleted',
2323
];
24-
protected $attributes = [ // default values
25-
'deleted' => 0,
26-
];
2724

2825
public function getCompositeKey(): string
2926
{

app/Models/User.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ class User extends Authenticatable
3232
protected $primaryKey = 'user_id';
3333
protected $fillable = ['realname', 'username', 'email', 'descr', 'can_modify_passwd', 'auth_type', 'auth_id', 'enabled'];
3434
protected $hidden = ['password', 'remember_token', 'pivot'];
35-
protected $attributes = [ // default values
36-
'descr' => '',
37-
'realname' => '',
38-
'email' => '',
39-
];
4035
protected $dispatchesEvents = [
4136
'created' => UserCreated::class,
4237
];
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::table('alert_rules', function (Blueprint $table) {
12+
$table->string('extra')->default('{}')->change();
13+
$table->text('builder')->default('{}')->change();
14+
$table->text('query')->default('')->change();
15+
});
16+
17+
Schema::table('bills', function (Blueprint $table) {
18+
foreach ([
19+
'rate_95th_in', 'rate_95th_out', 'rate_95th',
20+
'total_data', 'total_data_in', 'total_data_out',
21+
'rate_average_in', 'rate_average_out', 'rate_average',
22+
] as $col) {
23+
$table->bigInteger($col)->default(0)->change();
24+
}
25+
$table->string('dir_95th', 3)->default('in')->change();
26+
$table->dateTime('bill_last_calc')->default('1970-01-01 00:00:00')->change();
27+
$table->string('bill_custid', 64)->default('')->change();
28+
$table->string('bill_ref', 64)->default('')->change();
29+
$table->string('bill_notes', 256)->default('')->change();
30+
$table->boolean('bill_autoadded')->default(0)->change();
31+
});
32+
33+
Schema::table('users', function (Blueprint $table) {
34+
$table->string('realname', 64)->default('')->change();
35+
$table->string('email', 64)->default('')->change();
36+
$table->char('descr', 30)->default('')->change();
37+
});
38+
}
39+
40+
public function down(): void
41+
{
42+
Schema::table('alert_rules', function (Blueprint $table) {
43+
$table->string('extra')->change();
44+
$table->text('builder')->change();
45+
$table->text('query')->change();
46+
});
47+
48+
Schema::table('bills', function (Blueprint $table) {
49+
foreach ([
50+
'rate_95th_in', 'rate_95th_out', 'rate_95th',
51+
'total_data', 'total_data_in', 'total_data_out',
52+
'rate_average_in', 'rate_average_out', 'rate_average',
53+
] as $col) {
54+
$table->bigInteger($col)->change();
55+
}
56+
$table->string('dir_95th', 3)->change();
57+
$table->dateTime('bill_last_calc')->change();
58+
$table->string('bill_custid', 64)->change();
59+
$table->string('bill_ref', 64)->change();
60+
$table->string('bill_notes', 256)->change();
61+
$table->boolean('bill_autoadded')->change();
62+
});
63+
64+
Schema::table('users', function (Blueprint $table) {
65+
$table->string('realname', 64)->change();
66+
$table->string('email', 64)->change();
67+
$table->char('descr', 30)->change();
68+
});
69+
}
70+
};

0 commit comments

Comments
 (0)