From 10f9a2b82ff64d98dcc681a1d22d5fee4cc13b5a Mon Sep 17 00:00:00 2001 From: ricky rx Date: Mon, 20 May 2024 13:28:29 +0700 Subject: [PATCH] adjustment: DB changes based on meeting 20240520 --- .../{TvAppInfo.php => KIV_TvAppInfo.php} | 4 +- ...{TvConnectLog.php => KIV_TvConnectLog.php} | 4 +- .../{TvSession.php => KIV_TvSession.php} | 4 +- app/Models/NewTvRequest.php | 12 +++ app/Models/Tv.php | 39 ++++++++++ ...01_outlet.php => 2024_05_18_033101_outlet} | 0 database/migrations/2024_05_18_033105_tv.php | 78 +++++++++++-------- ..._sts_log.php => 2024_05_18_033128_sts_log} | 0 8 files changed, 101 insertions(+), 40 deletions(-) rename app/Models/{TvAppInfo.php => KIV_TvAppInfo.php} (89%) rename app/Models/{TvConnectLog.php => KIV_TvConnectLog.php} (87%) rename app/Models/{TvSession.php => KIV_TvSession.php} (86%) create mode 100644 app/Models/NewTvRequest.php rename database/migrations/{2024_05_18_033101_outlet.php => 2024_05_18_033101_outlet} (100%) rename database/migrations/{2024_05_18_033128_sts_log.php => 2024_05_18_033128_sts_log} (100%) diff --git a/app/Models/TvAppInfo.php b/app/Models/KIV_TvAppInfo.php similarity index 89% rename from app/Models/TvAppInfo.php rename to app/Models/KIV_TvAppInfo.php index edb3d23..c832606 100644 --- a/app/Models/TvAppInfo.php +++ b/app/Models/KIV_TvAppInfo.php @@ -14,9 +14,9 @@ class TvAppInfo extends Model { public $incrementing = false; //------------------------------------------------------------ - // -- RELATED TO MIGRATION + // -- RELATED TO RELATIONSHIP /// BELONGS TO public function tv(): BelongsTo { return $this->belongsTo(Tv::class, 'tv_fk', 'id'); } - // -- END RELATED TO MIGRATION + // -- END RELATED TO RELATIONSHIP //------------------------------------------------------------ } diff --git a/app/Models/TvConnectLog.php b/app/Models/KIV_TvConnectLog.php similarity index 87% rename from app/Models/TvConnectLog.php rename to app/Models/KIV_TvConnectLog.php index 9c9e961..faede24 100644 --- a/app/Models/TvConnectLog.php +++ b/app/Models/KIV_TvConnectLog.php @@ -10,9 +10,9 @@ class TvConnectLog extends Model { use HasFactory; //------------------------------------------------------------ - // -- RELATED TO MIGRATION + // -- RELATED TO RELATIONSHIP /// BELONGS TO public function tv(): BelongsTo { return $this->belongsTo(Tv::class, 'tv_fk', 'id'); } - // -- END RELATED TO MIGRATION + // -- END RELATED TO RELATIONSHIP //------------------------------------------------------------ } diff --git a/app/Models/TvSession.php b/app/Models/KIV_TvSession.php similarity index 86% rename from app/Models/TvSession.php rename to app/Models/KIV_TvSession.php index 4eccdd5..d5d0741 100644 --- a/app/Models/TvSession.php +++ b/app/Models/KIV_TvSession.php @@ -10,9 +10,9 @@ class TvSession extends Model { use HasFactory; //------------------------------------------------------------ - // -- RELATED TO MIGRATION + // -- RELATED TO RELATIONSHIP /// BELONGS TO public function tv(): BelongsTo { return $this->belongsTo(Tv::class, 'tv_fk', 'id'); } - // -- END RELATED TO MIGRATION + // -- END RELATED TO RELATIONSHIP //------------------------------------------------------------ } diff --git a/app/Models/NewTvRequest.php b/app/Models/NewTvRequest.php new file mode 100644 index 0000000..abb20aa --- /dev/null +++ b/app/Models/NewTvRequest.php @@ -0,0 +1,12 @@ +belongsTo(Outlet::class, 'outlet_fk', 'id'); } // -- END RELATED TO MIGRATION //------------------------------------------------------------ + + //------------------------------------------------------------ + // -- RELATED TO DATA FUNCTION + public static function generateRandomCode(): string { + $totalDigit = 6; + $randomDigit = ''; + while(true) { + $randomDigit = strtoupper(Str::random($totalDigit)); + $isExist = Tv::where('code', $randomDigit)->first(); + if(!$isExist) break; + } + return $randomDigit; + } + // -- END RELATED TO DATA FUNCTION + //------------------------------------------------------------ + + //------------------------------------------------------------ + // -- RELATED TO DATA FUNCTION + public static function createAnonymousData() :Tv { + $newTv = new self; + $newTv->code = self::generateRandomCode(); + $newTv->is_active = true; + $newTv->save(); + return $newTv; + } + // -- END RELATED TO DATA FUNCTION + //------------------------------------------------------------ + + + //------------------------------------------------------------ + // -- RELATED TO REQUEST + public static function renewTvInformation(Request $request) { + + } + // -- END RELATED TO REQUEST + //------------------------------------------------------------ } diff --git a/database/migrations/2024_05_18_033101_outlet.php b/database/migrations/2024_05_18_033101_outlet similarity index 100% rename from database/migrations/2024_05_18_033101_outlet.php rename to database/migrations/2024_05_18_033101_outlet diff --git a/database/migrations/2024_05_18_033105_tv.php b/database/migrations/2024_05_18_033105_tv.php index 1092337..7de0674 100644 --- a/database/migrations/2024_05_18_033105_tv.php +++ b/database/migrations/2024_05_18_033105_tv.php @@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. */ @@ -16,7 +15,6 @@ return new class extends Migration $table->string('code', 50)->unique(); $table->string('ik_address_id', 255); $table->string('notes', 255)->nullable(); - $table->timestampTz('last_connected_at')->nullable(); $table->string('col1', 255)->nullable(); $table->string('col2', 255)->nullable(); $table->string('col3', 255)->nullable(); @@ -27,53 +25,65 @@ return new class extends Migration $table->string('col8', 255)->nullable(); $table->string('col9', 255)->nullable(); $table->string('col10', 255)->nullable(); - $table->bool('is_acctive')->default(true); + $table->boolean('is_active')->default(true); + $table->timestampTz('installed_at')->nullable(); + $table->timestampTz('last_connected_at')->nullable(); $table->timestampsTz(); }); - Schema::create('tv_sessions', function (Blueprint $table) { + Schema::create('new_tv_requests', function (Blueprint $table) { $table->id(); - $table->foreignId('tv_fk')->index(); - $table->timestampTz('started_at')->index(); - $table->timestampTz('finished_at')->nullable()->index(); - $table->boolean('is_playing_video'); - $table->jsonb('current_videos')->nullable(); + $table->string('code', 50); + $table->jsonb('device_info')->nullable(); + $table->timestampTz('activated_at')->nullable(); + $table->timestampTz('responded_at')->nullable(); $table->timestampsTz(); - - $table->foreign('tv_fk')->references('id')->on('tvs'); }); - Schema::create('tv_app_infos', function (Blueprint $table) { - $table->foreignId('tv_fk')->unique()->index(); - $table->timestampTz('installed_at')->nullable()->index(); - $table->jsonb('current_videos')->nullable(); - $table->timestampTz('last_updated_video')->nullable()->index(); - $table->timestampsTz(); + // Schema::create('tv_sessions', function (Blueprint $table) { + // $table->id(); + // $table->foreignId('tv_fk')->index(); + // $table->timestampTz('started_at')->index(); + // $table->timestampTz('finished_at')->nullable()->index(); + // $table->boolean('is_playing_video'); + // $table->jsonb('current_videos')->nullable(); + // $table->timestampsTz(); - $table->foreign('tv_fk')->references('id')->on('tvs'); - }); + // $table->foreign('tv_fk')->references('id')->on('tvs'); + // }); - Schema::create('tv_app_logs', function (Blueprint $table) { - $table->id(); - $table->foreignId('tv_fk')->index(); - $table->string('requested_to'); - $table->string('ip', 50); - $table->jsonb('request_data')->nullable(); - $table->enum('result', ['success', 'failed']); - $table->jsonb('response_data')->nullable(); - $table->timestampsTz(); + // Schema::create('tv_app_infos', function (Blueprint $table) { + // $table->foreignId('tv_fk')->unique()->index(); + // $table->timestampTz('installed_at')->nullable()->index(); + // $table->jsonb('current_videos')->nullable(); + // $table->timestampTz('last_updated_video')->nullable()->index(); + // $table->timestampsTz(); - $table->foreign('tv_fk')->references('id')->on('tvs'); - }); + // $table->foreign('tv_fk')->references('id')->on('tvs'); + // }); + + // Schema::create('tv_app_logs', function (Blueprint $table) { + // $table->id(); + // $table->foreignId('tv_fk')->index(); + // $table->string('requested_to'); + // $table->string('ip', 50); + // $table->jsonb('request_data')->nullable(); + // $table->enum('result', ['success', 'failed']); + // $table->jsonb('response_data')->nullable(); + // $table->timestampsTz(); + + // $table->foreign('tv_fk')->references('id')->on('tvs'); + // }); } /** * Reverse the migrations. */ public function down(): void { - Schema::drop('tv_app_logs'); - Schema::drop('tv_app_infos'); - Schema::drop('tv_sessions'); + // Schema::drop('tv_app_logs'); + // Schema::drop('tv_app_infos'); + // Schema::drop('tv_sessions'); + Schema::drop('new_tv_requests'); Schema::drop('tvs'); } }; diff --git a/database/migrations/2024_05_18_033128_sts_log.php b/database/migrations/2024_05_18_033128_sts_log similarity index 100% rename from database/migrations/2024_05_18_033128_sts_log.php rename to database/migrations/2024_05_18_033128_sts_log