Add nominal support for mysql db backend

*very* experimental at this point, but seems to work
This commit is contained in:
Lance Edgar 2022-01-08 19:46:53 -06:00
parent 84ed805e22
commit d13f27223c
15 changed files with 68 additions and 38 deletions

View file

@ -148,6 +148,13 @@ class BatchHandler(object):
kwargs.setdefault('rowcount', 0) kwargs.setdefault('rowcount', 0)
kwargs.setdefault('complete', False) kwargs.setdefault('complete', False)
# we used just let the postgres sequence auto-generate the id,
# but now we are trying to support more than just postgres,
# and so we consume a batch id using shared logic which can
# accommodate more than just postgres
if 'id' not in kwargs:
kwargs['id'] = self.consume_batch_id(session)
# try to provide default creator # try to provide default creator
if user and 'created_by' not in kwargs and 'created_by_uuid' not in kwargs: if user and 'created_by' not in kwargs and 'created_by_uuid' not in kwargs:
kwargs['created_by'] = user kwargs['created_by'] = user

View file

@ -31,16 +31,10 @@ def upgrade():
op.execute(CreateSequence(batch_id_seq)) op.execute(CreateSequence(batch_id_seq))
# vendor_catalog # vendor_catalog
op.add_column('vendor_catalog', sa.Column('id', sa.Integer(), batch_id_seq, nullable=True)) op.add_column('vendor_catalog', sa.Column('id', sa.Integer(), nullable=False))
vendor_catalog = sa.sql.table('vendor_catalog', sa.sql.column('id'))
op.execute(vendor_catalog.update().values({'id': batch_id_seq.next_value()}))
op.alter_column('vendor_catalog', 'id', nullable=False)
# vendor_invoice # vendor_invoice
op.add_column('vendor_invoice', sa.Column('id', sa.Integer(), batch_id_seq, nullable=True)) op.add_column('vendor_invoice', sa.Column('id', sa.Integer(), nullable=False))
vendor_invoice = sa.sql.table('vendor_invoice', sa.sql.column('id'))
op.execute(vendor_invoice.update().values({'id': batch_id_seq.next_value()}))
op.alter_column('vendor_invoice', 'id', nullable=False)
def downgrade(): def downgrade():

View file

@ -29,7 +29,8 @@ def upgrade():
sa.Column('user_uuid', sa.String(length=32), nullable=False), sa.Column('user_uuid', sa.String(length=32), nullable=False),
sa.Column('type_code', sa.Integer(), nullable=False), sa.Column('type_code', sa.Integer(), nullable=False),
sa.Column('occurred', sa.DateTime(), nullable=True), sa.Column('occurred', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['user_uuid'], [u'user.uuid'], name=u'user_x_role_fk_user'), sa.ForeignKeyConstraint(['user_uuid'], ['user.uuid'],
name='user_event_fk_user'),
sa.PrimaryKeyConstraint('uuid') sa.PrimaryKeyConstraint('uuid')
) )

View file

@ -27,7 +27,8 @@ def upgrade():
op.add_column('product', sa.Column('deleted', sa.Boolean(), nullable=True)) op.add_column('product', sa.Column('deleted', sa.Boolean(), nullable=True))
product = sa.sql.table('product', sa.sql.column('deleted')) product = sa.sql.table('product', sa.sql.column('deleted'))
op.execute(product.update().values({'deleted': False})) op.execute(product.update().values({'deleted': False}))
op.alter_column('product', 'deleted', nullable=False) op.alter_column('product', 'deleted', nullable=False,
existing_type=sa.Boolean())
op.add_column('product_version', sa.Column('deleted', sa.Boolean(), nullable=True)) op.add_column('product_version', sa.Column('deleted', sa.Boolean(), nullable=True))

View file

@ -27,7 +27,8 @@ def upgrade():
op.add_column('product', sa.Column('special_order', sa.Boolean(), nullable=True)) op.add_column('product', sa.Column('special_order', sa.Boolean(), nullable=True))
product = sa.sql.table('product', sa.sql.column('special_order')) product = sa.sql.table('product', sa.sql.column('special_order'))
op.execute(product.update().values({'special_order': False})) op.execute(product.update().values({'special_order': False}))
op.alter_column('product', 'special_order', nullable=False) op.alter_column('product', 'special_order', nullable=False,
existing_type=sa.Boolean())
op.add_column('product_version', sa.Column('special_order', sa.Boolean(), nullable=True)) op.add_column('product_version', sa.Column('special_order', sa.Boolean(), nullable=True))

