From ef8bca007ddcbd10d58e83b1cc73533515bdb180 Mon Sep 17 00:00:00 2001 From: CID Date: Mon, 4 Mar 2024 17:11:31 +0000 Subject: [PATCH] Fix data length exceeding limit error This commit increases the length of the 'user' column to accommodate longer UUIDs, ensuring that the full user UUIDs are stored without exceeding the column limit. Closes-Bug: #2054594 Change-Id: I59b435ca2bb5850bb2338228b64868c2003bfea3 --- ...1d5e5195_increase_length_of_user_column.py | 33 +++++++++++++++++++ ironic/db/sqlalchemy/models.py | 2 +- .../unit/db/sqlalchemy/test_migrations.py | 16 +++++++++ ...ry_user_column_limit-8da6ae03288bff26.yaml | 6 ++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 ironic/db/sqlalchemy/alembic/versions/01f21d5e5195_increase_length_of_user_column.py create mode 100644 releasenotes/notes/increase_node_history_user_column_limit-8da6ae03288bff26.yaml diff --git a/ironic/db/sqlalchemy/alembic/versions/01f21d5e5195_increase_length_of_user_column.py b/ironic/db/sqlalchemy/alembic/versions/01f21d5e5195_increase_length_of_user_column.py new file mode 100644 index 0000000000..81dd88a8af --- /dev/null +++ b/ironic/db/sqlalchemy/alembic/versions/01f21d5e5195_increase_length_of_user_column.py @@ -0,0 +1,33 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""increase-length-of-user-column + +Revision ID: 01f21d5e5195 +Revises: aa2384fee727 +Create Date: 2024-03-05 11:02:08.996894 + +""" + +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = '01f21d5e5195' +down_revision = 'aa2384fee727' + + +def upgrade(): + op.alter_column('node_history', 'user', + existing_type=sa.String(length=32), + type_=sa.String(length=64), + existing_nullable=True) diff --git a/ironic/db/sqlalchemy/models.py b/ironic/db/sqlalchemy/models.py index 5660d7b1dd..ff4dcc522b 100644 --- a/ironic/db/sqlalchemy/models.py +++ b/ironic/db/sqlalchemy/models.py @@ -484,7 +484,7 @@ class NodeHistory(Base): event_type = Column(String(255), nullable=True) severity = Column(String(255), nullable=True) event = Column(Text, nullable=True) - user = Column(String(32), nullable=True) + user = Column(String(64), nullable=True) node_id = Column(Integer, ForeignKey('nodes.id'), nullable=True) diff --git a/ironic/tests/unit/db/sqlalchemy/test_migrations.py b/ironic/tests/unit/db/sqlalchemy/test_migrations.py index 3b44b04efa..416c7a5ba9 100644 --- a/ironic/tests/unit/db/sqlalchemy/test_migrations.py +++ b/ironic/tests/unit/db/sqlalchemy/test_migrations.py @@ -351,6 +351,22 @@ class MigrationCheckersMixin(object): self.assertIsInstance(nodes.c.inspection_finished_at.type, sqlalchemy.types.DateTime) + def _check_01f21d5e5195(self, engine, data): + node_history = db_utils.get_table(engine, 'node_history') + bigstring = 'a' * 64 + uuid = uuidutils.generate_uuid() + data = {'uuid': uuid, 'user': bigstring} + with engine.begin() as connection: + insert_node_history = node_history.insert().values(data) + connection.execute(insert_node_history) + node_history_stmt = sqlalchemy.select( + models.NodeHistory.user + ).where( + models.NodeHistory.uuid == uuid + ) + node_history = connection.execute(node_history_stmt).first() + self.assertEqual(bigstring, node_history.user) + def _check_4f399b21ae71(self, engine, data): nodes = db_utils.get_table(engine, 'nodes') col_names = [column.name for column in nodes.c] diff --git a/releasenotes/notes/increase_node_history_user_column_limit-8da6ae03288bff26.yaml b/releasenotes/notes/increase_node_history_user_column_limit-8da6ae03288bff26.yaml new file mode 100644 index 0000000000..e558f0b1e2 --- /dev/null +++ b/releasenotes/notes/increase_node_history_user_column_limit-8da6ae03288bff26.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Increases the 32-character limit of the ``user`` column in the + ``NodeHistory`` model to support up to 64-character-long values. + For more information, `see bug `_.