diff --git a/database/migrations/2025_06_20_110823_create_guard_patrol_entries_table.php b/database/migrations/2025_06_20_110823_create_guard_patrol_entries_table.php new file mode 100644 index 000000000..561d2044e --- /dev/null +++ b/database/migrations/2025_06_20_110823_create_guard_patrol_entries_table.php @@ -0,0 +1,53 @@ +id(); + // $table->timestamps(); + // }); + $sql = <<<'SQL' + CREATE TABLE guard_patrol_entries ( + id BIGINT GENERATED always AS IDENTITY PRIMARY KEY, + + plant_id BIGINT NOT NULL, + guard_name_id BIGINT NOT NULL, + check_point_name_id BIGINT NOT NULL, + + reader_code TEXT NULL, + patrol_time TIMESTAMP NOT NULL DEFAULT NOW(), + + created_at TIMESTAMP NOT NULL DEFAULT NOW(), + updated_at TIMESTAMP NOT NULL DEFAULT NOW(), + deleted_at TIMESTAMP, + + created_by TEXT NOT NULL, + updated_by TEXT NOT NULL, + + UNIQUE (plant_id, guard_name_id, check_point_name_id, patrol_time), + FOREIGN KEY (plant_id) REFERENCES plants (id), + FOREIGN KEY (guard_name_id) REFERENCES guard_names (id), + FOREIGN KEY (check_point_name_id) REFERENCES check_point_names (id) + ); + SQL; + + DB::statement($sql); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('guard_patrol_entries'); + } +};