Skip to content

Commit d7c010e

Browse files
committed
use the facade methods directly, not as a constant
1 parent bd59e87 commit d7c010e

File tree

1 file changed

+60
-30
lines changed

1 file changed

+60
-30
lines changed

migrations/2024_01_01_000000_create_developer_logs_table.php

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,61 @@ public function up(): void
1414
$tableName = config('devlogger.table_name', 'developer_logs');
1515
$connection = config('devlogger.database_connection', null);
1616

17-
$schema = $connection ? Schema::connection($connection) : Schema;
18-
19-
$schema->create($tableName, function (Blueprint $table) {
20-
$table->id();
21-
$table->string('level')->index();
22-
$table->string('queue')->nullable()->index();
23-
$table->longText('log');
24-
$table->json('context')->nullable();
25-
$table->string('file_path')->nullable();
26-
$table->integer('line_number')->nullable();
27-
$table->string('exception_class')->nullable()->index();
28-
$table->longText('stack_trace')->nullable();
29-
$table->string('request_url')->nullable();
30-
$table->string('request_method', 10)->nullable();
31-
$table->unsignedBigInteger('user_id')->nullable()->index();
32-
$table->string('ip_address', 45)->nullable();
33-
$table->text('user_agent')->nullable();
34-
$table->string('status')->default('open')->index();
35-
$table->json('tags')->nullable();
36-
$table->unsignedBigInteger('updated_by')->nullable();
37-
$table->timestamps();
38-
$table->softDeletes();
17+
if ($connection) {
18+
Schema::connection($connection)->create($tableName, function (Blueprint $table) {
19+
$table->id();
20+
$table->string('level')->index();
21+
$table->string('queue')->nullable()->index();
22+
$table->longText('log');
23+
$table->json('context')->nullable();
24+
$table->string('file_path')->nullable();
25+
$table->integer('line_number')->nullable();
26+
$table->string('exception_class')->nullable()->index();
27+
$table->longText('stack_trace')->nullable();
28+
$table->string('request_url')->nullable();
29+
$table->string('request_method', 10)->nullable();
30+
$table->unsignedBigInteger('user_id')->nullable()->index();
31+
$table->string('ip_address', 45)->nullable();
32+
$table->text('user_agent')->nullable();
33+
$table->string('status')->default('open')->index();
34+
$table->json('tags')->nullable();
35+
$table->unsignedBigInteger('updated_by')->nullable();
36+
$table->timestamps();
37+
$table->softDeletes();
38+
39+
// Add indexes for better performance
40+
$table->index(['level', 'created_at']);
41+
$table->index(['status', 'created_at']);
42+
$table->index('created_at');
43+
});
44+
} else {
45+
Schema::create($tableName, function (Blueprint $table) {
46+
$table->id();
47+
$table->string('level')->index();
48+
$table->string('queue')->nullable()->index();
49+
$table->longText('log');
50+
$table->json('context')->nullable();
51+
$table->string('file_path')->nullable();
52+
$table->integer('line_number')->nullable();
53+
$table->string('exception_class')->nullable()->index();
54+
$table->longText('stack_trace')->nullable();
55+
$table->string('request_url')->nullable();
56+
$table->string('request_method', 10)->nullable();
57+
$table->unsignedBigInteger('user_id')->nullable()->index();
58+
$table->string('ip_address', 45)->nullable();
59+
$table->text('user_agent')->nullable();
60+
$table->string('status')->default('open')->index();
61+
$table->json('tags')->nullable();
62+
$table->unsignedBigInteger('updated_by')->nullable();
63+
$table->timestamps();
64+
$table->softDeletes();
3965

40-
// Add indexes for better performance
41-
$table->index(['level', 'created_at']);
42-
$table->index(['status', 'created_at']);
43-
$table->index('created_at');
44-
});
66+
// Add indexes for better performance
67+
$table->index(['level', 'created_at']);
68+
$table->index(['status', 'created_at']);
69+
$table->index('created_at');
70+
});
71+
}
4572
}
4673

4774
/**
@@ -52,8 +79,11 @@ public function down(): void
5279
$tableName = config('devlogger.table_name', 'developer_logs');
5380
$connection = config('devlogger.database_connection', null);
5481

55-
$schema = $connection ? Schema::connection($connection) : Schema;
56-
57-
$schema->dropIfExists($tableName);
82+
if ($connection) {
83+
Schema::connection($connection)->dropIfExists($tableName);
84+
} else {
85+
$table->id();
86+
Schema::dropIfExists($tableName);
87+
}
5888
}
5989
};

0 commit comments

Comments
 (0)