memos/store/db/postgres
Steven d9e8387d63 fix(postgres): handle missing PAT data gracefully and add comprehensive tests
Fixes #5612, #5611

Root cause: PostgreSQL's jsonb_array_elements() throws errors when the
'tokens' key is missing or malformed, while SQLite/MySQL return NULL
gracefully. This caused:
- 502 errors when creating admin after v0.25.3 → v0.26.0 upgrade
- Settings not persisting and users unable to stay logged in

Changes to store/db/postgres/user_setting.go:
- Remove strict JSONB operations from GetUserByPATHash query
- Fetch all PERSONAL_ACCESS_TOKENS rows and filter in Go
- Skip malformed/invalid JSON rows with continue (error recovery)
- Match SQLite/MySQL's forgiving error handling

New integration tests (store/test/user_setting_test.go):
- TestUserSettingGetUserByPATHashNoTokensKey
- TestUserSettingGetUserByPATHashEmptyTokensArray
- TestUserSettingGetUserByPATHashWithOtherUsers

New PostgreSQL-specific tests (store/db/postgres/user_setting_test.go):
- TestGetUserByPATHashWithMissingData (comprehensive edge cases)
- TestGetUserByPATHashPerformance (100+ users)
- TestUpsertUserSetting (basic upsert)

Test coverage:
 Missing PERSONAL_ACCESS_TOKENS key
 Empty/malformed JSON data
 Multiple users with mixed valid/invalid data
 Performance with 100+ users
 Error recovery without crashes

Benefits:
- No database migration required (TEXT column works fine)
- Backward compatible with v0.25.3 upgrades
- Handles missing/corrupt data gracefully
- Consistent behavior across all database drivers
2026-02-09 21:02:09 +08:00
..
activity.go chore: fix postgres stmts 2024-01-05 21:27:16 +08:00
attachment.go refactor(db): rename tables for clarity - resource→attachment, system_setting→instance_setting 2026-01-06 23:36:42 +08:00
common.go chore: fix postgres stmts 2024-01-05 21:27:16 +08:00
idp.go fix: create idp in postgres 2024-05-29 23:22:20 +08:00
inbox.go test: optimize store tests performance by reusing docker image and reducing build context 2026-01-12 23:30:56 +08:00
instance_setting.go revert: revert system_setting to instance_setting rename changes 2026-01-07 20:38:02 +08:00
memo.go feat: allow setting custom timestamps when creating memos and comments 2026-01-17 12:56:03 +08:00
memo_relation.go test: optimize store tests performance by reusing docker image and reducing build context 2026-01-12 23:30:56 +08:00
postgres.go chore: add store tests (#5397) 2025-12-31 21:26:35 +08:00
reaction.go fix(security): implement security review recommendations (#5228) 2025-11-06 23:32:27 +08:00
user.go refactor: memo filter 2025-10-16 09:22:52 +08:00
user_setting.go fix(postgres): handle missing PAT data gracefully and add comprehensive tests 2026-02-09 21:02:09 +08:00
user_setting_test.go fix(postgres): handle missing PAT data gracefully and add comprehensive tests 2026-02-09 21:02:09 +08:00