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
This commit is contained in:
CID 2024-03-04 17:11:31 +00:00 committed by cid
parent 43861609a8
commit ef8bca007d
4 changed files with 56 additions and 1 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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]

View File

@ -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 <https://bugs.launchpad.net/ironic/+bug/2054594>`_.