𝗣𝗼𝘀𝘁𝗴𝗿𝗲𝗦𝗤𝗟 𝗕𝗮𝘀𝗶𝗰𝘀 𝗙𝗼𝗿 𝗕𝗲𝗴𝗶𝗻𝗻𝗲𝗿𝘀
Stop using JavaScript arrays for long term storage. Use PostgreSQL to store data permanently.
PostgreSQL uses tables. A table is like a spreadsheet. It has columns for structure. It has rows for data.
PostgreSQL forces you to pick data types.
- TEXT for strings.
- UUID for unique IDs.
- TIMESTAMP for dates.
- BOOLEAN for true or false.
- JSONB for structured data.
- DECIMAL for money.
Store phone numbers as TEXT. Numeric types remove the leading zero.
You use four main commands:
- INSERT to add data.
- SELECT to read data.
- UPDATE to change data.
- DELETE to remove data.
Always use a WHERE clause with UPDATE and DELETE. Without it, you change every row in the table.
Learn about relationships. One client has many projects. You use a foreign key to link them. A foreign key is a column in one table pointing to another. It ensures a project belongs to a real client.
Store data where it logically belongs. Projects have budgets and stages. Clients do not. Put project details in the projects table.
Errors teach you how databases think. A good design mirrors reality. Relationships matter more than tables.