agentsclimarketplace

Pg gleam

Skill aboio-labs/aboio-skills/skills/pg-gleam

Postgres performance optimization and best practices for a Gleam + Squirrel/Parrot + POG + Cigogne stack. Use this skill when writing, reviewing, or optimizing Postgres queries, schema designs, or database configurations.From its SKILL.md

Install
npx -y skills add aboio-labs/aboio-skills --skill pg-gleam

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its file declares

Copied from the file, not written here

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

7.8 KB, as published. Nobody here has run it

Postgres Best Practices (Gleam Stack)

Performance optimization and schema design guide for Postgres, aligned with our Gleam backend stack.

Stack Context

LayerToolRole
LanguageGleamBackend application code
SQL codegenSquirrel / ParrotGenerates type-safe Gleam from .sql files
DB driverPOGConnection pooling, binary protocol
MigrationsCigogneSchema migrations
Extensionspg_uuidv7UUIDv7 primary key generation

Our Conventions

  • Primary keys: uuid via uuid_generate_v7() (pg_uuidv7 extension)
  • Timestamps: timestamp (not timestamptz); timezone stored in core.tenant.timezone
  • Money: bigint with scale factor 10,000 (maps to Gleam Int, exact arithmetic)
  • Enums: CREATE TYPE with prefixed values (os_pending, ps_paid) for Gleam uniqueness
  • Constraints: Named with pk_, fk_, uq_, chk_, idx_ prefixes
  • Schemas: core, tenant, shared, extensions separation
  • Tables: Singular names (order not orders)
  • Soft deletes: deleted_at timestamp + deleted_by uuid + partial indexes
  • Audit fields: created_at, updated_at, created_by, updated_by via triggers
  • RLS: Session variables via core.current_tenant_id() / core.current_user_id()

Gleam Type Mapping (via Squirrel/POG)

Postgres TypeGleam TypeNotes
uuidStringUUIDv7 for PKs
textStringPrefer over varchar(n)
booleanBool
integerInt
bigintIntUse for money (exact)
numericFloatLossy! Avoid for money
timestamppog.TimestampNo timestamptz support
datepog.Date
jsonbString (raw JSON)Decode in Gleam
byteaBitArray
enumGenerated variant typeSee schema-enums.md

When to Apply

Reference these guidelines when:

  • Writing SQL queries or designing schemas
  • Implementing indexes or query optimization
  • Reviewing database performance issues
  • Configuring POG connection pooling
  • Working with Row-Level Security (RLS)
  • Creating Squirrel or Parrot .sql query files
  • Writing Cigogne migrations

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Query PerformanceCRITICALquery-
2Connection ManagementCRITICALconn-
3Security & RLSCRITICALsecurity-
4Schema DesignHIGHschema-
5Concurrency & LockingMEDIUM-HIGHlock-
6Data Access PatternsMEDIUMdata-
7Monitoring & DiagnosticsLOW-MEDIUMmonitor-
8Advanced FeaturesLOWadvanced-

Token Efficiency

Follow references/token-efficiency.md rules. When reviewing or writing database code:

  1. Grep for specific SQL patterns (e.g., pog.transaction, set_config, FORCE ROW LEVEL) instead of reading all migration files
  2. Use git diff --name-only to scope reviews to changed .sql files only
  3. Read targeted line ranges around Grep matches, not entire migrations

How to Use

Read individual rule files in references/ for detailed explanations and SQL examples. Each rule file contains:

  • Brief explanation of why it matters
  • Incorrect SQL example with explanation
  • Correct SQL example with explanation
  • Optional EXPLAIN output or metrics
  • Gleam/POG-specific notes where applicable

Reference routing — by task

TaskReferences to read
Designing a new tableschema-primary-keys.md + schema-data-types.md + schema-naming-conventions.md
Adding Enum columnsschema-enums.md
Adding Audit / Soft Deletesschema-audit-fields.md + schema-soft-deletes.md
Implementing RLS (Tenant Isolation)security-rls-basics.md + security-session-variables.md
RLS on Child Tablessecurity-rls-child-tables.md + security-rls-performance.md
Optimizing slow queriesquery-missing-indexes.md + monitor-explain-analyze.md
Creating indexesschema-foreign-key-indexes.md + query-composite-indexes.md
Writing batch insertsdata-batch-inserts.md
Implementing paginationdata-pagination.md
Handling concurrent updateslock-short-transactions.md + lock-skip-locked.md
Configuring POG connectionsconn-pooling.md + conn-limits.md

Reference routing — by topic

TopicReference
Postgres Data Types to Gleam mappingschema-data-types.md
UUIDv7 generationschema-primary-keys.md
Row Level Security (RLS) performancesecurity-rls-performance.md
Partial & Covering Indexesquery-partial-indexes.md + query-covering-indexes.md
JSONB Indexingadvanced-jsonb-indexing.md
Full Text Searchadvanced-full-text-search.md
Deadlock preventionlock-deadlock-prevention.md
N+1 Query preventiondata-n-plus-one.md
Upserts (ON CONFLICT)data-upsert.md
Connection Pooling & Idle timeoutsconn-pooling.md + conn-idle-timeout.md
Prepared Statementsconn-prepared-statements.md

References

Keep looking

Skills are one crate of 627,801. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.