Skip to content

Commit 374b79d

Browse files
authored
fix(db-postgres): prevent indexes from changing name on HMR (#10154)
As we didn't reset our `adapter.indexes` state, on every HMR reload we incremented every single index name with the `buildIndexName`: https://github.com/payloadcms/payload/blob/466f109152bc6bf9a67e7d7bafd38c7d57a881de/packages/drizzle/src/utilities/buildIndexName.ts#L3-L24 I found this while debugging our internal SQL schema: Before reload: ```ts "payload_preferences": { "name": "payload_preferences", "columns": { "id": { "name": "id", "type": "serial", "primaryKey": true }, "key": { "name": "key", "type": "varchar" }, "value": { "name": "value", "type": "jsonb" }, "updatedAt": { "name": "updated_at", "type": "timestamp", "defaultNow": true, "mode": "string", "notNull": true, "precision": 3, "withTimezone": true }, "createdAt": { "name": "created_at", "type": "timestamp", "defaultNow": true, "mode": "string", "notNull": true, "precision": 3, "withTimezone": true } }, "foreignKeys": {}, "indexes": { "payload_preferences_key_idx": { "name": "payload_preferences_key_idx", "on": "key" }, "payload_preferences_updated_at_idx": { "name": "payload_preferences_updated_at_idx", "on": "updatedAt" }, "payload_preferences_created_at_idx": { "name": "payload_preferences_created_at_idx", "on": "createdAt" } } }, ``` After: ```ts "payload_preferences": { "name": "payload_preferences", "columns": { "id": { "name": "id", "type": "serial", "primaryKey": true }, "key": { "name": "key", "type": "varchar" }, "value": { "name": "value", "type": "jsonb" }, "updatedAt": { "name": "updated_at", "type": "timestamp", "defaultNow": true, "mode": "string", "notNull": true, "precision": 3, "withTimezone": true }, "createdAt": { "name": "created_at", "type": "timestamp", "defaultNow": true, "mode": "string", "notNull": true, "precision": 3, "withTimezone": true } }, "foreignKeys": {}, "indexes": { "payload_preferences_key_1_idx": { "name": "payload_preferences_key_1_idx", "on": "key" }, "payload_preferences_updated_at_1_idx": { "name": "payload_preferences_updated_at_1_idx", "on": "updatedAt" }, "payload_preferences_created_at_1_idx": { "name": "payload_preferences_created_at_1_idx", "on": "createdAt" } } }, ``` Which isn't really great for dev performance and can potentially cause errors
1 parent a49e63c commit 374b79d

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

packages/drizzle/src/schema/buildRawSchema.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const buildRawSchema = ({
1616
adapter: DrizzleAdapter
1717
setColumnID: SetColumnID
1818
}) => {
19+
adapter.indexes = new Set()
20+
1921
adapter.payload.config.collections.forEach((collection) => {
2022
createTableName({
2123
adapter,

0 commit comments

Comments
 (0)