b192cd53ba
- Add comprehensive project overview and core philosophy - Document file structure reference for the codebase - Create key files reference table for task-specific guidance - Include multi-tenant guidelines and site resolution flow
2.3 KiB
2.3 KiB
description, agent
| description | agent |
|---|---|
| Scaffold a new Drizzle database migration for The Collective Hub. Generates schema additions in schema.ts and runs drizzle-kit generate to produce the SQL migration. | agent |
Generate a Drizzle database migration for: ${input}
Follow all conventions in:
Rules
- Additive changes only — never add destructive operations (ALTER DROP, RENAME) in a production migration
- Every new table must have a
siteIdcolumn — referencessites.idwithonDelete: 'cascade' - Every new table must have:
id: uuid('id').defaultRandom().primaryKey()createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow()updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow().$onUpdate(() => new Date())
- Use snake_case for column names in the database
- Add indexes on
siteIdand any commonly filtered columns - Use appropriate types:
text,boolean,integer,jsonb,timestamp
Steps
- Add the new table/column definition to
src/lib/server/db/schema.ts - Run
npx drizzle-kit generateto create the SQL migration file - Review the generated SQL in
drizzle/to ensure it matches expectations
Example: New Table
// In schema.ts
export const newTable = pgTable(
'new_table',
{
id: uuid('id').defaultRandom().primaryKey(),
siteId: uuid('site_id')
.notNull()
.references(() => sites.id, { onDelete: 'cascade' }),
name: text('name').notNull(),
isActive: boolean('is_active').notNull().default(true),
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true })
.notNull()
.defaultNow()
.$onUpdate(() => new Date()),
},
(table) => [
index('new_table_site_id_idx').on(table.siteId),
]
);
Example: New Column
// Add to an existing table definition
export const events = pgTable('events', {
// ... existing columns
newColumn: text('new_column'), // Add new optional column
});