feat: add app db schema extension, for CoreUser

need a way to map Wutta User to CORE Employee for auth purposes
This commit is contained in:
Lance Edgar 2025-01-25 17:20:55 -06:00
parent 73192a162d
commit 4ee5aa5372
8 changed files with 187 additions and 2 deletions

View file

View file

@ -0,0 +1,37 @@
"""initial user extension
Revision ID: 0f94089f1af1
Revises:
Create Date: 2025-01-24 21:13:14.359200
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import wuttjamaican.db.util
# revision identifiers, used by Alembic.
revision: str = '0f94089f1af1'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = ('wutta_corepos',)
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# corepos_user
op.create_table('corepos_user',
sa.Column('uuid', wuttjamaican.db.util.UUID(), nullable=False),
sa.Column('corepos_employee_number', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['uuid'], ['user.uuid'], name=op.f('fk_corepos_user_uuid_user')),
sa.PrimaryKeyConstraint('uuid', name=op.f('pk_corepos_user')),
sa.UniqueConstraint('corepos_employee_number', name=op.f('uq_corepos_user_corepos_employee_number'))
)
def downgrade() -> None:
# corepos_user
op.drop_table('corepos_user')

View file

@ -0,0 +1,67 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Wutta-COREPOS -- Wutta Framework integration for CORE-POS
# Copyright © 2025 Lance Edgar
#
# This file is part of Wutta Framework.
#
# Wutta Framework is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# Wutta Framework is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Data models for CORE-POS integration
"""
import sqlalchemy as sa
from sqlalchemy import orm
from wuttjamaican.db import model
class CoreUser(model.Base):
"""
CORE-POS extension for
:class:`~wuttjamaican:wuttjamaican.db.model.auth.User`.
"""
__tablename__ = 'corepos_user'
uuid = model.uuid_column(sa.ForeignKey('user.uuid'), default=None)
user = orm.relationship(
model.User,
cascade_backrefs=False,
doc="""
Reference to the
:class:`~wuttjamaican:wuttjamaican.db.model.auth.User` which
this record extends.
""",
backref=orm.backref(
'_corepos',
uselist=False,
cascade='all, delete-orphan',
cascade_backrefs=False,
doc="""
Reference to the CORE-POS extension record for the user.
""")
)
corepos_employee_number = sa.Column(sa.Integer(), nullable=False, unique=True, doc="""
``employees.emp_no`` value for the user within CORE-POS.
""")
def __str__(self):
return str(self.user)
CoreUser.make_proxy(model.User, '_corepos', 'corepos_employee_number')