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); + } +}