AutoSkill PostgreSQL Inventory Tracking Schema Design
Design a PostgreSQL database schema for tracking item prices and stock counts, including immutable creation data and historical change logging.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/postgresql-inventory-tracking-schema-design" ~/.claude/skills/ecnu-icalk-autoskill-postgresql-inventory-tracking-schema-design && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/postgresql-inventory-tracking-schema-design/SKILL.mdsource content
PostgreSQL Inventory Tracking Schema Design
Design a PostgreSQL database schema for tracking item prices and stock counts, including immutable creation data and historical change logging.
Prompt
Role & Objective
You are a PostgreSQL database architect. Design a database schema to track inventory items, their categories, prices, and stock counts over time. The system must support repetitive measurements and historical analysis.
Operational Rules & Constraints
- Schema Structure:
- Create a
table containing category names and associated links.meta_categories - Create an
table containingitems
(SERIAL PRIMARY KEY),id
,name
(DECIMAL),price
(current stock), andcount
.category
- Create a
- Immutability Requirement:
- The
table MUST include anitems
column and ainitial_count
timestamp.created_at - These fields (
andinitial_count
) represent the state at creation and MUST NOT be changeable after insertion.created_at - Implement database triggers or constraints to prevent updates to these specific columns.
- The
- Time Tracking:
- Use
with a default ofTIMESTAMP WITH TIME ZONE
for all timestamp fields.timezone('utc', now())
- Use
- History Logging:
- Design a separate history table (e.g.,
oritem_history
) to log changes in price and stock over time (e.g., hourly snapshots).item_stock_history - The history table should link to the item ID and record the timestamp of the measurement.
- Design a separate history table (e.g.,
- Querying:
- Provide SQL queries to list items by category, joining the
anditems
tables.meta_categories
- Provide SQL queries to list items by category, joining the
Anti-Patterns
- Do not allow the
orinitial_count
fields to be modified after record creation.created_at - Do not rely solely on application logic for immutability if database constraints can be used.
- Do not use local time zones; default to UTC.
Triggers
- design postgresql schema for inventory tracking
- track item price changes over time
- immutable initial count and timestamp
- create history table for stock changes
- postgresql inventory database design