PostgreSQL Convention
The chuck-stack PostgreSQL conventions aim to create a consistent, convention-based, scalable, and maintainable database structure that supports our data management philosophy.
You can always ask AI (using Claude Code or AIChat) about any chuck-stack specific convention or PostgreSQL best practices and options. For example, you can ask AI:
Should I create an address table to hold references to addresses?
TOC
Convention Summary
Here are the goals that drive our conventions:
- Maximize ↑ use of conventions and AI assistance to reduce learning/development time and complexity
- Minimize ↓ the number of experts needed to articulate and deploy a new feature
Here is a summary of our conventions. Click on any link to learn more.
- 
Database Schema Structure: - Private schema (private) to encapsulate the internal data model and logic
- Public API schema (api) to expose a public interface providing data and logic to the outside world in a controlled way
 
- Private schema (
- 
Table Conventions: - Use a single UUID primary key column named uuto support universaltable_name+record_uulookup across all tables
- Prefix core tables with stk_
- Use noun-first naming (e.g., stk_order_line)
- Minimize abbreviations to a known list to ensure maximum schema readability
 
- Use a single UUID primary key column named 
- 
Column Conventions: - Use mandatory columns: stk_entity_uu,created,created_by_uu,updated,updated_by_uu.
- All madatory columns are set automatically during save because of either default value or triggers
- All tables return automatically generated table_nameandrecord_uucolumns for easy and generic looks for attributes, statistics, change logs, ...
- Use _uusuffix for foreign keys
- Use texttype instead ofvarcharwhen possible
- Boolean columns must have default values
 
- Use mandatory columns: 
- 
Enum and Type Conventions: - Most important tables have have a supporting _typetable where users can describe that record's behavior
- Example: stk_actortable has astk_actor_typetable that describes the type of actor
- _typetables use enums for code-level logic
- No _uureferences should be made from code
- Only enums should be referenced from code
 
- Most important tables have have a supporting 
- 
Function Conventions: - Use _psuffix for function parameters
- Use _vsuffix for function variables
 
- Use 
- 
Trigger Conventions: - Triggers are heavily used to manage events in the chuck-stack
- The private.stk_trigger_create()function helps ensure core trigger functions are applied to all tables
 
- 
Attribute Tagging: - Makes use of the table_nameandrecord_uuconvention to associate an attribute tag to any record
- Use JSON for flexible attribute storage (stk_tagtable)
 
- Makes use of the 
- 
System Configuration: - Use stk_system_configtable for system-wide settings
 
- Use 
- 
Statistics: - Makes use of the table_nameandrecord_uuconvention to associate a statistic to any record
- Use stk_statistictable for denormalized statistical data
 
- Makes use of the 
- 
Scalability Considerations: - Use connection pooling
- Implement table partitioning
- Utilize physical/streaming replicas and logical replicas
 
Copyright © 2024-, CHUBOE LLC. All rights reserved.