feat: add partial unique index for single primary address per client
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1
src/lib/db/migrations/0001_soft_ender_wiggin.sql
Normal file
1
src/lib/db/migrations/0001_soft_ender_wiggin.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
CREATE UNIQUE INDEX "idx_ca_primary" ON "client_addresses" USING btree ("client_id") WHERE "client_addresses"."is_primary" = true;
|
||||||
7090
src/lib/db/migrations/meta/0001_snapshot.json
Normal file
7090
src/lib/db/migrations/meta/0001_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -8,6 +8,13 @@
|
|||||||
"when": 1776185027494,
|
"when": 1776185027494,
|
||||||
"tag": "0000_narrow_longshot",
|
"tag": "0000_narrow_longshot",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 1,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1776185487775,
|
||||||
|
"tag": "0001_soft_ender_wiggin",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
numeric,
|
numeric,
|
||||||
jsonb,
|
jsonb,
|
||||||
index,
|
index,
|
||||||
|
uniqueIndex,
|
||||||
primaryKey,
|
primaryKey,
|
||||||
} from 'drizzle-orm/pg-core';
|
} from 'drizzle-orm/pg-core';
|
||||||
import { sql } from 'drizzle-orm';
|
import { sql } from 'drizzle-orm';
|
||||||
@@ -173,7 +174,13 @@ export const clientAddresses = pgTable(
|
|||||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||||
},
|
},
|
||||||
(table) => [index('idx_ca_client').on(table.clientId), index('idx_ca_port').on(table.portId)],
|
(table) => [
|
||||||
|
index('idx_ca_client').on(table.clientId),
|
||||||
|
index('idx_ca_port').on(table.portId),
|
||||||
|
uniqueIndex('idx_ca_primary')
|
||||||
|
.on(table.clientId)
|
||||||
|
.where(sql`${table.isPrimary} = true`),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
export type Client = typeof clients.$inferSelect;
|
export type Client = typeof clients.$inferSelect;
|
||||||
|
|||||||
Reference in New Issue
Block a user