- Replace dart:js with package:js in health_check_service_web.dart\n- Implement showHealthCheckNotification in web/index.html\n- Pin js dependency to ^0.6.7 for flutter_secure_storage_web compatibility auth: harden AuthInterceptor + tests - Allow overrideAuthRepository injection for testing\n- Normalize imports to package: paths\n- Add unit test covering token attach, 401→refresh→retry, and failure path\n- Add integration test skeleton gated by env vars ui/data: map User.companyName to list column - Add companyName to domain User\n- Map UserDto.company?.name\n- Render companyName in user_list cleanup: remove legacy equipment table + unused code; minor warnings - Remove _buildFlexibleTable and unused helpers\n- Remove unused zipcode details and cache retry constant\n- Fix null-aware and non-null assertions\n- Address child-last warnings in administrator dialog docs: update AGENTS.md session context
76 lines
1.9 KiB
Markdown
76 lines
1.9 KiB
Markdown
# Superport Database Patterns v8.0
|
|
|
|
## What This Really Is
|
|
Database queries and schema patterns. PostgreSQL specific.
|
|
|
|
## Main Tables
|
|
```sql
|
|
-- Core entities
|
|
equipment (
|
|
id SERIAL PRIMARY KEY,
|
|
serial_number VARCHAR UNIQUE,
|
|
models_id INT REFERENCES models(id),
|
|
companies_id INT REFERENCES companies(id),
|
|
status VARCHAR
|
|
)
|
|
|
|
equipment_history (
|
|
id SERIAL PRIMARY KEY,
|
|
equipments_id INT REFERENCES equipment(id),
|
|
transaction_type CHAR(1), -- 'I'(입고), 'O'(출고)
|
|
warehouses_id INT,
|
|
transacted_at TIMESTAMP
|
|
)
|
|
|
|
maintenance (
|
|
id SERIAL PRIMARY KEY,
|
|
equipment_history_id INT,
|
|
maintenance_type VARCHAR, -- WARRANTY, CONTRACT, INSPECTION
|
|
expiry_date DATE
|
|
)
|
|
```
|
|
|
|
## Common Queries
|
|
```sql
|
|
-- Equipment with latest location
|
|
SELECT e.*, w.name as warehouse_name
|
|
FROM equipment e
|
|
LEFT JOIN LATERAL (
|
|
SELECT warehouses_id
|
|
FROM equipment_history
|
|
WHERE equipments_id = e.id
|
|
ORDER BY transacted_at DESC
|
|
LIMIT 1
|
|
) eh ON true
|
|
LEFT JOIN warehouses w ON w.id = eh.warehouses_id;
|
|
|
|
-- Maintenance due in 30 days
|
|
SELECT m.*, e.serial_number
|
|
FROM maintenance m
|
|
JOIN equipment_history eh ON m.equipment_history_id = eh.id
|
|
JOIN equipment e ON eh.equipments_id = e.id
|
|
WHERE m.expiry_date <= CURRENT_DATE + INTERVAL '30 days'
|
|
AND m.expiry_date >= CURRENT_DATE;
|
|
```
|
|
|
|
## Indexes
|
|
```sql
|
|
-- Add these for performance
|
|
CREATE INDEX idx_equipment_history_equipments ON equipment_history(equipments_id);
|
|
CREATE INDEX idx_equipment_history_transacted ON equipment_history(transacted_at DESC);
|
|
CREATE INDEX idx_maintenance_expiry ON maintenance(expiry_date);
|
|
```
|
|
|
|
## Transaction Pattern
|
|
```sql
|
|
BEGIN;
|
|
-- Insert equipment
|
|
INSERT INTO equipment (serial_number, models_id) VALUES ($1, $2) RETURNING id;
|
|
-- Insert history
|
|
INSERT INTO equipment_history (equipments_id, transaction_type, warehouses_id)
|
|
VALUES ($id, 'I', $3);
|
|
COMMIT;
|
|
```
|
|
|
|
---
|
|
*Backend handles all DB logic. Frontend never touches SQL.* |