Postgresql inventory tracking schema design
AutoSkill: Experience-Driven Lifelong Learning via Skill Self-Evolution
npx -y skills add ECNU-ICALK/AutoSkill --skill postgresql-inventory-tracking-schema-designAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
What its author says it does
Copied from the file, not written here
Design a PostgreSQL database schema for tracking item prices and stock counts, including immutable creation data and historical change logging.
SKILL.md
2.6 KB, as published. Nobody here has run it
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
meta_categoriestable containing category names and associated links. - Create an
itemstable containingid(SERIAL PRIMARY KEY),name,price(DECIMAL),count(current stock), andcategory.
- Create a
- Immutability Requirement:
- The
itemstable MUST include aninitial_countcolumn and acreated_attimestamp. - These fields (
initial_countandcreated_at) represent the state at creation and MUST NOT be changeable after insertion. - Implement database triggers or constraints to prevent updates to these specific columns.
- The
- Time Tracking:
- Use
TIMESTAMP WITH TIME ZONEwith a default oftimezone('utc', now())for all timestamp fields.
- Use
- History Logging:
- Design a separate history table (e.g.,
item_historyoritem_stock_history) to log changes in price and stock over time (e.g., hourly snapshots). - 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
itemsandmeta_categoriestables.
- Provide SQL queries to list items by category, joining the
Anti-Patterns
- Do not allow the
initial_countorcreated_atfields to be modified after record creation. - 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