fixing migrations

This commit is contained in:
Cayo Puigdefabregas 2021-04-20 19:12:07 +02:00
parent c6f908041b
commit 1b9aaf538a
1 changed files with 27 additions and 7 deletions

View File

@ -14,7 +14,7 @@ import citext
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '51439cf24be8' revision = '51439cf24be8'
down_revision = '6a2a939d5668' down_revision = '8cb91ad1cc40'
branch_labels = None branch_labels = None
depends_on = None depends_on = None
@ -34,6 +34,25 @@ def upgrade_data():
con.execute(sql) con.execute(sql)
op.create_table('trade',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
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('price', sa.Float(decimal_return_scale=2), nullable=True),
sa.Column('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', 'VND', 'YER', 'ZWD', name='currency'), nullable=False, comment='The currency of this price as for ISO 4217.'),
sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True),
sa.Column('document_id', citext.CIText(), nullable=True, comment='The id of one document like invoice so they can be linked.'),
sa.Column('confirm', sa.Boolean(), nullable=False, comment='If you need confirmation of the user, you need actevate this field'),
sa.Column('code', citext.CIText(), nullable=True, comment='If the user not exist, you need a code to be able to do the traceability'),
sa.Column('lot_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.ForeignKeyConstraint(['lot_id'], ['lot.id'], name='lot_trade', use_alter=True),
sa.ForeignKeyConstraint(['user_from_id'], ['common.user.id'], ),
sa.ForeignKeyConstraint(['user_to_id'], ['common.user.id'], ),
sa.PrimaryKeyConstraint('id')
)
def upgrade(): def upgrade():
## Trade ## Trade
currency = sa.Enum('AFN', 'ARS', 'AWG', 'AUD', 'AZN', 'BSD', 'BBD', 'BDT', 'BYR', 'BZD', 'BMD', currency = sa.Enum('AFN', 'ARS', 'AWG', 'AUD', 'AZN', 'BSD', 'BBD', 'BDT', 'BYR', 'BZD', 'BMD',
@ -48,7 +67,7 @@ def upgrade():
'THB', 'TTD', 'TRY', 'TRL', 'TVD', 'UAH', 'GBP', 'USD', 'UYU', 'UZS', 'VEF', name='currency', create_type=False, checkfirst=True, schema=f'{get_inv()}') 'THB', 'TTD', 'TRY', 'TRL', 'TVD', 'UAH', 'GBP', 'USD', 'UYU', 'UZS', 'VEF', name='currency', create_type=False, checkfirst=True, schema=f'{get_inv()}')
op.drop_table('trade', schema=f'{get_inv()}') op.drop_table('trade', schema=f'{get_inv()}')
op.create_table('Trade', op.create_table('trade',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('price', sa.Float(decimal_return_scale=4), nullable=True), sa.Column('price', sa.Float(decimal_return_scale=4), nullable=True),
sa.Column('lot_id', postgresql.UUID(as_uuid=True), nullable=True), sa.Column('lot_id', postgresql.UUID(as_uuid=True), nullable=True),
@ -69,14 +88,16 @@ def upgrade():
op.create_table('confirm', op.create_table('confirm',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False), sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('trade_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ), sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
sa.ForeignKeyConstraint(['trade_id'], [f'{get_inv()}.trade.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['common.user.id'], ), sa.ForeignKeyConstraint(['user_id'], ['common.user.id'], ),
sa.PrimaryKeyConstraint('id'), sa.PrimaryKeyConstraint('id'),
schema=f'{get_inv()}' schema=f'{get_inv()}'
) )
op.create_table('tradenote', op.create_table('trade_note',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('trade_id', postgresql.UUID(as_uuid=True), nullable=False), sa.Column('trade_id', postgresql.UUID(as_uuid=True), nullable=False),
@ -86,8 +107,7 @@ def upgrade():
schema=f'{get_inv()}' schema=f'{get_inv()}'
) )
# ## User
## User
op.add_column('user', sa.Column('active', sa.Boolean(), default=True, nullable=True), op.add_column('user', sa.Column('active', sa.Boolean(), default=True, nullable=True),
schema='common') schema='common')
op.add_column('user', sa.Column('phantom', sa.Boolean(), default=False, nullable=True), op.add_column('user', sa.Column('phantom', sa.Boolean(), default=False, nullable=True),
@ -100,9 +120,9 @@ def upgrade():
def downgrade(): def downgrade():
op.drop_table('trade', schema=f'{get_inv()}')
op.drop_table('confirm', schema=f'{get_inv()}') op.drop_table('confirm', schema=f'{get_inv()}')
op.drop_table('tradenote', schema=f'{get_inv()}') op.drop_table('trade_note', schema=f'{get_inv()}')
op.drop_table('trade', schema=f'{get_inv()}')
op.create_table('trade', op.create_table('trade',
sa.Column('shipping_date', sa.TIMESTAMP(timezone=True), nullable=True, sa.Column('shipping_date', sa.TIMESTAMP(timezone=True), nullable=True,
comment='When are the devices going to be ready \n \ comment='When are the devices going to be ready \n \