implement uuid and make sample data factory
This commit is contained in:
@ -17,7 +17,7 @@ class DeviceFactory extends Factory
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'device_id' => $this->faker->randomDigitNotNull(),
|
||||
'device_id' => $this->faker->uuid(),
|
||||
'title' => $this->faker->word(),
|
||||
'device_type' => $this->faker->domainWord(),
|
||||
'description' => $this->faker->sentence(),
|
||||
|
24
device-app/database/factories/LocationTransactionFactory.php
Normal file
24
device-app/database/factories/LocationTransactionFactory.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\LocationTransaction>
|
||||
*/
|
||||
class LocationTransactionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'room_code' => $this->faker->buildingNumber(),
|
||||
'timestamp_located_since' => $this->faker->unixTime()
|
||||
];
|
||||
}
|
||||
}
|
24
device-app/database/factories/OwnerTransactionFactory.php
Normal file
24
device-app/database/factories/OwnerTransactionFactory.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\OwnerTransaction>
|
||||
*/
|
||||
class OwnerTransactionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'rz_username' => $this->faker->name(),
|
||||
'timestamp_owner_since' => $this->faker->unixTime()
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PurchasingInformation>
|
||||
*/
|
||||
class PurchasingInformationFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'price' => $this->faker->word(),
|
||||
'timestamp_warranty_end' => $this->faker->unixTime(),
|
||||
'timestamp_purchase' => $this->faker->unixTime(),
|
||||
'cost_centre' => $this->faker->numberBetween(1000000000, 9999999999),
|
||||
'seller' => $this->faker->company()
|
||||
];
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ return new class extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('devices', function (Blueprint $table) {
|
||||
$table->string('device_id')->unique();
|
||||
$table->uuid('device_id')->primary();
|
||||
$table->string('title');
|
||||
$table->string('device_type');
|
||||
$table->string('description')->nullable();
|
||||
|
@ -12,11 +12,10 @@ return new class extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('location_transactions', function (Blueprint $table) {
|
||||
$table->string('location_transaction_id')->unique();
|
||||
$table->uuid('location_transaction_id')->primary();
|
||||
$table->string('room_code');
|
||||
$table->string('timestamp_located_since');
|
||||
$table->string('device_id');
|
||||
$table->foreign('device_id')->references('device_id')->on('devices');
|
||||
$table->foreignUUid('device_id')->references('device_id')->on('devices')->cascadeOnUpdate()->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -12,11 +12,10 @@ return new class extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('owner_transactions', function (Blueprint $table) {
|
||||
$table->string('owner_transaction_id')->unique();
|
||||
$table->uuid('owner_transaction_id')->primary();
|
||||
$table->string('rz_username');
|
||||
$table->string('timestamp_owner_since');
|
||||
$table->string('device_id');
|
||||
$table->foreign('device_id')->references('device_id')->on('devices');
|
||||
$table->foreignUuid('device_id')->references('device_id')->on('devices')->cascadeOnUpdate()->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -12,14 +12,13 @@ return new class extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('purchasing_information', function (Blueprint $table) {
|
||||
$table->string('purchasing_information_id')->unique();
|
||||
$table->uuid('purchasing_information_id')->primary();
|
||||
$table->string('price');
|
||||
$table->string('timestamp_warranty_end');
|
||||
$table->string('timestamp_purchase');
|
||||
$table->string('cost_centre');
|
||||
$table->string('seller')->nullable();
|
||||
$table->string('device_id');
|
||||
$table->foreign('device_id')->references('device_id')->on('devices');
|
||||
$table->foreignUuid('device_id')->references('device_id')->on('devices')->cascadeOnUpdate()->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -25,12 +25,15 @@ class DatabaseSeeder extends Seeder
|
||||
// 'email' => 'test@example.com',
|
||||
// ]);
|
||||
|
||||
Device::factory(1)->create([
|
||||
'device_id' => '1'
|
||||
]);
|
||||
//Device::factory()->has(PurchasingInformation::factory()->count(1))->create();
|
||||
|
||||
Device::factory()->count(10)
|
||||
->has(PurchasingInformation::factory()->count(1), 'purchasing')
|
||||
->has(LocationTransaction::factory()->count(3), 'locations')
|
||||
->has(OwnerTransaction::factory()->count(3), 'owners')
|
||||
->create();
|
||||
|
||||
User::create([
|
||||
|
||||
'rz_username' => 'admin',
|
||||
'full_name' => 'Admin',
|
||||
'organisation_unit' => '11111111',
|
||||
@ -45,29 +48,5 @@ class DatabaseSeeder extends Seeder
|
||||
'has_admin_privileges' => false,
|
||||
'hashed_password' => bcrypt('test123')
|
||||
]);
|
||||
|
||||
PurchasingInformation::create([
|
||||
'purchasing_information_id' => '1',
|
||||
'price' => '1',
|
||||
'timestamp_warranty_end' => '1',
|
||||
'timestamp_purchase' => '1',
|
||||
'cost_centre' => '1',
|
||||
'seller' => '1',
|
||||
'device_id' => '1',
|
||||
]);
|
||||
|
||||
LocationTransaction::create([
|
||||
'location_transaction_id' => '1',
|
||||
'room_code' => '1',
|
||||
'timestamp_located_since' => '1',
|
||||
'device_id' => '1',
|
||||
]);
|
||||
|
||||
OwnerTransaction::create([
|
||||
'owner_transaction_id' => '1',
|
||||
'rz_username' => '1',
|
||||
'timestamp_owner_since' => '1',
|
||||
'device_id' => '1',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user