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.
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
- Establish database connection variables, lock timeout limits, and failure handling parameters for {{database_flavor}}.
- Calculate future time boundaries and generate upcoming partition tables dynamically based on {{partition_interval_unit}}.
- Query metadata catalogs to identify telemetry tables older than {{active_retention_days}}.
- Detach identified historical partitions without holding exclusive metadata table locks during peak construction hours.
- Export detached partitions into columnar parquet or compressed dump files targeted for {{cold_archive_location}}.
- Drop or truncate detached partitions once export integrity is checksum-verified.
- 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:
- Configuration Variables and Safety Flags (max 25 lines)
- Forward Partition Provisioning Function (max 45 lines)
- Historical Partition Detach and Export Routine (max 50 lines)
- 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.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.