Merge pull request #280 from eReuse/bugfix/279-alembic
fix enums in migration process
This commit is contained in:
commit
1bd0d6cc30
|
@ -5,14 +5,11 @@ Revises: eca457d8b2a4
|
|||
Create Date: 2021-03-15 17:40:34.410408
|
||||
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
import citext
|
||||
import teal
|
||||
from alembic import op
|
||||
from alembic import context
|
||||
import sqlalchemy as sa
|
||||
from alembic import context, op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '51439cf24be8'
|
||||
down_revision = '21afd375a654'
|
||||
|
@ -36,59 +33,197 @@ def upgrade_data():
|
|||
|
||||
|
||||
def upgrade():
|
||||
## Trade
|
||||
currency = sa.Enum('AFN', 'ARS', 'AWG', 'AUD', 'AZN', 'BSD', 'BBD', 'BDT', 'BYR', 'BZD', 'BMD',
|
||||
'BOB', 'BAM', 'BWP', 'BGN', 'BRL', 'BND', 'KHR', 'CAD', 'KYD', 'CLP', 'CNY',
|
||||
'COP', 'CRC', 'HRK', 'CUP', 'CZK', 'DKK', 'DOP', 'XCD', 'EGP', 'SVC', 'EEK',
|
||||
'EUR', 'FKP', 'FJD', 'GHC', 'GIP', 'GTQ', 'GGP', 'GYD', 'HNL', 'HKD', 'HUF',
|
||||
'ISK', 'INR', 'IDR', 'IRR', 'IMP', 'ILS', 'JMD', 'JPY', 'JEP', 'KZT', 'KPW',
|
||||
'KRW', 'KGS', 'LAK', 'LVL', 'LBP', 'LRD', 'LTL', 'MKD', 'MYR', 'MUR', 'MXN',
|
||||
'MNT', 'MZN', 'NAD', 'NPR', 'ANG', 'NZD', 'NIO', 'NGN', 'NOK', 'OMR', 'PKR',
|
||||
'PAB', 'PYG', 'PEN', 'PHP', 'PLN', 'QAR', 'RON', 'RUB', 'SHP', 'SAR', 'RSD',
|
||||
'SCR', 'SGD', 'SBD', 'SOS', 'ZAR', 'LKR', 'SEK', 'CHF', 'SRD', 'SYP', 'TWD',
|
||||
'THB', 'TTD', 'TRY', 'TRL', 'TVD', 'UAH', 'GBP', 'USD', 'UYU', 'UZS', 'VEF', name='currency', create_type=False, checkfirst=True, schema=f'{get_inv()}')
|
||||
|
||||
# Trade
|
||||
currency = sa.Enum(
|
||||
'AFN',
|
||||
'ARS',
|
||||
'AWG',
|
||||
'AUD',
|
||||
'AZN',
|
||||
'BSD',
|
||||
'BBD',
|
||||
'BDT',
|
||||
'BYR',
|
||||
'BZD',
|
||||
'BMD',
|
||||
'BOB',
|
||||
'BAM',
|
||||
'BWP',
|
||||
'BGN',
|
||||
'BRL',
|
||||
'BND',
|
||||
'KHR',
|
||||
'CAD',
|
||||
'KYD',
|
||||
'CLP',
|
||||
'CNY',
|
||||
'COP',
|
||||
'CRC',
|
||||
'HRK',
|
||||
'CUP',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'DOP',
|
||||
'XCD',
|
||||
'EGP',
|
||||
'SVC',
|
||||
'EEK',
|
||||
'EUR',
|
||||
'FKP',
|
||||
'FJD',
|
||||
'GHC',
|
||||
'GIP',
|
||||
'GTQ',
|
||||
'GGP',
|
||||
'GYD',
|
||||
'HNL',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ISK',
|
||||
'INR',
|
||||
'IDR',
|
||||
'IRR',
|
||||
'IMP',
|
||||
'ILS',
|
||||
'JMD',
|
||||
'JPY',
|
||||
'JEP',
|
||||
'KZT',
|
||||
'KPW',
|
||||
'KRW',
|
||||
'KGS',
|
||||
'LAK',
|
||||
'LVL',
|
||||
'LBP',
|
||||
'LRD',
|
||||
'LTL',
|
||||
'MKD',
|
||||
'MYR',
|
||||
'MUR',
|
||||
'MXN',
|
||||
'MNT',
|
||||
'MZN',
|
||||
'NAD',
|
||||
'NPR',
|
||||
'ANG',
|
||||
'NZD',
|
||||
'NIO',
|
||||
'NGN',
|
||||
'NOK',
|
||||
'OMR',
|
||||
'PKR',
|
||||
'PAB',
|
||||
'PYG',
|
||||
'PEN',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'QAR',
|
||||
'RON',
|
||||
'RUB',
|
||||
'SHP',
|
||||
'SAR',
|
||||
'RSD',
|
||||
'SCR',
|
||||
'SGD',
|
||||
'SBD',
|
||||
'SOS',
|
||||
'ZAR',
|
||||
'LKR',
|
||||
'SEK',
|
||||
'CHF',
|
||||
'SRD',
|
||||
'SYP',
|
||||
'TWD',
|
||||
'THB',
|
||||
'TTD',
|
||||
'TRY',
|
||||
'TRL',
|
||||
'TVD',
|
||||
'UAH',
|
||||
'GBP',
|
||||
'USD',
|
||||
'UYU',
|
||||
'UZS',
|
||||
'VEF',
|
||||
name='currency',
|
||||
create_type=False,
|
||||
checkfirst=True,
|
||||
)
|
||||
|
||||
op.drop_table('trade', schema=f'{get_inv()}')
|
||||
op.create_table('trade',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('price', sa.Float(decimal_return_scale=4), nullable=True),
|
||||
sa.Column('lot_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True),
|
||||
sa.Column('user_from_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('user_to_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('document_id', citext.CIText(), nullable=True),
|
||||
sa.Column('confirm', sa.Boolean(), nullable=True),
|
||||
sa.Column('code', citext.CIText(), default='', nullable=True,
|
||||
comment = "This code is used for traceability"),
|
||||
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
||||
sa.ForeignKeyConstraint(['user_from_id'], ['common.user.id'], ),
|
||||
sa.ForeignKeyConstraint(['user_to_id'], ['common.user.id'], ),
|
||||
sa.ForeignKeyConstraint(['lot_id'], [f'{get_inv()}.lot.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
schema=f'{get_inv()}'
|
||||
)
|
||||
op.create_table(
|
||||
'trade',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('price', sa.Float(decimal_return_scale=4), nullable=True),
|
||||
sa.Column('lot_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True),
|
||||
sa.Column('user_from_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('user_to_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('document_id', citext.CIText(), nullable=True),
|
||||
sa.Column('confirm', sa.Boolean(), nullable=True),
|
||||
sa.Column(
|
||||
'code',
|
||||
citext.CIText(),
|
||||
default='',
|
||||
nullable=True,
|
||||
comment="This code is used for traceability",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['id'],
|
||||
[f'{get_inv()}.action.id'],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['user_from_id'],
|
||||
['common.user.id'],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['user_to_id'],
|
||||
['common.user.id'],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['lot_id'],
|
||||
[f'{get_inv()}.lot.id'],
|
||||
),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
schema=f'{get_inv()}',
|
||||
)
|
||||
|
||||
op.add_column("trade", sa.Column("currency", currency, nullable=False), schema=f'{get_inv()}')
|
||||
op.add_column(
|
||||
"trade", sa.Column("currency", currency, nullable=False), schema=f'{get_inv()}'
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
'confirm',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('action_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
['id'],
|
||||
[f'{get_inv()}.action.id'],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['action_id'],
|
||||
[f'{get_inv()}.action.id'],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['user_id'],
|
||||
['common.user.id'],
|
||||
),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
schema=f'{get_inv()}',
|
||||
)
|
||||
|
||||
op.create_table('confirm',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('action_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
|
||||
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
||||
sa.ForeignKeyConstraint(['action_id'], [f'{get_inv()}.action.id'], ),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['common.user.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
schema=f'{get_inv()}'
|
||||
)
|
||||
|
||||
## User
|
||||
op.add_column('user', sa.Column('active', sa.Boolean(), default=True, nullable=True),
|
||||
schema='common')
|
||||
op.add_column('user', sa.Column('phantom', sa.Boolean(), default=False, nullable=True),
|
||||
schema='common')
|
||||
# User
|
||||
op.add_column(
|
||||
'user',
|
||||
sa.Column('active', sa.Boolean(), default=True, nullable=True),
|
||||
schema='common',
|
||||
)
|
||||
op.add_column(
|
||||
'user',
|
||||
sa.Column('phantom', sa.Boolean(), default=False, nullable=True),
|
||||
schema='common',
|
||||
)
|
||||
|
||||
upgrade_data()
|
||||
|
||||
|
@ -99,28 +234,57 @@ def upgrade():
|
|||
def downgrade():
|
||||
op.drop_table('confirm', schema=f'{get_inv()}')
|
||||
op.drop_table('trade', schema=f'{get_inv()}')
|
||||
op.create_table('trade',
|
||||
sa.Column('shipping_date', sa.TIMESTAMP(timezone=True), nullable=True,
|
||||
comment='When are the devices going to be ready \n \
|
||||
for shipping?\n '),
|
||||
sa.Column('invoice_number', citext.CIText(), nullable=True,
|
||||
comment='The id of the invoice so they can be linked.'),
|
||||
sa.Column('price_id', postgresql.UUID(as_uuid=True), nullable=True,
|
||||
comment='The price set for this trade. \n \
|
||||
op.create_table(
|
||||
'trade',
|
||||
sa.Column(
|
||||
'shipping_date',
|
||||
sa.TIMESTAMP(timezone=True),
|
||||
nullable=True,
|
||||
comment='When are the devices going to be ready \n \
|
||||
for shipping?\n ',
|
||||
),
|
||||
sa.Column(
|
||||
'invoice_number',
|
||||
citext.CIText(),
|
||||
nullable=True,
|
||||
comment='The id of the invoice so they can be linked.',
|
||||
),
|
||||
sa.Column(
|
||||
'price_id',
|
||||
postgresql.UUID(as_uuid=True),
|
||||
nullable=True,
|
||||
comment='The price set for this trade. \n \
|
||||
If no price is set it is supposed that the trade was\n \
|
||||
not payed, usual in donations.\n '),
|
||||
sa.Column('to_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('confirms_id', postgresql.UUID(as_uuid=True), nullable=True,
|
||||
comment='An organize action that this association confirms. \
|
||||
not payed, usual in donations.\n ',
|
||||
),
|
||||
sa.Column('to_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column(
|
||||
'confirms_id',
|
||||
postgresql.UUID(as_uuid=True),
|
||||
nullable=True,
|
||||
comment='An organize action that this association confirms. \
|
||||
\n \n For example, a ``Sell`` or ``Rent``\n \
|
||||
can confirm a ``Reserve`` action.\n '),
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.ForeignKeyConstraint(['confirms_id'], [f'{get_inv()}.organize.id'], ),
|
||||
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
||||
sa.ForeignKeyConstraint(['price_id'], [f'{get_inv()}.price.id'], ),
|
||||
sa.ForeignKeyConstraint(['to_id'], [f'{get_inv()}.agent.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
schema=f'{get_inv()}'
|
||||
)
|
||||
can confirm a ``Reserve`` action.\n ',
|
||||
),
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
['confirms_id'],
|
||||
[f'{get_inv()}.organize.id'],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['id'],
|
||||
[f'{get_inv()}.action.id'],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['price_id'],
|
||||
[f'{get_inv()}.price.id'],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['to_id'],
|
||||
[f'{get_inv()}.agent.id'],
|
||||
),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
schema=f'{get_inv()}',
|
||||
)
|
||||
op.drop_column('user', 'active', schema='common')
|
||||
op.drop_column('user', 'phantom', schema='common')
|
||||
|
|
|
@ -5,12 +5,10 @@ Revises: 3eb50297c365
|
|||
Create Date: 2020-12-29 20:19:46.981207
|
||||
|
||||
"""
|
||||
from alembic import context
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
import teal
|
||||
|
||||
from alembic import context, op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'b4bd1538bad5'
|
||||
|
@ -25,33 +23,71 @@ def get_inv():
|
|||
raise ValueError("Inventory value is not specified")
|
||||
return INV
|
||||
|
||||
|
||||
def upgrade():
|
||||
# op.execute("COMMIT")
|
||||
op.execute("ALTER TYPE snapshotsoftware ADD VALUE 'WorkbenchDesktop'")
|
||||
SOFTWARE = sa.Enum(
|
||||
'Workbench',
|
||||
'WorkbenchAndroid',
|
||||
'AndroidApp',
|
||||
'Web',
|
||||
'DesktopApp',
|
||||
'WorkbenchDesktop',
|
||||
name='snapshotsoftware',
|
||||
create_type=False,
|
||||
checkfirst=True,
|
||||
)
|
||||
|
||||
# Live action
|
||||
op.drop_table('live', schema=f'{get_inv()}')
|
||||
op.create_table('live',
|
||||
op.create_table(
|
||||
'live',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('serial_number', sa.Unicode(), nullable=True,
|
||||
comment='The serial number of the Hard Disk in lower case.'),
|
||||
sa.Column(
|
||||
'serial_number',
|
||||
sa.Unicode(),
|
||||
nullable=True,
|
||||
comment='The serial number of the Hard Disk in lower case.',
|
||||
),
|
||||
sa.Column('usage_time_hdd', sa.Interval(), nullable=True),
|
||||
sa.Column('snapshot_uuid', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('software_version', teal.db.StrictVersionType(length=32), nullable=False),
|
||||
sa.Column('licence_version', teal.db.StrictVersionType(length=32), nullable=False),
|
||||
sa.Column('software', sa.Enum('Workbench', 'WorkbenchAndroid', 'AndroidApp', 'Web',
|
||||
'DesktopApp', 'WorkbenchDesktop', name='snapshotsoftware'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
||||
sa.Column(
|
||||
'software_version', teal.db.StrictVersionType(length=32), nullable=False
|
||||
),
|
||||
sa.Column(
|
||||
'licence_version', teal.db.StrictVersionType(length=32), nullable=False
|
||||
),
|
||||
sa.Column('software', SOFTWARE, nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
['id'],
|
||||
[f'{get_inv()}.action.id'],
|
||||
),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
schema=f'{get_inv()}'
|
||||
schema=f'{get_inv()}',
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('live', schema=f'{get_inv()}')
|
||||
op.create_table('live',
|
||||
op.create_table(
|
||||
'live',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('serial_number', sa.Unicode(), nullable=True,
|
||||
comment='The serial number of the Hard Disk in lower case.'),
|
||||
sa.Column(
|
||||
'serial_number',
|
||||
sa.Unicode(),
|
||||
nullable=True,
|
||||
comment='The serial number of the Hard Disk in lower case.',
|
||||
),
|
||||
sa.Column('usage_time_hdd', sa.Interval(), nullable=True),
|
||||
sa.Column('snapshot_uuid', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
||||
sa.ForeignKeyConstraint(
|
||||
['id'],
|
||||
[f'{get_inv()}.action.id'],
|
||||
),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
schema=f'{get_inv()}'
|
||||
schema=f'{get_inv()}',
|
||||
)
|
||||
op.execute(
|
||||
"select e.enumlabel FROM pg_enum e JOIN pg_type t ON e.enumtypid = t.oid WHERE t.typname = 'snapshotsoftware'"
|
||||
)
|
||||
|
|
Reference in a new issue