Rename all tables/models for Harvest "cache"
make this more explicit, for better naming convention
This commit is contained in:
parent
509405cb34
commit
aa87ce57be
7 changed files with 324 additions and 88 deletions
|
@ -0,0 +1,179 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
"""rename cache tables
|
||||
|
||||
Revision ID: 53c066772ad5
|
||||
Revises: f2a1650e7fbc
|
||||
Create Date: 2023-10-04 15:19:03.857323
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '53c066772ad5'
|
||||
down_revision = 'f2a1650e7fbc'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import rattail.db.types
|
||||
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
||||
##############################
|
||||
# drop all constraints
|
||||
##############################
|
||||
|
||||
# harvest_time_entry
|
||||
op.drop_constraint('harvest_time_entry_fk_user', 'harvest_time_entry', type_='foreignkey')
|
||||
op.drop_constraint('harvest_time_entry_fk_client', 'harvest_time_entry', type_='foreignkey')
|
||||
op.drop_constraint('harvest_time_entry_fk_project', 'harvest_time_entry', type_='foreignkey')
|
||||
op.drop_constraint('harvest_time_entry_fk_task', 'harvest_time_entry', type_='foreignkey')
|
||||
op.drop_constraint('harvest_time_entry_uq_id', 'harvest_time_entry', type_='unique')
|
||||
|
||||
# harvest_task
|
||||
op.drop_constraint('harvest_task_uq_id', 'harvest_task', type_='unique')
|
||||
|
||||
# harvest_project
|
||||
op.drop_constraint('harvest_project_fk_client', 'harvest_project', type_='foreignkey')
|
||||
op.drop_constraint('harvest_project_uq_id', 'harvest_project', type_='unique')
|
||||
|
||||
# harvest_client
|
||||
op.drop_constraint('harvest_client_uq_id', 'harvest_client', type_='unique')
|
||||
|
||||
# harvest_user
|
||||
op.drop_constraint('harvest_user_fk_person', 'harvest_user', type_='foreignkey')
|
||||
op.drop_constraint('harvest_user_uq_id', 'harvest_user', type_='unique')
|
||||
|
||||
##############################
|
||||
# rename all tables
|
||||
##############################
|
||||
|
||||
op.rename_table('harvest_user', 'harvest_cache_user')
|
||||
op.rename_table('harvest_user_version', 'harvest_cache_user_version')
|
||||
op.rename_table('harvest_client', 'harvest_cache_client')
|
||||
op.rename_table('harvest_client_version', 'harvest_cache_client_version')
|
||||
op.rename_table('harvest_project', 'harvest_cache_project')
|
||||
op.rename_table('harvest_project_version', 'harvest_cache_project_version')
|
||||
op.rename_table('harvest_task', 'harvest_cache_task')
|
||||
op.rename_table('harvest_task_version', 'harvest_cache_task_version')
|
||||
op.rename_table('harvest_time_entry', 'harvest_cache_time_entry')
|
||||
op.rename_table('harvest_time_entry_version', 'harvest_cache_time_entry_version')
|
||||
|
||||
##############################
|
||||
# re-create all constraints
|
||||
##############################
|
||||
|
||||
# harvest_cache_user
|
||||
op.create_foreign_key('harvest_cache_user_fk_person',
|
||||
'harvest_cache_user', 'person',
|
||||
['person_uuid'], ['uuid'])
|
||||
op.create_unique_constraint('harvest_cache_user_uq_id', 'harvest_cache_user', ['id'])
|
||||
|
||||
# harvest_cache_client
|
||||
op.create_unique_constraint('harvest_cache_client_uq_id', 'harvest_cache_client', ['id'])
|
||||
|
||||
# harvest_cache_project
|
||||
op.create_foreign_key('harvest_cache_project_fk_client',
|
||||
'harvest_cache_project', 'harvest_cache_client',
|
||||
['client_id'], ['id'])
|
||||
op.create_unique_constraint('harvest_cache_project_uq_id', 'harvest_cache_project', ['id'])
|
||||
|
||||
# harvest_cache_task
|
||||
op.create_unique_constraint('harvest_cache_task_uq_id', 'harvest_cache_task', ['id'])
|
||||
|
||||
# harvest_cache_time_entry
|
||||
op.create_foreign_key('harvest_cache_time_entry_fk_user',
|
||||
'harvest_cache_time_entry', 'harvest_cache_user',
|
||||
['user_id'], ['id'])
|
||||
op.create_foreign_key('harvest_cache_time_entry_fk_client',
|
||||
'harvest_cache_time_entry', 'harvest_cache_client',
|
||||
['client_id'], ['id'])
|
||||
op.create_foreign_key('harvest_cache_time_entry_fk_project',
|
||||
'harvest_cache_time_entry', 'harvest_cache_project',
|
||||
['project_id'], ['id'])
|
||||
op.create_foreign_key('harvest_cache_time_entry_fk_task',
|
||||
'harvest_cache_time_entry', 'harvest_cache_task',
|
||||
['task_id'], ['id'])
|
||||
op.create_unique_constraint('harvest_cache_time_entry_uq_id', 'harvest_cache_time_entry', ['id'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
##############################
|
||||
# drop all constraints
|
||||
##############################
|
||||
|
||||
# harvest_cache_time_entry
|
||||
op.drop_constraint('harvest_cache_time_entry_fk_user', 'harvest_cache_time_entry', type_='foreignkey')
|
||||
op.drop_constraint('harvest_cache_time_entry_fk_client', 'harvest_cache_time_entry', type_='foreignkey')
|
||||
op.drop_constraint('harvest_cache_time_entry_fk_project', 'harvest_cache_time_entry', type_='foreignkey')
|
||||
op.drop_constraint('harvest_cache_time_entry_fk_task', 'harvest_cache_time_entry', type_='foreignkey')
|
||||
op.drop_constraint('harvest_cache_time_entry_uq_id', 'harvest_cache_time_entry', type_='unique')
|
||||
|
||||
# harvest_cache_task
|
||||
op.drop_constraint('harvest_cache_task_uq_id', 'harvest_cache_task', type_='unique')
|
||||
|
||||
# harvest_cache_project
|
||||
op.drop_constraint('harvest_cache_project_fk_client', 'harvest_cache_project', type_='foreignkey')
|
||||
op.drop_constraint('harvest_cache_project_uq_id', 'harvest_cache_project', type_='unique')
|
||||
|
||||
# harvest_cache_client
|
||||
op.drop_constraint('harvest_cache_client_uq_id', 'harvest_cache_client', type_='unique')
|
||||
|
||||
# harvest_cache_user
|
||||
op.drop_constraint('harvest_cache_user_fk_person', 'harvest_cache_user', type_='foreignkey')
|
||||
op.drop_constraint('harvest_cache_user_uq_id', 'harvest_cache_user', type_='unique')
|
||||
|
||||
##############################
|
||||
# rename all tables
|
||||
##############################
|
||||
|
||||
op.rename_table('harvest_cache_user', 'harvest_user')
|
||||
op.rename_table('harvest_cache_user_version', 'harvest_user_version')
|
||||
op.rename_table('harvest_cache_client', 'harvest_client')
|
||||
op.rename_table('harvest_cache_client_version', 'harvest_client_version')
|
||||
op.rename_table('harvest_cache_project', 'harvest_project')
|
||||
op.rename_table('harvest_cache_project_version', 'harvest_project_version')
|
||||
op.rename_table('harvest_cache_task', 'harvest_task')
|
||||
op.rename_table('harvest_cache_task_version', 'harvest_task_version')
|
||||
op.rename_table('harvest_cache_time_entry', 'harvest_time_entry')
|
||||
op.rename_table('harvest_cache_time_entry_version', 'harvest_time_entry_version')
|
||||
|
||||
##############################
|
||||
# re-create all constraints
|
||||
##############################
|
||||
|
||||
# harvest_user
|
||||
op.create_foreign_key('harvest_user_fk_person',
|
||||
'harvest_user', 'person',
|
||||
['person_uuid'], ['uuid'])
|
||||
op.create_unique_constraint('harvest_user_uq_id', 'harvest_user', ['id'])
|
||||
|
||||
# harvest_client
|
||||
op.create_unique_constraint('harvest_client_uq_id', 'harvest_client', ['id'])
|
||||
|
||||
# harvest_project
|
||||
op.create_foreign_key('harvest_project_fk_client',
|
||||
'harvest_project', 'harvest_client',
|
||||
['client_id'], ['id'])
|
||||
op.create_unique_constraint('harvest_project_uq_id', 'harvest_project', ['id'])
|
||||
|
||||
# harvest_cache_task
|
||||
op.create_unique_constraint('harvest_task_uq_id', 'harvest_task', ['id'])
|
||||
|
||||
# harvest_time_entry
|
||||
op.create_foreign_key('harvest_time_entry_fk_user',
|
||||
'harvest_time_entry', 'harvest_user',
|
||||
['user_id'], ['id'])
|
||||
op.create_foreign_key('harvest_time_entry_fk_client',
|
||||
'harvest_time_entry', 'harvest_client',
|
||||
['client_id'], ['id'])
|
||||
op.create_foreign_key('harvest_time_entry_fk_project',
|
||||
'harvest_time_entry', 'harvest_project',
|
||||
['project_id'], ['id'])
|
||||
op.create_foreign_key('harvest_time_entry_fk_task',
|
||||
'harvest_time_entry', 'harvest_task',
|
||||
['task_id'], ['id'])
|
||||
op.create_unique_constraint('harvest_time_entry_uq_id', 'harvest_time_entry', ['id'])
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -24,5 +24,9 @@
|
|||
Harvest integration data models
|
||||
"""
|
||||
|
||||
from .harvest import (HarvestUser, HarvestClient, HarvestProject,
|
||||
from .harvest import (HarvestCacheUser, HarvestCacheClient,
|
||||
HarvestCacheProject, HarvestCacheTask,
|
||||
HarvestCacheTimeEntry,
|
||||
# TODO: deprecate / remove these
|
||||
HarvestUser, HarvestClient, HarvestProject,
|
||||
HarvestTask, HarvestTimeEntry)
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
Harvest "cache" data models
|
||||
"""
|
||||
|
||||
import warnings
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
|
@ -31,16 +33,17 @@ from rattail.db import model
|
|||
from rattail.db.util import normalize_full_name
|
||||
|
||||
|
||||
class HarvestUser(model.Base):
|
||||
class HarvestCacheUser(model.Base):
|
||||
"""
|
||||
Represents a user record in Harvest.
|
||||
|
||||
https://help.getharvest.com/api-v2/users-api/users/users/#the-user-object
|
||||
"""
|
||||
__tablename__ = 'harvest_user'
|
||||
__tablename__ = 'harvest_cache_user'
|
||||
__table_args__ = (
|
||||
sa.ForeignKeyConstraint(['person_uuid'], ['person.uuid'], name='harvest_user_fk_person'),
|
||||
sa.UniqueConstraint('id', name='harvest_user_uq_id'),
|
||||
sa.ForeignKeyConstraint(['person_uuid'], ['person.uuid'],
|
||||
name='harvest_cache_user_fk_person'),
|
||||
sa.UniqueConstraint('id', name='harvest_cache_user_uq_id'),
|
||||
)
|
||||
__versioned__ = {}
|
||||
|
||||
|
@ -108,15 +111,24 @@ class HarvestUser(model.Base):
|
|||
return normalize_full_name(self.first_name, self.last_name)
|
||||
|
||||
|
||||
class HarvestClient(model.Base):
|
||||
class HarvestUser(HarvestCacheUser):
|
||||
""" DEPRECATED """
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn("HarvestUser class is deprecated; "
|
||||
"please use HarvestCacheUser instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
|
||||
class HarvestCacheClient(model.Base):
|
||||
"""
|
||||
Represents a client record in Harvest.
|
||||
|
||||
https://help.getharvest.com/api-v2/clients-api/clients/clients/#the-client-object
|
||||
"""
|
||||
__tablename__ = 'harvest_client'
|
||||
__tablename__ = 'harvest_cache_client'
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('id', name='harvest_client_uq_id'),
|
||||
sa.UniqueConstraint('id', name='harvest_cache_client_uq_id'),
|
||||
)
|
||||
__versioned__ = {}
|
||||
|
||||
|
@ -140,16 +152,26 @@ class HarvestClient(model.Base):
|
|||
return self.name or ''
|
||||
|
||||
|
||||
class HarvestProject(model.Base):
|
||||
class HarvestClient(HarvestCacheClient):
|
||||
""" DEPRECATED """
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn("HarvestClient class is deprecated; "
|
||||
"please use HarvestCacheClient instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
|
||||
class HarvestCacheProject(model.Base):
|
||||
"""
|
||||
Represents a project record in Harvest.
|
||||
|
||||
https://help.getharvest.com/api-v2/projects-api/projects/projects/#the-project-object
|
||||
"""
|
||||
__tablename__ = 'harvest_project'
|
||||
__tablename__ = 'harvest_cache_project'
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('id', name='harvest_project_uq_id'),
|
||||
sa.ForeignKeyConstraint(['client_id'], ['harvest_client.id'], name='harvest_project_fk_client'),
|
||||
sa.UniqueConstraint('id', name='harvest_cache_project_uq_id'),
|
||||
sa.ForeignKeyConstraint(['client_id'], ['harvest_cache_client.id'],
|
||||
name='harvest_cache_project_fk_client'),
|
||||
)
|
||||
__versioned__ = {'exclude': ['over_budget_notification_date']}
|
||||
|
||||
|
@ -158,7 +180,7 @@ class HarvestProject(model.Base):
|
|||
id = sa.Column(sa.BigInteger(), nullable=False)
|
||||
|
||||
client_id = sa.Column(sa.BigInteger(), nullable=True) # TODO: should not allow null?
|
||||
client = orm.relationship(HarvestClient, backref=orm.backref('projects'))
|
||||
client = orm.relationship(HarvestCacheClient, backref=orm.backref('projects'))
|
||||
|
||||
name = sa.Column(sa.String(length=255), nullable=True)
|
||||
|
||||
|
@ -212,15 +234,24 @@ class HarvestProject(model.Base):
|
|||
return self.name or ''
|
||||
|
||||
|
||||
class HarvestTask(model.Base):
|
||||
class HarvestProject(HarvestCacheProject):
|
||||
""" DEPRECATED """
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn("HarvestProject class is deprecated; "
|
||||
"please use HarvestCacheProject instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
|
||||
class HarvestCacheTask(model.Base):
|
||||
"""
|
||||
Represents a task record in Harvest.
|
||||
|
||||
https://help.getharvest.com/api-v2/tasks-api/tasks/tasks/#the-task-object
|
||||
"""
|
||||
__tablename__ = 'harvest_task'
|
||||
__tablename__ = 'harvest_cache_task'
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('id', name='harvest_task_uq_id'),
|
||||
sa.UniqueConstraint('id', name='harvest_cache_task_uq_id'),
|
||||
)
|
||||
__versioned__ = {}
|
||||
|
||||
|
@ -246,19 +277,32 @@ class HarvestTask(model.Base):
|
|||
return self.name or ''
|
||||
|
||||
|
||||
class HarvestTimeEntry(model.Base):
|
||||
class HarvestTask(HarvestCacheTask):
|
||||
""" DEPRECATED """
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn("HarvestTask class is deprecated; "
|
||||
"please use HarvestCacheTask instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
|
||||
class HarvestCacheTimeEntry(model.Base):
|
||||
"""
|
||||
Represents a time entry record in Harvest.
|
||||
|
||||
https://help.getharvest.com/api-v2/timesheets-api/timesheets/time-entries/#the-time-entry-object
|
||||
"""
|
||||
__tablename__ = 'harvest_time_entry'
|
||||
__tablename__ = 'harvest_cache_time_entry'
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('id', name='harvest_time_entry_uq_id'),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['harvest_user.id'], name='harvest_time_entry_fk_user'),
|
||||
sa.ForeignKeyConstraint(['client_id'], ['harvest_client.id'], name='harvest_time_entry_fk_client'),
|
||||
sa.ForeignKeyConstraint(['project_id'], ['harvest_project.id'], name='harvest_time_entry_fk_project'),
|
||||
sa.ForeignKeyConstraint(['task_id'], ['harvest_task.id'], name='harvest_time_entry_fk_task'),
|
||||
sa.UniqueConstraint('id', name='harvest_cache_time_entry_uq_id'),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['harvest_cache_user.id'],
|
||||
name='harvest_cache_time_entry_fk_user'),
|
||||
sa.ForeignKeyConstraint(['client_id'], ['harvest_cache_client.id'],
|
||||
name='harvest_cache_time_entry_fk_client'),
|
||||
sa.ForeignKeyConstraint(['project_id'], ['harvest_cache_project.id'],
|
||||
name='harvest_cache_time_entry_fk_project'),
|
||||
sa.ForeignKeyConstraint(['task_id'], ['harvest_cache_task.id'],
|
||||
name='harvest_cache_time_entry_fk_task'),
|
||||
)
|
||||
__versioned__ = {}
|
||||
model_title_plural = "Harvest Time Entries"
|
||||
|
@ -270,16 +314,16 @@ class HarvestTimeEntry(model.Base):
|
|||
spent_date = sa.Column(sa.Date(), nullable=True)
|
||||
|
||||
user_id = sa.Column(sa.BigInteger(), nullable=True)
|
||||
user = orm.relationship(HarvestUser, backref=orm.backref('time_entries'))
|
||||
user = orm.relationship(HarvestCacheUser, backref=orm.backref('time_entries'))
|
||||
|
||||
client_id = sa.Column(sa.BigInteger(), nullable=True)
|
||||
client = orm.relationship(HarvestClient, backref=orm.backref('time_entries'))
|
||||
client = orm.relationship(HarvestCacheClient, backref=orm.backref('time_entries'))
|
||||
|
||||
project_id = sa.Column(sa.BigInteger(), nullable=True)
|
||||
project = orm.relationship(HarvestProject, backref=orm.backref('time_entries'))
|
||||
project = orm.relationship(HarvestCacheProject, backref=orm.backref('time_entries'))
|
||||
|
||||
task_id = sa.Column(sa.BigInteger(), nullable=True)
|
||||
task = orm.relationship(HarvestTask, backref=orm.backref('time_entries'))
|
||||
task = orm.relationship(HarvestCacheTask, backref=orm.backref('time_entries'))
|
||||
|
||||
invoice_id = sa.Column(sa.BigInteger(), nullable=True)
|
||||
|
||||
|
@ -317,3 +361,12 @@ class HarvestTimeEntry(model.Base):
|
|||
|
||||
def __str__(self):
|
||||
return str(self.spent_date or '')
|
||||
|
||||
|
||||
class HarvestTimeEntry(HarvestCacheTimeEntry):
|
||||
""" DEPRECATED """
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn("HarvestTimeEntry class is deprecated; "
|
||||
"please use HarvestCacheTimeEntry instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue