Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
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 S
Sasha committed
374b79d2180418102283d9766fd149ee1d747386
Parent: a49e63c
Committed by GitHub <noreply@github.com>
on 12/27/2024, 3:04:48 PM