View file

@ -32,7 +32,8 @@ def upgrade():
op.execute(product_version.update()\ op.execute(product_version.update()\
.where(product_version.c.unit_of_measure == None)\ .where(product_version.c.unit_of_measure == None)\
.values({'unit_of_measure': enum.UNIT_OF_MEASURE_NONE})) .values({'unit_of_measure': enum.UNIT_OF_MEASURE_NONE}))
op.alter_column('product', 'unit_of_measure', nullable=False) op.alter_column('product', 'unit_of_measure', nullable=False,
existing_type=sa.Boolean())
# product.unit_size # product.unit_size
op.add_column('product', sa.Column('unit_size', sa.Numeric(precision=8, scale=3), nullable=True)) op.add_column('product', sa.Column('unit_size', sa.Numeric(precision=8, scale=3), nullable=True))
@ -42,7 +43,8 @@ def upgrade():
op.add_column('product', sa.Column('weighed', sa.Boolean(), nullable=True)) op.add_column('product', sa.Column('weighed', sa.Boolean(), nullable=True))
product = sa.sql.table('product', sa.sql.column('weighed')) product = sa.sql.table('product', sa.sql.column('weighed'))
op.execute(product.update().values({'weighed': False})) op.execute(product.update().values({'weighed': False}))
op.alter_column('product', 'weighed', nullable=False) op.alter_column('product', 'weighed', nullable=False,
existing_type=sa.Boolean())
op.add_column('product_version', sa.Column('weighed', sa.Boolean(), nullable=True)) op.add_column('product_version', sa.Column('weighed', sa.Boolean(), nullable=True))

View file

@ -27,7 +27,8 @@ def upgrade():
op.add_column('product', sa.Column('discountable', sa.Boolean(), nullable=True)) op.add_column('product', sa.Column('discountable', sa.Boolean(), nullable=True))
product = sa.sql.table('product', sa.sql.column('discountable')) product = sa.sql.table('product', sa.sql.column('discountable'))
op.execute(product.update().values({'discountable': True})) op.execute(product.update().values({'discountable': True}))
op.alter_column('product', 'discountable', nullable=False) op.alter_column('product', 'discountable', nullable=False,
existing_type=sa.Boolean())
op.add_column('product_version', sa.Column('discountable', sa.Boolean(), nullable=True)) op.add_column('product_version', sa.Column('discountable', sa.Boolean(), nullable=True))

View file

@ -27,7 +27,8 @@ def upgrade():
op.add_column('product', sa.Column('organic', sa.Boolean(), nullable=True)) op.add_column('product', sa.Column('organic', sa.Boolean(), nullable=True))
product = sa.sql.table('product', sa.sql.column('organic')) product = sa.sql.table('product', sa.sql.column('organic'))
op.execute(product.update().values({'organic': False})) op.execute(product.update().values({'organic': False}))
op.alter_column('product', 'organic', nullable=False) op.alter_column('product', 'organic', nullable=False,
existing_type=sa.Boolean())
op.add_column('product_version', sa.Column('organic', sa.Boolean(), nullable=True)) op.add_column('product_version', sa.Column('organic', sa.Boolean(), nullable=True))

View file

