memos/store
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
..
cache fix: resolve linter warning and cache race condition 2026-01-14 23:50:37 +08:00
db fix(postgres): handle missing PAT data gracefully and add comprehensive tests 2026-02-09 21:02:09 +08:00
migration refactor: migrate HOST roles to ADMIN 2026-01-20 23:38:30 +08:00
seed fix: update demo mode handling 2026-01-21 07:36:30 +08:00
test fix(postgres): handle missing PAT data gracefully and add comprehensive tests 2026-02-09 21:02:09 +08:00
activity.go chore: remove version update activity 2025-02-09 11:48:53 +08:00
attachment.go feat: implement attachment filtering functionality 2025-12-28 18:47:59 +08:00
cache.go chore: update store cache 2024-05-12 13:19:31 +08:00
common.go chore: update workspace setting store 2024-04-13 02:08:35 +08:00
driver.go refactor: user auth improvements (#5360) 2025-12-18 18:15:51 +08:00
idp.go refactor: store cache 2025-05-27 22:06:41 +08:00
inbox.go fix(store): filter inbox notifications by message type at database level 2025-12-01 08:43:05 +08:00
instance_setting.go refactor: remove NSFW content settings from instance configuration 2025-12-29 20:13:54 +08:00
memo.go fix: clean up memo_relation and attachments when deleting memo 2026-01-12 23:18:04 +08:00
memo_relation.go fix: list memo relations 2025-04-12 22:02:13 +08:00
migrator.go refactor: migrate HOST roles to ADMIN 2026-01-20 23:38:30 +08:00
reaction.go fix(security): implement security review recommendations (#5228) 2025-11-06 23:32:27 +08:00
store.go refactor: rename workspace to instance throughout codebase 2025-11-05 23:35:35 +08:00
user.go refactor: migrate HOST roles to ADMIN 2026-01-20 23:38:30 +08:00
user_setting.go refactor: remove deprecated Sessions and AccessTokens settings 2025-12-19 08:35:57 +08:00