Skip to content

Commit 0c215d3

Browse files
committed
fix: add missing created_at column to equipment_group_members PG DDL
The PG migration script was missing the created_at column on the equipment_group_members table, causing Drizzle ORM queries to fail with a 500 error when creating equipment groups.
1 parent 3fd9f9d commit 0c215d3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

apps/server/src/routes/equipment-groups.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ router.post('/', async (req, res) => {
3939
const full = await storage.getEquipmentGroup(group.id);
4040
res.json(full);
4141
} catch (error) {
42+
console.error('Failed to create equipment group:', error);
4243
res.status(500).json({ message: 'Failed to create equipment group' });
4344
}
4445
});

tools/scripts/apply-pg-migrations.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ async function runMigrations() {
160160
CREATE TABLE IF NOT EXISTS equipment_group_members (
161161
id SERIAL PRIMARY KEY,
162162
group_id INTEGER NOT NULL REFERENCES equipment_groups(id) ON DELETE CASCADE,
163-
equipment_id INTEGER NOT NULL REFERENCES equipment(id) ON DELETE CASCADE
163+
equipment_id INTEGER NOT NULL REFERENCES equipment(id) ON DELETE CASCADE,
164+
created_at TIMESTAMP DEFAULT NOW()
164165
);
165166
`;
166167

@@ -187,6 +188,16 @@ async function runMigrations() {
187188
console.error('Migration failed for equipment cost/acquisition_date columns:', err.message);
188189
}
189190

191+
// Migration: Add created_at to equipment_group_members if it doesn't exist
192+
try {
193+
await connection`
194+
ALTER TABLE equipment_group_members ADD COLUMN IF NOT EXISTS created_at TIMESTAMP DEFAULT NOW();
195+
`;
196+
console.log('Migration: Checked/Added created_at column to equipment_group_members');
197+
} catch (err) {
198+
console.error('Migration failed for equipment_group_members created_at:', err.message);
199+
}
200+
190201
console.log('Database tables and migrations completed successfully');
191202

192203
} catch (error) {

0 commit comments

Comments
 (0)