Replace hardcoded container names with dynamic lookup
Coolify regenerates the container suffix on every redeploy, making
hardcoded names stale. All three docs now use:
TS_DB=$(docker ps --filter "name=timescale_db" --format "{{.Names}}" | head -1)
OPERATIONS_MANUAL.md: replaced bare connection string with full
tsdb() shell function, one-liner pattern, and multi-container
label-filter guidance.
tracksolid_DB_manual.md: updated header and connection example.
01_BusinessAnalytics.md: updated Step 5 migration commands.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
09b3860706
commit
40e452e156
3 changed files with 66 additions and 7 deletions
|
|
@ -732,13 +732,16 @@ VALUES (
|
||||||
### Step 5 — Run Migrations and Deploy Updated Containers
|
### Step 5 — Run Migrations and Deploy Updated Containers
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# Resolve container name dynamically (survives Coolify redeployments)
|
||||||
|
TS_DB=$(docker ps --filter "name=timescale_db" --format "{{.Names}}" | head -1)
|
||||||
|
|
||||||
# 1. Run distance correction migration (fixes historical data)
|
# 1. Run distance correction migration (fixes historical data)
|
||||||
docker exec timescale_db-bo3nov2ija7g8wn9b1g2paxs-210508774107 \
|
docker exec -i "$TS_DB" psql -U postgres -d tracksolid_db \
|
||||||
psql -U postgres -d tracksolid_db -f /migrations/04_bug_fix_migration.sql
|
< /migrations/04_bug_fix_migration.sql
|
||||||
|
|
||||||
# 2. Run schema enhancement migration (new tables + columns)
|
# 2. Run schema enhancement migration (new tables + columns)
|
||||||
docker exec timescale_db-bo3nov2ija7g8wn9b1g2paxs-210508774107 \
|
docker exec -i "$TS_DB" psql -U postgres -d tracksolid_db \
|
||||||
psql -U postgres -d tracksolid_db -f /migrations/05_enhancement_migration.sql
|
< /migrations/05_enhancement_migration.sql
|
||||||
|
|
||||||
# 3. Rebuild and restart ingestion containers with updated code
|
# 3. Rebuild and restart ingestion containers with updated code
|
||||||
docker compose up -d --build ingest_movement ingest_events webhook_receiver
|
docker compose up -d --build ingest_movement ingest_events webhook_receiver
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,59 @@
|
||||||
# Fireside Communications — Tracksolid Pro Telemetry Stack
|
# Fireside Communications — Tracksolid Pro Telemetry Stack
|
||||||
## Operations Manual & Verification Guide
|
## Operations Manual & Verification Guide
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
connection string docker exec -it timescale_db-bo3nov2ija7g8wn9b1g2paxs-210508774107 psql -U postgres -d tracksolid_db
|
## Database Access
|
||||||
|
|
||||||
|
The TimescaleDB container name includes a Coolify-generated suffix that changes on every redeploy. Use the shell function below instead of hardcoding the container name.
|
||||||
|
|
||||||
|
### Recommended: add to `~/.zshrc` on the server
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Auto-resolves current TimescaleDB container — survives Coolify redeployments
|
||||||
|
tsdb() {
|
||||||
|
local container
|
||||||
|
container=$(docker ps --filter "name=timescale_db" --format "{{.Names}}" | head -1)
|
||||||
|
if [[ -z "$container" ]]; then
|
||||||
|
echo "ERROR: no running timescale_db container found" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
docker exec -it "$container" psql -U postgres -d tracksolid_db "$@"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
After adding it: `source ~/.zshrc`
|
||||||
|
|
||||||
|
**Usage:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
tsdb # open interactive psql prompt
|
||||||
|
tsdb -c "\dt tracksolid.*" # list all tracksolid tables
|
||||||
|
tsdb -c "SELECT COUNT(*) FROM tracksolid.trips;" # run a single query
|
||||||
|
tsdb -c "SELECT dwh_gold.refresh_daily_metrics(CURRENT_DATE - 1);" # run nightly ETL
|
||||||
|
```
|
||||||
|
|
||||||
|
### One-liner (for scripts and migrations)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
TS_DB=$(docker ps --filter "name=timescale_db" --format "{{.Names}}" | head -1)
|
||||||
|
docker exec -i "$TS_DB" psql -U postgres -d tracksolid_db < migration.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
> Use `-i` (not `-it`) when piping SQL files — the `-t` TTY flag conflicts with stdin redirection.
|
||||||
|
|
||||||
|
### If multiple TimescaleDB containers are running
|
||||||
|
|
||||||
|
Filter by Coolify label instead of name to target a specific instance:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Inspect available labels first
|
||||||
|
docker inspect $(docker ps --filter "name=timescale_db" --format "{{.Names}}" | head -1) \
|
||||||
|
--format '{{json .Config.Labels}}' | jq .
|
||||||
|
|
||||||
|
# Then filter by a stable label, e.g.:
|
||||||
|
TS_DB=$(docker ps --filter "label=coolify.name=timescale_db" --format "{{.Names}}" | head -1)
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,18 @@
|
||||||
|
|
||||||
**Database:** `tracksolid_db`
|
**Database:** `tracksolid_db`
|
||||||
**Host:** `kianiadee@stage.rahamafresh.com`
|
**Host:** `kianiadee@stage.rahamafresh.com`
|
||||||
**Container:** `timescale_db-bo3nov2ija7g8wn9b1g2paxs-210508774107`
|
**Container:** `timescale_db-*` (Coolify-generated suffix — changes on redeploy, use dynamic lookup below)
|
||||||
**Engine:** TimescaleDB (PostgreSQL 16 + TimescaleDB 2.15)
|
**Engine:** TimescaleDB (PostgreSQL 16 + TimescaleDB 2.15)
|
||||||
**Timezone note:** All timestamps are stored in UTC. Always cast to `AT TIME ZONE 'Africa/Nairobi'` (EAT = UTC+3) when displaying to users or building reports.
|
**Timezone note:** All timestamps are stored in UTC. Always cast to `AT TIME ZONE 'Africa/Nairobi'` (EAT = UTC+3) when displaying to users or building reports.
|
||||||
|
|
||||||
To connect from the host server:
|
To connect from the host server:
|
||||||
```bash
|
```bash
|
||||||
docker exec timescale_db-bo3nov2ija7g8wn9b1g2paxs-210508774107 psql -U postgres -d tracksolid_db
|
# Dynamic — works after every Coolify redeploy
|
||||||
|
tsdb # if ~/.zshrc function is installed (see OPERATIONS_MANUAL.md)
|
||||||
|
|
||||||
|
# Or inline:
|
||||||
|
TS_DB=$(docker ps --filter "name=timescale_db" --format "{{.Names}}" | head -1)
|
||||||
|
docker exec -it "$TS_DB" psql -U postgres -d tracksolid_db
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue