PostgreSQL Convention
The chuck-stack PostgreSQL conventions aim to create a consistent, convention-based, scalable, and maintainable database structure.
We provide two high-level features by which most applications are built:
- Workflow
- Attribute Tagging
The below convention summary creates a workflow and attributing tagging system that is both:
- Generic enough to support a wide variety of use cases
- Simple enough to support rapid adoption
You can always ask AI (using AIChat) about any chuck-stack specific convention or PostgreSQL best practices and options. For example, you can ask AI:
It seems more secure to disable PostgreSQL's TCP service and require clients to connect via unix socket. Is this true?
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 with a
<table_name>_uu
convention to support universaltable_name
+record_uu
lookup 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 with a
-
Column Conventions:
- Use mandatory columns:
stk_entity_uu
,created
,created_by_uu
,updated
,updated_by_uu
. - Use
_uu
suffix for primary and foreign keys - Use
text
type instead ofvarchar
when possible - Boolean columns must have default values
- Use mandatory columns:
-
Enum and Type Conventions:
- Use enums for code-level distinctions
- Create facade type tables to reference enums in transactional tables
-
Function Conventions:
- Use
_p
suffix for function parameters - Use
_v
suffix for function variables
- Use
-
Trigger Conventions:
- Use
private.stk_trigger_create()
function to manage triggers across tables
- Use
-
Attribute Tagging:
- Use JSON for flexible attribute storage (
stk_attribute_tag
table)
- Use JSON for flexible attribute storage (
-
System Configuration:
- Use
stk_system_config
table for system-wide settings
- Use
-
Statistics:
- Use
stk_statistic
table for denormalized statistical data
- Use
-
Scalability Considerations:
- Use connection pooling
- Implement table partitioning
- Utilize physical/streaming replicas and logical replicas
Copyright © , CHUBOE LLC. All rights reserved.