Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1897 - database migration to change VAProfile and Participant IDs to big integers #1901

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = (
Expand Down
53 changes: 53 additions & 0 deletions migrations/versions/0369a_va_profile_cache_fields.py
Original file line number Diff line number Diff line change
@@ -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 ###