@ -28,66 +28,82 @@ def upgrade():
op.execute(batch.update()\ op.execute(batch.update()\
.where(batch.c.complete == None)\ .where(batch.c.complete == None)\
.values({'complete': False})) .values({'complete': False}))
op.alter_column('batch_handheld', 'complete', nullable=False) op.alter_column('batch_handheld', 'complete', nullable=False,
existing_type=sa.Boolean())
# batch_importer # batch_importer
batch = sa.sql.table('batch_importer', sa.sql.column('complete')) batch = sa.sql.table('batch_importer', sa.sql.column('complete'))
op.execute(batch.update()\ op.execute(batch.update()\
.where(batch.c.complete == None)\ .where(batch.c.complete == None)\
.values({'complete': False})) .values({'complete': False}))
op.alter_column('batch_importer', 'complete', nullable=False) op.alter_column('batch_importer', 'complete', nullable=False,
existing_type=sa.Boolean())
# batch_inventory # batch_inventory
batch = sa.sql.table('batch_inventory', sa.sql.column('complete')) batch = sa.sql.table('batch_inventory', sa.sql.column('complete'))
op.execute(batch.update()\ op.execute(batch.update()\
.where(batch.c.complete == None)\ .where(batch.c.complete == None)\
.values({'complete': False})) .values({'complete': False}))
op.alter_column('batch_inventory', 'complete', nullable=False) op.alter_column('batch_inventory', 'complete', nullable=False,
existing_type=sa.Boolean())
# batch_pricing # batch_pricing
batch = sa.sql.table('batch_pricing', sa.sql.column('complete')) batch = sa.sql.table('batch_pricing', sa.sql.column('complete'))
op.execute(batch.update()\ op.execute(batch.update()\
.where(batch.c.complete == None)\ .where(batch.c.complete == None)\
.values({'complete': False})) .values({'complete': False}))
op.alter_column('batch_pricing', 'complete', nullable=False) op.alter_column('batch_pricing', 'complete', nullable=False,
existing_type=sa.Boolean())
# label_batch # label_batch
batch = sa.sql.table('label_batch', sa.sql.column('complete')) batch = sa.sql.table('label_batch', sa.sql.column('complete'))
op.execute(batch.update()\ op.execute(batch.update()\
.where(batch.c.complete == None)\ .where(batch.c.complete == None)\
.values({'complete': False})) .values({'complete': False}))
op.alter_column('label_batch', 'complete', nullable=False) op.alter_column('label_batch', 'complete', nullable=False,
existing_type=sa.Boolean())
# purchase_batch # purchase_batch
batch = sa.sql.table('purchase_batch', sa.sql.column('complete')) batch = sa.sql.table('purchase_batch', sa.sql.column('complete'))
op.execute(batch.update()\ op.execute(batch.update()\
.where(batch.c.complete == None)\ .where(batch.c.complete == None)\
.values({'complete': False})) .values({'complete': False}))
op.alter_column('purchase_batch', 'complete', nullable=False) op.alter_column('purchase_batch', 'complete', nullable=False,
existing_type=sa.Boolean())
# vendor_catalog # vendor_catalog
batch = sa.sql.table('vendor_catalog', sa.sql.column('complete')) batch = sa.sql.table('vendor_catalog', sa.sql.column('complete'))
op.execute(batch.update()\ op.execute(batch.update()\
.where(batch.c.complete == None)\ .where(batch.c.complete == None)\
.values({'complete': False})) .values({'complete': False}))
op.alter_column('vendor_catalog', 'complete', nullable=False) op.alter_column('vendor_catalog', 'complete', nullable=False,
existing_type=sa.Boolean())
# vendor_invoice # vendor_invoice
batch = sa.sql.table('vendor_invoice', sa.sql.column('complete')) batch = sa.sql.table('vendor_invoice', sa.sql.column('complete'))
op.execute(batch.update()\ op.execute(batch.update()\
.where(batch.c.complete == None)\ .where(batch.c.complete == None)\
.values({'complete': False})) .values({'complete': False}))
op.alter_column('vendor_invoice', 'complete', nullable=False) op.alter_column('vendor_invoice', 'complete', nullable=False,
existing_type=sa.Boolean())
def downgrade(): def downgrade():
# downgrade is simpler, we just need to allow null again # downgrade is simpler, we just need to allow null again
op.alter_column('vendor_invoice', 'complete', nullable=True) op.alter_column('vendor_invoice', 'complete', nullable=True,
op.alter_column('vendor_catalog', 'complete', nullable=True) existing_type=sa.Boolean())
op.alter_column('purchase_batch', 'complete', nullable=True) op.alter_column('vendor_catalog', 'complete', nullable=True,
op.alter_column('label_batch', 'complete', nullable=True) existing_type=sa.Boolean())
op.alter_column('batch_pricing', 'complete', nullable=True) op.alter_column('purchase_batch', 'complete', nullable=True,
op.alter_column('batch_inventory', 'complete', nullable=True) existing_type=sa.Boolean())
op.alter_column('batch_importer', 'complete', nullable=True) op.alter_column('label_batch', 'complete', nullable=True,
op.alter_column('batch_handheld', 'complete', nullable=True) existing_type=sa.Boolean())
op.alter_column('batch_pricing', 'complete', nullable=True,
existing_type=sa.Boolean())
op.alter_column('batch_inventory', 'complete', nullable=True,
existing_type=sa.Boolean())
op.alter_column('batch_importer', 'complete', nullable=True,
existing_type=sa.Boolean())
op.alter_column('batch_handheld', 'complete', nullable=True,
existing_type=sa.Boolean())

View file

