def upgrade():
    op.rename_table('payment_transactions',
                    'payment_transactions_old',
                    schema='events')
    op.execute(
        _rename_constraint('events', 'payment_transactions_old',
                           'pk_payment_transactions',
                           'pk_payment_transactions_old'))
    op.execute(
        "ALTER SEQUENCE events.payment_transactions_id_seq RENAME TO payment_transactions_old_id_seq"
    )
    op.create_table(
        'payment_transactions',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('registration_id', sa.Integer(), nullable=False, index=True),
        sa.Column('status', PyIntEnum(TransactionStatus), nullable=False),
        sa.Column('amount', sa.Numeric(precision=8, scale=2), nullable=False),
        sa.Column('currency', sa.String(), nullable=False),
        sa.Column('provider', sa.String(), nullable=False),
        sa.Column('timestamp', UTCDateTime, nullable=False),
        sa.Column('data', postgresql.JSON(), nullable=False),
        sa.CheckConstraint('amount > 0', name='positive_amount'),
        sa.ForeignKeyConstraint(['registration_id'],
                                ['event_registration.registrations.id']),
        sa.PrimaryKeyConstraint('id'),
        schema='events')
    op.create_foreign_key(None,
                          'registrations',
                          'payment_transactions', ['transaction_id'], ['id'],
                          source_schema='event_registration',
                          referent_schema='events')
Example #2
0
def upgrade():
    op.execute(CreateSchema('plugin_livesync'))
    op.create_table('agents',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('backend_name', sa.String(), nullable=False),
                    sa.Column('name', sa.String(), nullable=False),
                    sa.Column('initial_data_exported', sa.Boolean(), nullable=False),
                    sa.Column('last_run', UTCDateTime(), nullable=False),
                    sa.Column('settings', postgresql.JSON(), nullable=False),
                    sa.PrimaryKeyConstraint('id', name='agents_pkey'),
                    schema='plugin_livesync')
    op.create_table('queues',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('agent_id', sa.Integer(), nullable=False),
                    sa.Column('timestamp', UTCDateTime(), nullable=False),
                    sa.Column('processed', sa.Boolean(), nullable=False),
                    sa.Column('change', PyIntEnum(ChangeType), nullable=False),
                    sa.Column('type', sa.String(), nullable=False),
                    sa.Column('category_id', sa.String()),
                    sa.Column('event_id', sa.String()),
                    sa.Column('contrib_id', sa.String()),
                    sa.Column('subcontrib_id', sa.String()),
                    sa.ForeignKeyConstraint(['agent_id'], ['plugin_livesync.agents.id'], name='queues_agent_id_fkey'),
                    sa.PrimaryKeyConstraint('id', name='queues_pkey'),
                    sa.Index('ix_plugin_livesync_queues_agent_id', 'agent_id'),
                    schema='plugin_livesync')
    # later migrations expect the old name...
    op.execute(_rename_constraint('plugin_livesync', 'queues', 'ck_queues_valid_enum_change', 'queues_change_check'))
def downgrade():
    op.drop_constraint(op.f('fk_registrations_transaction_id_payment_transactions'), 'registrations',
                       schema='event_registration')
    op.drop_table('payment_transactions', schema='events')
    op.execute("ALTER SEQUENCE events.payment_transactions_old_id_seq RENAME TO payment_transactions_id_seq")
    op.execute(_rename_constraint('events', 'payment_transactions_old',
                                  'pk_payment_transactions_old', 'pk_payment_transactions'))
    op.rename_table('payment_transactions_old', 'payment_transactions', schema='events')
def downgrade():
    op.drop_constraint(
        op.f('fk_registrations_transaction_id_payment_transactions'),
        'registrations',
        schema='event_registration')
    op.drop_table('payment_transactions', schema='events')
    op.execute(
        "ALTER SEQUENCE events.payment_transactions_old_id_seq RENAME TO payment_transactions_id_seq"
    )
    op.execute(
        _rename_constraint('events', 'payment_transactions_old',
                           'pk_payment_transactions_old',
                           'pk_payment_transactions'))
    op.rename_table('payment_transactions_old',
                    'payment_transactions',
                    schema='events')
def upgrade():
    op.rename_table('payment_transactions', 'payment_transactions_old', schema='events')
    op.execute(_rename_constraint('events', 'payment_transactions_old',
                                  'pk_payment_transactions', 'pk_payment_transactions_old'))
    op.execute("ALTER SEQUENCE events.payment_transactions_id_seq RENAME TO payment_transactions_old_id_seq")
    op.create_table(
        'payment_transactions',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('registration_id', sa.Integer(), nullable=False, index=True),
        sa.Column('status', PyIntEnum(TransactionStatus), nullable=False),
        sa.Column('amount', sa.Numeric(precision=8, scale=2), nullable=False),
        sa.Column('currency', sa.String(), nullable=False),
        sa.Column('provider', sa.String(), nullable=False),
        sa.Column('timestamp', UTCDateTime, nullable=False),
        sa.Column('data', postgresql.JSON(), nullable=False),
        sa.CheckConstraint('amount > 0', name='positive_amount'),
        sa.ForeignKeyConstraint(['registration_id'], ['event_registration.registrations.id']),
        sa.PrimaryKeyConstraint('id'),
        schema='events'
    )
    op.create_foreign_key(None,
                          'registrations', 'payment_transactions',
                          ['transaction_id'], ['id'],
                          source_schema='event_registration', referent_schema='events')