From ae4937654dbab207205a0dd02ecb5417e8f6b01c Mon Sep 17 00:00:00 2001 From: boban Date: Sat, 20 Jun 2026 23:59:11 +0200 Subject: [PATCH] feat(wg): wg_traffic_samples table + model --- app/Models/WgTrafficSample.php | 18 +++++++++++++ ...000010_create_wg_traffic_samples_table.php | 26 +++++++++++++++++++ tests/Feature/WgTrafficSampleTest.php | 23 ++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 app/Models/WgTrafficSample.php create mode 100644 database/migrations/2026_06_20_000010_create_wg_traffic_samples_table.php create mode 100644 tests/Feature/WgTrafficSampleTest.php diff --git a/app/Models/WgTrafficSample.php b/app/Models/WgTrafficSample.php new file mode 100644 index 0000000..e96959b --- /dev/null +++ b/app/Models/WgTrafficSample.php @@ -0,0 +1,18 @@ + 'integer', + 'tx' => 'integer', + 'sampled_at' => 'datetime', + ]; +} diff --git a/database/migrations/2026_06_20_000010_create_wg_traffic_samples_table.php b/database/migrations/2026_06_20_000010_create_wg_traffic_samples_table.php new file mode 100644 index 0000000..229b88a --- /dev/null +++ b/database/migrations/2026_06_20_000010_create_wg_traffic_samples_table.php @@ -0,0 +1,26 @@ +id(); + $table->string('peer_pubkey'); + $table->string('peer_name')->nullable(); + $table->unsignedBigInteger('rx')->default(0); + $table->unsignedBigInteger('tx')->default(0); + $table->timestamp('sampled_at')->index(); + $table->index(['peer_pubkey', 'sampled_at']); + }); + } + + public function down(): void + { + Schema::dropIfExists('wg_traffic_samples'); + } +}; diff --git a/tests/Feature/WgTrafficSampleTest.php b/tests/Feature/WgTrafficSampleTest.php new file mode 100644 index 0000000..3b741ea --- /dev/null +++ b/tests/Feature/WgTrafficSampleTest.php @@ -0,0 +1,23 @@ + 'abc', 'peer_name' => 'laptop', 'rx' => 1000, 'tx' => 2000, 'sampled_at' => now(), + ]); + + $this->assertDatabaseHas('wg_traffic_samples', ['peer_pubkey' => 'abc', 'rx' => 1000]); + $this->assertInstanceOf(Carbon::class, $s->fresh()->sampled_at); + } +}