Add HarvestUser.person association

importer does not set this; you must do so manually
This commit is contained in:
Lance Edgar 2022-01-30 17:40:19 -06:00
parent 3883a8551f
commit ec78f8c9c4
6 changed files with 210 additions and 8 deletions

View file

@ -0,0 +1,35 @@
# -*- coding: utf-8; -*-
"""add harvest_user.person
Revision ID: 6bc1cb21d920
Revises: 5505c0e60d28
Create Date: 2022-01-30 16:49:32.271745
"""
# revision identifiers, used by Alembic.
revision = '6bc1cb21d920'
down_revision = '5505c0e60d28'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
import rattail.db.types
def upgrade():
# harvest_user
op.add_column('harvest_user', sa.Column('person_uuid', sa.String(length=32), nullable=True))
op.create_foreign_key('harvest_user_fk_person', 'harvest_user', 'person', ['person_uuid'], ['uuid'])
op.add_column('harvest_user_version', sa.Column('person_uuid', sa.String(length=32), autoincrement=False, nullable=True))
def downgrade():
# harvest_user
op.drop_column('harvest_user_version', 'person_uuid')
op.drop_constraint('harvest_user_fk_person', 'harvest_user', type_='foreignkey')
op.drop_column('harvest_user', 'person_uuid')

View file

@ -39,6 +39,7 @@ class HarvestUser(model.Base):
"""
__tablename__ = 'harvest_user'
__table_args__ = (
sa.ForeignKeyConstraint(['person_uuid'], ['person.uuid'], name='harvest_user_fk_person'),
sa.UniqueConstraint('id', name='harvest_user_uq_id'),
)
__versioned__ = {}
@ -90,6 +91,19 @@ class HarvestUser(model.Base):
updated_at = sa.Column(sa.DateTime(), nullable=True)
person_uuid = sa.Column(sa.String(length=32), nullable=True)
person = orm.relationship(
model.Person,
doc="""
Reference to the person associated with this Harvest user.
""",
backref=orm.backref(
'harvest_users',
doc="""
List of all Harvest user accounts for the person.
""")
)
def __str__(self):
return normalize_full_name(self.first_name, self.last_name)