From 2fa7ef5e71bf7454394f7860327244e0f510ddc8 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 8 Aug 2023 11:05:15 -0500 Subject: [PATCH] Grow all ID fields for Harvest cache tables turns out Integer is not big enough, need BigInteger --- .../versions/f2a1650e7fbc_grow_id_fields.py | 89 +++++++++++++++++++ rattail_harvest/db/model/harvest.py | 24 ++--- 2 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 rattail_harvest/db/alembic/versions/f2a1650e7fbc_grow_id_fields.py diff --git a/rattail_harvest/db/alembic/versions/f2a1650e7fbc_grow_id_fields.py b/rattail_harvest/db/alembic/versions/f2a1650e7fbc_grow_id_fields.py new file mode 100644 index 0000000..0c24bb5 --- /dev/null +++ b/rattail_harvest/db/alembic/versions/f2a1650e7fbc_grow_id_fields.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8; -*- +"""grow id fields + +Revision ID: f2a1650e7fbc +Revises: 6bc1cb21d920 +Create Date: 2023-08-08 10:53:56.013211 + +""" + +# revision identifiers, used by Alembic. +revision = 'f2a1650e7fbc' +down_revision = '6bc1cb21d920' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa +import rattail.db.types +from sqlalchemy.dialects import postgresql + + +def upgrade(): + + # harvest_user + op.alter_column('harvest_user', 'id', type_=sa.BigInteger()) + op.alter_column('harvest_user_version', 'id', type_=sa.BigInteger()) + + # harvest_client + op.alter_column('harvest_client', 'id', type_=sa.BigInteger()) + op.alter_column('harvest_client_version', 'id', type_=sa.BigInteger()) + + # harvest_project + op.alter_column('harvest_project', 'id', type_=sa.BigInteger()) + op.alter_column('harvest_project', 'client_id', type_=sa.BigInteger()) + op.alter_column('harvest_project_version', 'id', type_=sa.BigInteger()) + op.alter_column('harvest_project_version', 'client_id', type_=sa.BigInteger()) + + # harvest_task + op.alter_column('harvest_task', 'id', type_=sa.BigInteger()) + op.alter_column('harvest_task_version', 'id', type_=sa.BigInteger()) + + # harvest_time_entry + op.alter_column('harvest_time_entry', 'id', type_=sa.BigInteger()) + op.alter_column('harvest_time_entry', 'user_id', type_=sa.BigInteger()) + op.alter_column('harvest_time_entry', 'client_id', type_=sa.BigInteger()) + op.alter_column('harvest_time_entry', 'project_id', type_=sa.BigInteger()) + op.alter_column('harvest_time_entry', 'task_id', type_=sa.BigInteger()) + op.alter_column('harvest_time_entry', 'invoice_id', type_=sa.BigInteger()) + op.alter_column('harvest_time_entry_version', 'id', type_=sa.BigInteger()) + op.alter_column('harvest_time_entry_version', 'user_id', type_=sa.BigInteger()) + op.alter_column('harvest_time_entry_version', 'client_id', type_=sa.BigInteger()) + op.alter_column('harvest_time_entry_version', 'project_id', type_=sa.BigInteger()) + op.alter_column('harvest_time_entry_version', 'task_id', type_=sa.BigInteger()) + op.alter_column('harvest_time_entry_version', 'invoice_id', type_=sa.BigInteger()) + + +def downgrade(): + + # harvest_time_entry + op.alter_column('harvest_time_entry_version', 'id', type_=sa.Integer()) + op.alter_column('harvest_time_entry_version', 'user_id', type_=sa.Integer()) + op.alter_column('harvest_time_entry_version', 'client_id', type_=sa.Integer()) + op.alter_column('harvest_time_entry_version', 'project_id', type_=sa.Integer()) + op.alter_column('harvest_time_entry_version', 'task_id', type_=sa.Integer()) + op.alter_column('harvest_time_entry_version', 'invoice_id', type_=sa.Integer()) + op.alter_column('harvest_time_entry', 'id', type_=sa.Integer()) + op.alter_column('harvest_time_entry', 'user_id', type_=sa.Integer()) + op.alter_column('harvest_time_entry', 'client_id', type_=sa.Integer()) + op.alter_column('harvest_time_entry', 'project_id', type_=sa.Integer()) + op.alter_column('harvest_time_entry', 'task_id', type_=sa.Integer()) + op.alter_column('harvest_time_entry', 'invoice_id', type_=sa.Integer()) + + # harvest_task + op.alter_column('harvest_task_version', 'id', type_=sa.Integer()) + op.alter_column('harvest_task', 'id', type_=sa.Integer()) + + # harvest_project + op.alter_column('harvest_project_version', 'id', type_=sa.Integer()) + op.alter_column('harvest_project_version', 'client_id', type_=sa.Integer()) + op.alter_column('harvest_project', 'id', type_=sa.Integer()) + op.alter_column('harvest_project', 'client_id', type_=sa.Integer()) + + # harvest_client + op.alter_column('harvest_client_version', 'id', type_=sa.Integer()) + op.alter_column('harvest_client', 'id', type_=sa.Integer()) + + # harvest_user + op.alter_column('harvest_user_version', 'id', type_=sa.Integer()) + op.alter_column('harvest_user', 'id', type_=sa.Integer()) diff --git a/rattail_harvest/db/model/harvest.py b/rattail_harvest/db/model/harvest.py index 7ac7506..fd3a8ee 100644 --- a/rattail_harvest/db/model/harvest.py +++ b/rattail_harvest/db/model/harvest.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2022 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -46,7 +46,7 @@ class HarvestUser(model.Base): uuid = model.uuid_column() - id = sa.Column(sa.Integer(), nullable=False) + id = sa.Column(sa.BigInteger(), nullable=False) first_name = sa.Column(sa.String(length=255), nullable=True) @@ -122,7 +122,7 @@ class HarvestClient(model.Base): uuid = model.uuid_column() - id = sa.Column(sa.Integer(), nullable=False) + id = sa.Column(sa.BigInteger(), nullable=False) name = sa.Column(sa.String(length=255), nullable=True) @@ -155,9 +155,9 @@ class HarvestProject(model.Base): uuid = model.uuid_column() - id = sa.Column(sa.Integer(), nullable=False) + id = sa.Column(sa.BigInteger(), nullable=False) - client_id = sa.Column(sa.Integer(), nullable=True) # TODO: should not allow null? + client_id = sa.Column(sa.BigInteger(), nullable=True) # TODO: should not allow null? client = orm.relationship(HarvestClient, backref=orm.backref('projects')) name = sa.Column(sa.String(length=255), nullable=True) @@ -226,7 +226,7 @@ class HarvestTask(model.Base): uuid = model.uuid_column() - id = sa.Column(sa.Integer(), nullable=False) + id = sa.Column(sa.BigInteger(), nullable=False) name = sa.Column(sa.String(length=255), nullable=True) @@ -265,23 +265,23 @@ class HarvestTimeEntry(model.Base): uuid = model.uuid_column() - id = sa.Column(sa.Integer(), nullable=False) + id = sa.Column(sa.BigInteger(), nullable=False) spent_date = sa.Column(sa.Date(), nullable=True) - user_id = sa.Column(sa.Integer(), nullable=True) + user_id = sa.Column(sa.BigInteger(), nullable=True) user = orm.relationship(HarvestUser, backref=orm.backref('time_entries')) - client_id = sa.Column(sa.Integer(), nullable=True) + client_id = sa.Column(sa.BigInteger(), nullable=True) client = orm.relationship(HarvestClient, backref=orm.backref('time_entries')) - project_id = sa.Column(sa.Integer(), nullable=True) + project_id = sa.Column(sa.BigInteger(), nullable=True) project = orm.relationship(HarvestProject, backref=orm.backref('time_entries')) - task_id = sa.Column(sa.Integer(), nullable=True) + task_id = sa.Column(sa.BigInteger(), nullable=True) task = orm.relationship(HarvestTask, backref=orm.backref('time_entries')) - invoice_id = sa.Column(sa.Integer(), nullable=True) + invoice_id = sa.Column(sa.BigInteger(), nullable=True) hours = sa.Column(sa.Numeric(precision=6, scale=2), nullable=True)