Databases
AuraScore 81/100

Construction Site Sensor Partitioning Script

Generate a database maintenance script to automate time-bucket partitioning and cold-storage retention for IoT site telemetry.

Use when managing high-frequency construction telemetry streams like vibration, dust, crane load, and noise monitors. It delivers automated partition rollouts and archival commands.

Template

Role: Principal Site Reliability Engineer (Database Infrastructure) specializing in heavy civil engineering telematics.

Context

  • Database technology stack: {{database_flavor}}
  • Sensor readings target table: {{telemetry_table_name}}
  • Temporal partition window: {{partition_interval_unit}}
  • Active hot storage threshold: {{active_retention_days}}
  • Long-term cold archive endpoint: {{cold_archive_location}}
  • Operational alert webhook: {{alert_webhook_url}}

Task

Deliver an automated shell and SQL maintenance script that provisions forward partitions for {{telemetry_table_name}}, detaches aged partitions exceeding {{active_retention_days}}, compresses them, and moves historical site telemetry to {{cold_archive_location}}.

Method

  1. Establish database connection variables, lock timeout limits, and failure handling parameters for {{database_flavor}}.
  2. Calculate future time boundaries and generate upcoming partition tables dynamically based on {{partition_interval_unit}}.
  3. Query metadata catalogs to identify telemetry tables older than {{active_retention_days}}.
  4. Detach identified historical partitions without holding exclusive metadata table locks during peak construction hours.
  5. Export detached partitions into columnar parquet or compressed dump files targeted for {{cold_archive_location}}.
  6. Drop or truncate detached partitions once export integrity is checksum-verified.
  7. Dispatch execution status and telemetry volume metrics to {{alert_webhook_url}} upon script completion or error.

Constraints

  • MUST include explicit LOCK_TIMEOUT settings to prevent blocking continuous IoT sensor writes.
  • MUST NOT drop any raw data partition prior to receiving an archival storage success response.
  • All database commands MUST execute idempotently to tolerate scheduled cron retries.
  • Script must contain error traps that notify {{alert_webhook_url}} immediately upon failure.

Output format

A unified Bash script encapsulating embedded SQL commands, divided into:

  1. Configuration Variables and Safety Flags (max 25 lines)
  2. Forward Partition Provisioning Function (max 45 lines)
  3. Historical Partition Detach and Export Routine (max 50 lines)
  4. Retention Cleanup and Metric Dispatcher (max 35 lines)

Self-review

  • Check that all partition naming conventions follow standard UTC date suffix patterns.
  • Validate that lock acquisition timeouts are set low enough to prevent queuing live sensor feeds.
  • Verify error exit codes and webhook alert payloads contain actionable failure context.
AuraScore breakdown
81/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

developers
developers-databases
real-estate-construction
iot
timescale
partitioning