Fix MUC room created_at timestamp and add updated_at field#4464
Fix MUC room created_at timestamp and add updated_at field#4464YonesSohrabi wants to merge 1 commit intoprocessone:masterfrom
Conversation
prefiks
left a comment
There was a problem hiding this comment.
I see two things that require change:
- sql files in sql/ will need to be update with that new column definitions
- store_room can be simplified by just using special syntax in in upsert statement (check by comment near this code).
| "!host=%(Host)s", | ||
| "server_host=%(LServer)s", | ||
| "opts=%(SOpts)s", | ||
| "created_at=%(CreatedAt)t", |
There was a problem hiding this comment.
I believe you can replace that whole conditional code by just having single upsert with "-created_at=..." instead of "created_at=...", having "-" at start will only make that field be set when value is inserted.
1803f80 to
644a79e
Compare
|
Hi @Neustradamus and @prefiks , Thank you for the feedback! I've updated the PR based on the review comments: Changes Made1. Simplified
|
- Add updated_at column to muc_room table schema - Use UPSERT special syntax (-created_at) to preserve created_at on updates - Set created_at to current time for new rooms (not 1970-01-02) - Add hibernation_time support in format_room_option - Update SQL files: mysql.new.sql, pg.new.sql, lite.new.sql, mssql.new.sql - Include migration guide and SQL scripts This fixes the issue where newly created MUC rooms have created_at = 1970-01-02 00:00:00 instead of actual creation time. The solution: - Uses ejabberd's UPSERT special syntax where '-field' means 'only set on INSERT, not on UPDATE' - Adds updated_at column to properly track room modifications - Separates concerns: created_at vs updated_at vs hibernation_time
644a79e to
ec12913
Compare
|
@Neustradamus Thank you for the feedback! I've updated the PR: ✅ Updated all SQL files:
✅ Added issue references:
✅ Simplified code using All SQL schema files now include the |
|
I will try to review this today |
|
Hi @YonesSohrabi, many thanks for your contribution! In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. |
Fixes
This PR fixes the following issues:
created_attimestamp incorrectly set to 1970-01-02Summary
This PR fixes the issue where newly created MUC rooms have
created_at = 1970-01-02 00:00:00and adds proper separation between creation time and update time.Problem
Currently:
created_at = 1970-01-02 00:00:00created_atchanges on every room update (UPSERT behavior)hibernation_timeandcreated_atSolution
This PR:
updated_atcolumn tomuc_roomtablecreated_atis set once on creation and never changesupdated_atcreated_at≠updated_at≠hibernation_timehibernation_timesupport in API (optional)Changes
Modified Files
src/mod_muc_sql.erl(lines 75-78, 142-185, 295)updated_atcolumn to schemastore_room/5to check if room exists:created_at, updateupdated_at1970-01-02 00:00:00fallbackget_hibernated_rooms_older_thanquerysrc/mod_muc_admin.erl(line 1734)hibernation_timesupport informat_room_optionNew Files
PULL_REQUEST_PROPOSAL.md- Detailed analysis with alternativesMIGRATION_GUIDE.md- Step-by-step migration instructionssql/migration_add_updated_at.sql- SQL migration scriptDatabase Migration Required
See
MIGRATION_GUIDE.mdfor complete instructions for all databases.Testing
Before This PR
After This PR
Backward Compatibility
✅ Fully backward compatible with migration script
✅ No breaking changes to API
✅ Existing rooms work without changes
✅ Old rooms can be updated with migration script
Benefits
created_at+updated_atpatternDocumentation
PULL_REQUEST_PROPOSAL.md: Detailed problem analysis and alternative solutionsMIGRATION_GUIDE.md: Complete migration instructions with troubleshootingsql/migration_add_updated_at.sql: Ready-to-use SQL migration scriptsChecklist
Related Files
src/mod_muc_sql.erl- Main changessrc/mod_muc_admin.erl- API supportPULL_REQUEST_PROPOSAL.md- Detailed proposalMIGRATION_GUIDE.md- Migration instructions