mirror of
https://github.com/twinpath/app.git
synced 2026-01-26 05:15:28 +07:00
Initial commit
This commit is contained in:
1
database/.gitignore
vendored
Normal file
1
database/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
31
database/factories/ApiKeyFactory.php
Normal file
31
database/factories/ApiKeyFactory.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\ApiKey;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ApiKeyFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = ApiKey::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->words(3, true),
|
||||
'key' => Str::random(64),
|
||||
'last_used_at' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
45
database/factories/UserFactory.php
Normal file
45
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'first_name' => fake()->firstName(),
|
||||
'last_name' => fake()->lastName(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
158
database/install.sql
Normal file
158
database/install.sql
Normal file
@@ -0,0 +1,158 @@
|
||||
-- Database Export for Direct Import (e.g., cPanel/phpMyAdmin)
|
||||
-- Includes Schema and Initial Data (Roles & Admin User)
|
||||
|
||||
-- Table structure for `roles`
|
||||
CREATE TABLE `roles` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`label` varchar(255) NOT NULL,
|
||||
`created_at` timestamp NULL DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `roles_name_unique` (`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
INSERT INTO `roles` (`id`, `name`, `label`, `created_at`, `updated_at`) VALUES
|
||||
(1, 'admin', 'Administrator', NOW(), NOW()),
|
||||
(2, 'customer', 'Customer', NOW(), NOW());
|
||||
|
||||
-- Table structure for `users`
|
||||
CREATE TABLE `users` (
|
||||
`id` varchar(32) NOT NULL,
|
||||
`first_name` varchar(255) NOT NULL,
|
||||
`last_name` varchar(255) DEFAULT NULL,
|
||||
`email` varchar(255) NOT NULL,
|
||||
`email_verified_at` timestamp NULL DEFAULT NULL,
|
||||
`password` varchar(255) DEFAULT NULL,
|
||||
`status` varchar(255) NOT NULL DEFAULT 'active',
|
||||
`phone` varchar(255) DEFAULT NULL,
|
||||
`bio` text DEFAULT NULL,
|
||||
`avatar` varchar(255) DEFAULT NULL,
|
||||
`country` varchar(255) DEFAULT NULL,
|
||||
`city_state` varchar(255) DEFAULT NULL,
|
||||
`postal_code` varchar(255) DEFAULT NULL,
|
||||
`tax_id` varchar(255) DEFAULT NULL,
|
||||
`facebook` varchar(255) DEFAULT NULL,
|
||||
`x_link` varchar(255) DEFAULT NULL,
|
||||
`linkedin` varchar(255) DEFAULT NULL,
|
||||
`instagram` varchar(255) DEFAULT NULL,
|
||||
`google_id` varchar(255) DEFAULT NULL,
|
||||
`google_token` text DEFAULT NULL,
|
||||
`google_refresh_token` text DEFAULT NULL,
|
||||
`github_id` varchar(255) DEFAULT NULL,
|
||||
`github_token` text DEFAULT NULL,
|
||||
`github_refresh_token` text DEFAULT NULL,
|
||||
`remember_token` varchar(100) DEFAULT NULL,
|
||||
`role_id` bigint(20) unsigned DEFAULT NULL,
|
||||
`created_at` timestamp NULL DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `users_email_unique` (`email`),
|
||||
KEY `users_role_id_foreign` (`role_id`),
|
||||
CONSTRAINT `users_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Admin User (Password: password)
|
||||
INSERT INTO `users` (`id`, `first_name`, `last_name`, `email`, `password`, `role_id`, `status`, `created_at`, `updated_at`) VALUES
|
||||
('ADMIN000000000000000000000000001', 'Admin', 'User', 'admin@dyzulk.com', '$2y$12$R.SjA7Gk/9l7HlA.zC6iGOJbA5HkXfLrTYDR.SjA7Gk/9l7HlA.zC6iG', 1, 'active', NOW(), NOW());
|
||||
|
||||
-- Table structure for `api_keys`
|
||||
CREATE TABLE `api_keys` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`user_id` varchar(32) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`key` varchar(64) NOT NULL,
|
||||
`is_active` tinyint(1) NOT NULL DEFAULT 1,
|
||||
`last_used_at` timestamp NULL DEFAULT NULL,
|
||||
`created_at` timestamp NULL DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `api_keys_key_unique` (`key`),
|
||||
KEY `api_keys_user_id_foreign` (`user_id`),
|
||||
CONSTRAINT `api_keys_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `ca_certificates`
|
||||
CREATE TABLE `ca_certificates` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`uuid` char(36) NOT NULL,
|
||||
`ca_type` varchar(255) NOT NULL,
|
||||
`cert_content` text NOT NULL,
|
||||
`key_content` text NOT NULL,
|
||||
`serial_number` varchar(255) DEFAULT NULL,
|
||||
`common_name` varchar(255) DEFAULT NULL,
|
||||
`organization` varchar(255) DEFAULT NULL,
|
||||
`valid_from` datetime DEFAULT NULL,
|
||||
`valid_to` datetime DEFAULT NULL,
|
||||
`created_at` timestamp NULL DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `ca_certificates_uuid_unique` (`uuid`),
|
||||
UNIQUE KEY `ca_certificates_ca_type_unique` (`ca_type`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `certificates`
|
||||
CREATE TABLE `certificates` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`uuid` char(36) NOT NULL,
|
||||
`user_id` varchar(32) NOT NULL,
|
||||
`common_name` varchar(255) NOT NULL,
|
||||
`organization` varchar(255) DEFAULT NULL,
|
||||
`locality` varchar(255) DEFAULT NULL,
|
||||
`state` varchar(255) DEFAULT NULL,
|
||||
`country` varchar(10) DEFAULT NULL,
|
||||
`san` text DEFAULT NULL,
|
||||
`key_bits` int(11) NOT NULL DEFAULT 2048,
|
||||
`serial_number` varchar(255) NOT NULL,
|
||||
`cert_content` text NOT NULL,
|
||||
`key_content` text NOT NULL,
|
||||
`csr_content` text DEFAULT NULL,
|
||||
`valid_from` timestamp NULL DEFAULT NULL,
|
||||
`valid_to` timestamp NULL DEFAULT NULL,
|
||||
`created_at` timestamp NULL DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `certificates_uuid_unique` (`uuid`),
|
||||
UNIQUE KEY `certificates_serial_number_unique` (`serial_number`),
|
||||
KEY `certificates_user_id_foreign` (`user_id`),
|
||||
CONSTRAINT `certificates_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `cache`, `jobs`, `sessions`, etc.
|
||||
CREATE TABLE `cache` (
|
||||
`key` varchar(255) NOT NULL,
|
||||
`value` mediumtext NOT NULL,
|
||||
`expiration` int(11) NOT NULL,
|
||||
PRIMARY KEY (`key`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `sessions` (
|
||||
`id` varchar(255) NOT NULL,
|
||||
`user_id` varchar(32) DEFAULT NULL,
|
||||
`ip_address` varchar(45) DEFAULT NULL,
|
||||
`user_agent` text DEFAULT NULL,
|
||||
`payload` longtext NOT NULL,
|
||||
`last_activity` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `sessions_user_id_index` (`user_id`),
|
||||
KEY `sessions_last_activity_index` (`last_activity`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `migrations` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`migration` varchar(255) NOT NULL,
|
||||
`batch` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES
|
||||
(1,'0000_00_00_000000_create_roles_table',1),
|
||||
(2,'0001_01_01_000000_create_users_table',1),
|
||||
(3,'0001_01_01_000001_create_cache_table',1),
|
||||
(4,'0001_01_01_000002_create_jobs_table',1),
|
||||
(5,'2025_12_21_051706_create_ca_certificates_table',1),
|
||||
(6,'2025_12_21_051735_create_certificates_table',1),
|
||||
(7,'2025_12_21_161950_create_login_histories_table',1),
|
||||
(8,'2025_12_22_012656_add_status_to_users_table',1),
|
||||
(9,'2025_12_22_025212_create_api_keys_table',1),
|
||||
(10,'2025_12_22_030724_add_is_active_to_api_keys_table',1);
|
||||
29
database/migrations/0000_00_00_000000_create_roles_table.php
Normal file
29
database/migrations/0000_00_00_000000_create_roles_table.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->string('label');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('roles');
|
||||
}
|
||||
};
|
||||
83
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
83
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->string('id', 32)->primary();
|
||||
|
||||
// Personal Information
|
||||
$table->string('first_name');
|
||||
$table->string('last_name')->nullable();
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password')->nullable();
|
||||
$table->string('phone')->nullable();
|
||||
$table->text('bio')->nullable();
|
||||
|
||||
// Avatar
|
||||
$table->string('avatar')->nullable();
|
||||
|
||||
// Address Information
|
||||
$table->string('country')->nullable();
|
||||
$table->string('city_state')->nullable();
|
||||
$table->string('postal_code')->nullable();
|
||||
$table->string('tax_id')->nullable();
|
||||
|
||||
// Social Links
|
||||
$table->string('facebook')->nullable();
|
||||
$table->string('x_link')->nullable();
|
||||
$table->string('linkedin')->nullable();
|
||||
$table->string('instagram')->nullable();
|
||||
|
||||
// Social Auth - Google
|
||||
$table->string('google_id')->nullable();
|
||||
$table->text('google_token')->nullable();
|
||||
$table->text('google_refresh_token')->nullable();
|
||||
|
||||
// Social Auth - GitHub
|
||||
$table->string('github_id')->nullable();
|
||||
$table->text('github_token')->nullable();
|
||||
$table->text('github_refresh_token')->nullable();
|
||||
|
||||
|
||||
|
||||
$table->rememberToken();
|
||||
$table->foreignId('role_id')->nullable()->constrained('roles')->onDelete('set null');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('user_id', 32)->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
||||
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
||||
57
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
57
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('ca_certificates', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->unique();
|
||||
$table->string('ca_type')->unique();
|
||||
$table->text('cert_content');
|
||||
$table->text('key_content');
|
||||
$table->string('serial_number')->nullable();
|
||||
$table->string('common_name')->nullable();
|
||||
$table->string('organization')->nullable();
|
||||
$table->dateTime('valid_from')->nullable();
|
||||
$table->dateTime('valid_to')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('ca_certificates');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('certificates', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->unique();
|
||||
$table->string('user_id', 32);
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->string('common_name');
|
||||
$table->string('organization')->nullable();
|
||||
$table->string('locality')->nullable();
|
||||
$table->string('state')->nullable();
|
||||
$table->string('country', 10)->nullable();
|
||||
$table->text('san')->nullable();
|
||||
$table->integer('key_bits')->default(2048);
|
||||
$table->string('serial_number')->unique();
|
||||
$table->text('cert_content');
|
||||
$table->text('key_content');
|
||||
$table->text('csr_content')->nullable();
|
||||
$table->timestamp('valid_from')->nullable();
|
||||
$table->timestamp('valid_to')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('certificates');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('login_histories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('user_id');
|
||||
$table->string('ip_address')->nullable();
|
||||
$table->string('user_agent')->nullable();
|
||||
$table->string('provider')->default('credentials');
|
||||
$table->timestamp('login_at')->useCurrent();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('login_histories');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('status')->default('active')->after('password');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('status');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('api_keys', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignUuid('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('name');
|
||||
$table->string('key', 64)->unique();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('api_keys');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('api_keys', function (Blueprint $table) {
|
||||
$table->boolean('is_active')->default(true)->after('key');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('api_keys', function (Blueprint $table) {
|
||||
$table->dropColumn('is_active');
|
||||
});
|
||||
}
|
||||
};
|
||||
62
database/seeders/DatabaseSeeder.php
Normal file
62
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// Create Roles
|
||||
$adminRole = \App\Models\Role::firstOrCreate(
|
||||
['name' => 'admin'],
|
||||
['label' => 'Administrator']
|
||||
);
|
||||
|
||||
$customerRole = \App\Models\Role::firstOrCreate(
|
||||
['name' => 'customer'],
|
||||
['label' => 'Customer']
|
||||
);
|
||||
|
||||
// Create Admin User
|
||||
// Create Admin User
|
||||
User::firstOrCreate(
|
||||
['email' => 'admin@dyzulk.com'],
|
||||
[
|
||||
'first_name' => 'Admin',
|
||||
'last_name' => 'User',
|
||||
'password' => \Illuminate\Support\Facades\Hash::make('password'),
|
||||
'role_id' => $adminRole->id,
|
||||
'email_verified_at' => now(),
|
||||
]
|
||||
);
|
||||
|
||||
// Create Regular User
|
||||
// Create Regular User
|
||||
User::firstOrCreate(
|
||||
['email' => 'test@example.com'],
|
||||
[
|
||||
'first_name' => 'Test',
|
||||
'last_name' => 'User',
|
||||
'password' => \Illuminate\Support\Facades\Hash::make('password'),
|
||||
'role_id' => $customerRole->id,
|
||||
]
|
||||
);
|
||||
|
||||
// Create specific test user for password reset
|
||||
// User::firstOrCreate(
|
||||
// ['email' => 'santulitam2024@gmail.com'],
|
||||
// [
|
||||
// 'first_name' => 'Santul',
|
||||
// 'last_name' => 'Itam',
|
||||
// 'password' => \Illuminate\Support\Facades\Hash::make('password'),
|
||||
// 'role_id' => $customerRole->id,
|
||||
// ]
|
||||
// );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user