Przejdź do treści
Biblioteka skilli
Dane i analityka · Analiza

readonly-db-query

/readonly-db-query

Wykonuje bezpieczne, tylko do odczytu zapytania do bazy Postgres, żeby sprawdzić liczbę lub stan danych bez ryzyka zmian.

Licencja
MIT
Ostatnia zmiana repozytorium
09.11.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
3
Skrypty
1
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 09.11.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co sprawdzić przed instalacją
  • 1 skrypt w paczce. Przejrzyj je przed instalacją, bo Claude może je uruchomić.

Skrypty: test/guard.test.cjs

Co robi i kiedy

Wykonuje bezpieczne, tylko do odczytu zapytania do bazy Postgres, żeby sprawdzić liczbę lub stan danych bez ryzyka zmian.

Oryginalny opis (EN)

Run a safe, read-only query against a specific Postgres database (usually production) to pull a stat or verify data. The script refuses to run unless the connection points at the expected host, never prints the connection string, and reads timestamps as text to avoid time-zone shifts. Use whenever the user asks to pull a number from prod, check production data, confirm a queue is empty, or ground a claim in real data.

Jak działa

  1. Safety rules
  2. Setup (once per project)
  3. Template
  4. Guard self-test
  5. Notes
Sekcje z nagłówków SKILL.md, w oryginale · 96 linii, 487 słów
Podgląd SKILL.md
---
name: readonly-db-query
description: Run a safe, read-only query against a specific Postgres database (usually production) to pull a stat or verify data. The script refuses to run unless the connection points at the expected host, never prints the connection string, and reads timestamps as text to avoid time-zone shifts. Use whenever the user asks to pull a number from prod, check production data, confirm a queue is empty, or ground a claim in real data.
---

# Read-Only Database Query

Pull a number from a live database safely. **SELECTs only, never a write.**

## Safety rules

- **SELECT only.** No INSERT, UPDATE, DELETE, or DDL. No reset or migration commands.
- **Never echo the connection string.** Load `DATABASE_URL` from the env file; never print it.
  Confirm which database you hit with `select current_database()`, not by logging the URL.
- **Guard on the host.** The script refuses to connect unless the URL's host contains
  `EXPECTED_DB_HOST`. A wrong env file fails closed instead of querying the wrong database.
- **Timestamps:** postgres.js shifts `timestamp without time zone` by the local time zone on a
  non-UTC machine. Read timestamps with `::text` and do date math in SQL.
- **Clean up** the temp script when done.

## Setup (once per project)

Ask the user for, or find in the project's docs:

- the env file that holds the target `DATABASE_URL` (for example `.env.production`)
- the expected host fragment for that database (for example the project ref or hostname).
  Hostnames and project refs are not secrets; the password inside `DATABASE_URL` is.

Requires Node and the `postgres` package. Run from the project root.

## Template

Write a temp `_diag.cjs` at the project root, run it, then delete it:

```js
/* READ-ONLY diagnostic. SELECTs only. */
require('dotenv').config({ path: process.env.ENV_FILE || '.env' })
const url = process.env.DATABASE_URL
const expected = process.env.EXPECTED_DB_HOST

function assertExpectedHost(rawUrl, expectedHost) {
  if (!rawUrl) throw new Error('no DATABASE_URL')
  if (!expectedHost) throw new Error('no EXPECTED_DB_HOST set')
  let host
  try {
    host = new URL(rawUrl).hostname
  } catch {
    throw new Error('DATABASE_URL is not a valid URL')
  }
  // Check host AND username: poolers often share a hostname and put the project ref in the user.
  const user = new URL(rawUrl).username
  if (!host.includes(expectedHost) && !user.includes(expectedHost)) {
    throw new Error('REFUSING: connection does not match EXPECTED_DB_HOST')
  }
}

assertExpectedHost(url, expected)

const postgres = require('postgres')
;(async () => {
  const sql = postgres(url, { max: 1, idle_timeout: 5, connect_timeout: 15 })
  const db = (await sql`select current_database() db`)[0].db
  console.log('DB:', db, '- READ ONLY\n')

  // ---- your SELECTs here ----
  // Read timestamps as text to dodge the tz shift:
  //   select created_at::text ts from orders where ...
  // Do date-window math in SQL:
  //   where created_at::text >= '2026-06-07' and created_at::text < '2026-06-12'

  await sql.end()
})().catch((e) => {
  console.error('ERR:', e.message)
  process.exit(1)
})
```

Run and clean up:

```bash
ENV_FILE=.env.production EXPECTED_DB_HOST=<host-fragment> node _diag.cjs
rm -f _diag.cjs
```

## Guard self-test

Before trusting the guard on a new project, prove it refuses a mismatch (no network needed):

```bash
DATABASE_URL='postgres://user@some-other-host.example.com:5432/db' EXPECTED_DB_HOST=my-prod-ref node _diag.cjs
# expected: ERR / REFUSING: connection does not match EXPECTED_DB_HOST, exit code 1
```

`test/guard.test.cjs` in this folder runs the same check as a script.

## Notes

- For many rows, pull them and aggregate in JS; keep the SQL to plain SELECTs.
- A timeout on a fast query usually means connection-pool starvation, not a slow query. `max: 1` is right for a one-shot script.
Pliki w paczce (3)
  • README.md 1 KB
  • SKILL.md 4 KB
  • test/guard.test.cjs 1 KB

Wersje

W bazie nie ma innych skilli o nazwie readonly-db-query.

Migawka bazy z 13.11.2026 · wersja paczki 419c83a11ee0 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100postgres-query
    Wykonuje zapytania PostgreSQL do testów, debugowania i analizy wydajności, z obowiązkowym wskazaniem bazy --prod lub --dev (domyślnie produkcyjna) i połączeniami tylko do odczytu.
  • 100db-postgres
    Odpytuje bazy PostgreSQL skonfigurowane w .env (DB_POSTGRES_N_*) po etykiecie lub indeksie, domyślnie tylko do odczytu, a zapisy dopuszcza dopiero po jawnej fladze.
  • 90production-db-readonly
    Odpytuje produkcyjną bazę MySQL lub PostgreSQL tylko do odczytu, przez konektor projektu, w dialekcie tej bazy, do walidacji danych.
  • 100postgres-query
    Wykonuje zapytania PostgreSQL do testów, debugowania i analizy wydajności: EXPLAIN ANALYZE, porównanie wyników i testy optymalizacji SQL, domyślnie z połączeniami tylko do odczytu.
  • 100postgres
    Wykonuje doraźne zapytania SELECT do PostgreSQL, analizuje plany EXPLAIN i ANALYZE, sprawdza schematy, indeksy i blokady oraz bada wolne zapytania, domyślnie tylko do odczytu.
  • 100querying-production-databases
    Obsługuje zapytania tylko do odczytu w produkcyjnych bazach PostHog, ClickHouse i Postgres, w regionach US i EU.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.