@ -35,7 +35,8 @@ def upgrade():
op.add_column('purchase_batch', sa.Column('mode', sa.Integer(), nullable=True)) op.add_column('purchase_batch', sa.Column('mode', sa.Integer(), nullable=True))
batch = sa.sql.table('purchase_batch', sa.sql.column('mode')) batch = sa.sql.table('purchase_batch', sa.sql.column('mode'))
op.execute(batch.update().values({'mode': enum.PURCHASE_BATCH_MODE_ORDERING})) op.execute(batch.update().values({'mode': enum.PURCHASE_BATCH_MODE_ORDERING}))
op.alter_column('purchase_batch', 'mode', nullable=False) op.alter_column('purchase_batch', 'mode', nullable=False,
existing_type=sa.Integer())
def downgrade(): def downgrade():

View file

@ -27,7 +27,8 @@ def upgrade():
op.add_column('product', sa.Column('discontinued', sa.Boolean(), nullable=True)) op.add_column('product', sa.Column('discontinued', sa.Boolean(), nullable=True))
product = sa.sql.table('product', sa.sql.column('discontinued')) product = sa.sql.table('product', sa.sql.column('discontinued'))
op.execute(product.update().values({'discontinued': False})) op.execute(product.update().values({'discontinued': False}))
op.alter_column('product', 'discontinued', nullable=False) op.alter_column('product', 'discontinued', nullable=False,
existing_type=sa.Boolean())
def downgrade(): def downgrade():

View file

@ -27,7 +27,8 @@ def upgrade():
op.add_column('batch_pricing', sa.Column('shelved', sa.Boolean(), nullable=True)) op.add_column('batch_pricing', sa.Column('shelved', sa.Boolean(), nullable=True))
batch = sa.sql.table('batch_pricing', sa.sql.column('shelved')) batch = sa.sql.table('batch_pricing', sa.sql.column('shelved'))
op.execute(batch.update().values({'shelved': False})) op.execute(batch.update().values({'shelved': False}))
op.alter_column('batch_pricing', 'shelved', nullable=False) op.alter_column('batch_pricing', 'shelved', nullable=False,
existing_type=sa.Boolean())
def downgrade(): def downgrade():

View file

@ -28,7 +28,8 @@ def upgrade():
op.add_column('customer_version', sa.Column('active_in_pos_sticky', sa.Boolean(), autoincrement=False, nullable=True)) op.add_column('customer_version', sa.Column('active_in_pos_sticky', sa.Boolean(), autoincrement=False, nullable=True))
customer = sa.sql.table('customer', sa.sql.column('active_in_pos_sticky')) customer = sa.sql.table('customer', sa.sql.column('active_in_pos_sticky'))
op.execute(customer.update().values({'active_in_pos_sticky': False})) op.execute(customer.update().values({'active_in_pos_sticky': False}))
op.alter_column('customer', 'active_in_pos_sticky', nullable=False) op.alter_column('customer', 'active_in_pos_sticky', nullable=False,
existing_type=sa.Boolean())
def downgrade(): def downgrade():

View file

@ -27,7 +27,8 @@ def upgrade():
op.add_column('vendor_catalog_row', sa.Column('department_name', sa.String(length=30), nullable=True)) op.add_column('vendor_catalog_row', sa.Column('department_name', sa.String(length=30), nullable=True))
op.add_column('vendor_catalog_row', sa.Column('department_number', sa.Integer(), nullable=True)) op.add_column('vendor_catalog_row', sa.Column('department_number', sa.Integer(), nullable=True))
op.add_column('vendor_catalog_row', sa.Column('item_id', sa.String(length=20), nullable=True)) op.add_column('vendor_catalog_row', sa.Column('item_id', sa.String(length=20), nullable=True))
op.alter_column('vendor_catalog_row', 'description', nullable=True) op.alter_column('vendor_catalog_row', 'description', nullable=True,
existing_type=sa.String(length=255))
def downgrade(): def downgrade():

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar # Copyright © 2010-2022 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -321,7 +321,8 @@ class UserEvent(Base):
""" """
__tablename__ = 'user_event' __tablename__ = 'user_event'
__table_args__ = ( __table_args__ = (
sa.ForeignKeyConstraint(['user_uuid'], ['user.uuid'], name='user_x_role_fk_user'), sa.ForeignKeyConstraint(['user_uuid'], ['user.uuid'],
name='user_event_fk_user'),
) )
uuid = uuid_column() uuid = uuid_column()