From 1ab360772cc12eef9002c992ba74aa36b1fdeeb8 Mon Sep 17 00:00:00 2001 From: "OMAR.A" <58332033+civilcoder55@users.noreply.github.com> Date: Fri, 7 Aug 2026 19:40:03 +0300 Subject: [PATCH] alembic: Preserve sub-second precision in the queue_log time column. ast_queue_log() formats realtime queue_log timestamps with microseconds ("%F %T.%6q" in main/logger.c), but the queue_log table declares 'time' as a generic SQLAlchemy DateTime. That renders on MySQL and MariaDB as bare DATETIME, which has a fractional-seconds precision of 0, so MariaDB truncates the fraction and MySQL rounds it. Every event of a single queue entry can collapse onto one second, or move to the next one, and neither server warns, not even in strict mode. Once that happens, queue_log rows can no longer be ordered against each other, or against the CEL records that cel_odbc and cel_pgsql do stamp with microseconds. This adds a revision that widens the queue_log column to DATETIME(6) on MySQL and MariaDB. PostgreSQL is unaffected and left untouched: DateTime already renders as TIMESTAMP, which keeps microseconds by default. Fixes: #2072 UpgradeNote: (schema) On MySQL and MariaDB the queue_log 'time' column is widened from DATETIME to DATETIME(6) so that the microsecond timestamps Asterisk already writes are stored rather than discarded. This ALTER rewrites the table, a datetime precision change is neither INSTANT nor INPLACE, so queue_log writes will block for its duration on a large table. PostgreSQL installations are unaffected. Rows already written at whole-second precision will remain as-is and won't be updated. --- ...f4b17_increase_queue_log_time_precision.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 contrib/ast-db-manage/queue_log/versions/8e6a9c2f4b17_increase_queue_log_time_precision.py diff --git a/contrib/ast-db-manage/queue_log/versions/8e6a9c2f4b17_increase_queue_log_time_precision.py b/contrib/ast-db-manage/queue_log/versions/8e6a9c2f4b17_increase_queue_log_time_precision.py new file mode 100644 index 0000000000..36506ef130 --- /dev/null +++ b/contrib/ast-db-manage/queue_log/versions/8e6a9c2f4b17_increase_queue_log_time_precision.py @@ -0,0 +1,38 @@ +"""increase queue_log time precision + +Revision ID: 8e6a9c2f4b17 +Revises: 4105ee839f58 +Create Date: 2026-08-03 00:00:00.000000 + +""" + +# revision identifiers, used by Alembic. +revision = "8e6a9c2f4b17" +down_revision = "4105ee839f58" + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects.mysql import DATETIME as MYSQL_DATETIME + + +def upgrade(): + # MariaDB is reported as the 'mysql' dialect, so this covers both. + if op.get_context().bind.dialect.name == "mysql": + op.alter_column( + "queue_log", + "time", + existing_type=sa.DateTime(), + type_=MYSQL_DATETIME(fsp=6), + existing_nullable=True, + ) + + +def downgrade(): + if op.get_context().bind.dialect.name == "mysql": + op.alter_column( + "queue_log", + "time", + existing_type=MYSQL_DATETIME(fsp=6), + type_=sa.DateTime(), + existing_nullable=True, + )