From af2d06ef6f654e96c4c1442adfdb77f13deee1d0 Mon Sep 17 00:00:00 2001 From: Mack Halliday Date: Tue, 6 Aug 2024 11:43:15 -0400 Subject: [PATCH] #1897 - participant_id and va_profile_id in VAProfileLocalCache updated to BigInt --- app/models.py | 4 +- .../versions/0369a_va_profile_cache_fields.py | 53 +++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 migrations/versions/0369a_va_profile_cache_fields.py diff --git a/app/models.py b/app/models.py index e5696b6fbd..b4d634610a 100644 --- a/app/models.py +++ b/app/models.py @@ -2176,12 +2176,12 @@ class VAProfileLocalCache(db.Model): id = db.Column(db.Integer, primary_key=True) allowed = db.Column(db.Boolean, nullable=False) - va_profile_id = db.Column(db.Integer, nullable=False) + va_profile_id = db.Column(db.BigInteger, nullable=False) communication_item_id = db.Column(db.Integer, nullable=False) communication_channel_id = db.Column(db.Integer, nullable=False) source_datetime = db.Column(db.DateTime, nullable=False) - participant_id = db.Column(db.Integer, nullable=True) + participant_id = db.Column(db.BigInteger, nullable=True) has_duplicate_mappings = db.Column(db.Boolean, nullable=False, default=False) __table_args__ = ( diff --git a/migrations/versions/0369a_va_profile_cache_fields.py b/migrations/versions/0369a_va_profile_cache_fields.py new file mode 100644 index 0000000000..0073078350 --- /dev/null +++ b/migrations/versions/0369a_va_profile_cache_fields.py @@ -0,0 +1,53 @@ +""" + +Revision ID:0369a_va_profile_cache_fields +Revises: 0369_va_profile_cache_fields +Create Date: 2024-08-05 15:10:01 + +""" +from alembic import op +import sqlalchemy as sa + +revision = '0369a_va_profile_cache_fields' +down_revision = '0369_va_profile_cache_fields' + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('va_profile_local_cache', 'va_profile_id', + existing_type=sa.INTEGER(), + type_=sa.BigInteger(), + existing_nullable=False) + op.alter_column('va_profile_local_cache', 'participant_id', + existing_type=sa.INTEGER(), + type_=sa.BigInteger(), + existing_nullable=True) + # ### end Alembic commands ### + + +def downgrade(): + + # Update participant_id to -1 where it cannot be converted back to INTEGER + op.execute(""" + UPDATE va_profile_local_cache + SET participant_id = -1 + WHERE participant_id > 2147483647 + """) + + # Delete rows where va_profile_id cannot be converted back to INTEGER + op.execute(""" + DELETE FROM va_profile_local_cache + WHERE va_profile_id > 2147483647 + """) + + + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('va_profile_local_cache', 'participant_id', + existing_type=sa.BigInteger(), + type_=sa.INTEGER(), + existing_nullable=True) + op.alter_column('va_profile_local_cache', 'va_profile_id', + existing_type=sa.BigInteger(), + type_=sa.INTEGER(), + existing_nullable=False) + # ### end Alembic commands ###