def upgrade():
    """Upgrade database model."""
    op.add_column('projects',
                  sa.Column('pool_id', types.UUIDType(), nullable=True))
    op.add_column(
        'projects',
        sa.Column('delivery', types.JSONType(), nullable=True),
    )
    op.create_index(op.f('ix_projects_pool_id'),
                    'projects', ['pool_id'],
                    unique=False)
    op.create_foreign_key(None, 'projects', 'pools', ['pool_id'], ['id'])
    op.add_column(
        'projects_version',
        sa.Column('pool_id',
                  types.UUIDType(),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'projects_version',
        sa.Column('delivery', types.JSONType(), nullable=True),
    )
    op.create_index(op.f('ix_projects_version_pool_id'),
                    'projects_version', ['pool_id'],
                    unique=False)
    data_upgrade()
Esempio n. 2
0
class PaymentAttributes(db.Model):
    """
    Defines list of attributes linked to a Payment resource
    """
    id = db.Column(column_types.UUIDType(binary=False),
                   db.ForeignKey('payment.id'),
                   primary_key=True)

    amount = db.Column(db.DECIMAL, nullable=False)

    beneficiary_party_id = db.Column(db.Integer,
                                     db.ForeignKey('bank_account.id'),
                                     index=True,
                                     unique=False)
    beneficiary_party = db.relationship('BankAccount',
                                        foreign_keys=[beneficiary_party_id])

    charges_information_id = db.Column(db.Integer,
                                       db.ForeignKey('charges_information.id'))
    charges_information = db.relationship('ChargesInformation')

    currency = db.Column(db.String)

    debtor_party_id = db.Column(db.Integer,
                                db.ForeignKey('bank_account.id'),
                                index=True,
                                unique=False)
    debtor_party = db.relationship('BankAccount',
                                   foreign_keys=[debtor_party_id])

    end_to_end_reference = db.Column(db.String)

    fx_id = db.Column(db.Integer,
                      db.ForeignKey('fx.id'),
                      index=True,
                      unique=False)
    fx = db.relationship('FX')

    numeric_reference = db.Column(db.String)
    payment_id = db.Column(db.String)
    payment_purpose = db.Column(db.String)
    payment_scheme = db.Column(db.String)
    payment_type = db.Column(db.String)
    processing_date = db.Column(db.String)
    reference = db.Column(db.String)
    scheme_payment_sub_type = db.Column(db.String)
    scheme_payment_type = db.Column(db.String)

    sponsor_party_id = db.Column(db.Integer,
                                 db.ForeignKey('bank_account.id'),
                                 index=True,
                                 unique=False)
    sponsor_party = db.relationship('BankAccount',
                                    foreign_keys=[sponsor_party_id])
Esempio n. 3
0
class Payment(db.Model, Timestamp):
    """
    Defines Payment Database Model within the ORM
    """

    type = "Payment"
    id = db.Column(column_types.UUIDType(binary=False),
                   default=uuid.uuid4,
                   primary_key=True)  # pylint: disable=invalid-name
    version = 0
    organisation_id = db.Column(column_types.UUIDType(binary=False),
                                index=True,
                                unique=False)
    attributes = db.relationship('PaymentAttributes',
                                 uselist=False,
                                 cascade="save-update, merge, "
                                 "delete, delete-orphan")

    def __repr__(self):
        return ("<{class_name}("
                "id='{self.id}'"
                "version={self.version}"
                "organisation_id='{self.organisation_id}'"
                ")>".format(class_name=self.__class__.__name__, self=self))
def create_tables():
    """Create new tables."""
    op.create_table(
        'items', sa.Column('id', types.UUIDType(), nullable=False),
        sa.Column('can_view', postgresql.ARRAY(sa.String()), nullable=False),
        sa.Column('title', sa.String(), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('slug', sa.String(length=255), nullable=True),
        sa.Column('created_at', AwareDateTime(), nullable=True),
        sa.Column('state', sa.String(length=100), nullable=True),
        sa.Column('state_history',
                  sqlalchemy_utils.types.json.JSONType(),
                  nullable=True),
        sa.Column('path',
                  postgresql.ARRAY(postgresql.UUID(as_uuid=True)),
                  nullable=False),
        sa.Column('type', sa.String(length=50), nullable=True),
        sa.Column('updated_at', AwareDateTime(), nullable=True),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('id'))

    op.create_table(
        'items_version',
        sa.Column('id', types.UUIDType(), autoincrement=False, nullable=False),
        sa.Column('can_view',
                  postgresql.ARRAY(sa.String()),
                  autoincrement=False,
                  nullable=True),
        sa.Column('title', sa.String(), autoincrement=False, nullable=True),
        sa.Column('description', sa.Text(), autoincrement=False,
                  nullable=True),
        sa.Column('slug',
                  sa.String(length=255),
                  autoincrement=False,
                  nullable=True),
        sa.Column('created_at',
                  AwareDateTime(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('state',
                  sa.String(length=100),
                  autoincrement=False,
                  nullable=True),
        sa.Column('path',
                  postgresql.ARRAY(postgresql.UUID(as_uuid=True)),
                  autoincrement=False,
                  nullable=True),
        sa.Column('type',
                  sa.String(length=50),
                  autoincrement=False,
                  nullable=True),
        sa.Column('updated_at',
                  AwareDateTime(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('transaction_id',
                  sa.BigInteger(),
                  autoincrement=False,
                  nullable=False),
        sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
        sa.Column('operation_type', sa.SmallInteger(), nullable=False),
        sa.PrimaryKeyConstraint('id', 'transaction_id'))

    op.create_table(
        'localroles',
        sa.Column('id', types.UUIDType(), autoincrement=False, nullable=False),
        sa.Column('item_type', sa.String(length=255), nullable=False),
        sa.Column('item_id',
                  types.UUIDType(),
                  sa.ForeignKey('items.id'),
                  nullable=False),
        sa.Column('created_at', AwareDateTime(), nullable=True),
        sa.Column('updated_at',
                  AwareDateTime(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('role_name', sa.String(255), nullable=False),
        sa.Column('item_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('principal_id',
                  postgresql.UUID(as_uuid=True),
                  nullable=False), sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('id'))
def create_columns():
    """Create and alter columns and constraints."""
    op.create_unique_constraint(None, 'items', ['id'])
    op.create_unique_constraint(None, 'localroles', ['id'])

    op.drop_constraint('professionals_in_pool_pool_id_fkey',
                       'professionals_in_pool',
                       type_='foreignkey')
    op.drop_constraint('professionals_in_pool_professional_id_fkey',
                       'professionals_in_pool',
                       type_='foreignkey')

    op.alter_column('customercontacts',
                    'title',
                    existing_type=sa.VARCHAR(),
                    nullable=True)
    op.add_column('customeruserprofiles',
                  sa.Column('customer_id', types.UUIDType(), nullable=True))
    op.add_column(
        'assignments_version',
        sa.Column('timezone',
                  types.TimezoneType(),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'customeruserprofiles_version',
        sa.Column('customer_id',
                  types.UUIDType(),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'professionals',
        sa.Column('external_id', sa.String(length=255), nullable=True))
    op.add_column(
        'professionals_version',
        sa.Column('external_id',
                  sa.String(length=255),
                  autoincrement=False,
                  nullable=True))

    # fks to parent table items
    op.create_foreign_key(None, 'assets', 'items', ['id'], ['id'])
    op.create_foreign_key(None, 'assignments', 'items', ['id'], ['id'])
    op.create_foreign_key(None, 'customers', 'items', ['id'], ['id'])
    op.create_foreign_key(None, 'projects', 'items', ['id'], ['id'])
    op.create_foreign_key(None, 'userprofiles', 'items', ['id'], ['id'])
    op.create_foreign_key(None, 'orders', 'items', ['id'], ['id'])
    op.create_foreign_key(None, 'pools', 'items', ['id'], ['id'])

    # new fks
    op.create_foreign_key(None, 'localroles', 'items', ['item_id'], ['id'])
    op.create_foreign_key(None, 'customeruserprofiles', 'customers',
                          ['customer_id'], ['id'])
    op.create_foreign_key(None,
                          'professionals_in_pool',
                          'professionals', ['professional_id'], ['id'],
                          ondelete='CASCADE')
    op.create_foreign_key(None,
                          'professionals_in_pool',
                          'pools', ['pool_id'], ['id'],
                          ondelete='CASCADE')
Esempio n. 6
0
def upgrade():
    """Upgrade database model."""
    op.create_table(
        'billing_infos', sa.Column('id', types.UUIDType(), nullable=False),
        sa.Column('title', sa.String(), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('slug', sa.String(length=255), nullable=True),
        sa.Column('created_at', AwareDateTime(), nullable=True),
        sa.Column('state', sa.String(length=100), nullable=True),
        sa.Column('state_history',
                  sqlalchemy_utils.types.json.JSONType(),
                  nullable=True),
        sa.Column('first_name', sa.String(length=255), nullable=False),
        sa.Column('last_name', sa.String(length=255), nullable=False),
        sa.Column('billing_address',
                  postgresql.JSONB(astext_type=sa.Text()),
                  nullable=True),
        sa.Column('tax_id_type',
                  types.ChoiceType(choices=TaxIdTypes,
                                   impl=sa.String(length=3)),
                  nullable=False),
        sa.Column('tax_id', sa.String(length=50), nullable=True),
        sa.Column('tax_id_name', sa.String(length=50), nullable=True),
        sa.Column('email',
                  sqlalchemy_utils.types.email.EmailType(length=255),
                  nullable=True),
        sa.Column('type', sa.String(length=50), nullable=True),
        sa.Column('updated_at', AwareDateTime(), nullable=True),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('id'))
    op.create_index(op.f('ix_billing_infos_created_at'),
                    'billing_infos', ['created_at'],
                    unique=False)
    op.create_index(op.f('ix_billing_infos_slug'),
                    'billing_infos', ['slug'],
                    unique=False)
    op.create_index(op.f('ix_billing_infos_title'),
                    'billing_infos', ['title'],
                    unique=False)
    op.create_index(op.f('ix_billing_infos_updated_at'),
                    'billing_infos', ['updated_at'],
                    unique=False)
    op.create_table(
        'billing_infos_version',
        sa.Column('id', types.UUIDType(), autoincrement=False, nullable=False),
        sa.Column('title', sa.String(), nullable=True),
        sa.Column('description', sa.Text(), autoincrement=False,
                  nullable=True),
        sa.Column('slug',
                  sa.String(length=255),
                  autoincrement=False,
                  nullable=True),
        sa.Column('created_at',
                  AwareDateTime(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('state',
                  sa.String(length=100),
                  autoincrement=False,
                  nullable=True),
        sa.Column('first_name',
                  sa.String(length=255),
                  autoincrement=False,
                  nullable=True),
        sa.Column('last_name',
                  sa.String(length=255),
                  autoincrement=False,
                  nullable=True),
        sa.Column('billing_address',
                  postgresql.JSONB(astext_type=sa.Text()),
                  autoincrement=False,
                  nullable=True),
        sa.Column('tax_id_type',
                  types.ChoiceType(choices=TaxIdTypes,
                                   impl=sa.String(length=3)),
                  autoincrement=False,
                  nullable=True),
        sa.Column('tax_id',
                  sa.String(length=50),
                  autoincrement=False,
                  nullable=True),
        sa.Column('tax_id_name',
                  sa.String(length=50),
                  autoincrement=False,
                  nullable=True),
        sa.Column('email',
                  sqlalchemy_utils.types.email.EmailType(length=255),
                  autoincrement=False,
                  nullable=True),
        sa.Column('type',
                  sa.String(length=50),
                  autoincrement=False,
                  nullable=True),
        sa.Column('updated_at',
                  AwareDateTime(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('transaction_id',
                  sa.BigInteger(),
                  autoincrement=False,
                  nullable=False),
        sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
        sa.Column('operation_type', sa.SmallInteger(), nullable=False),
        sa.PrimaryKeyConstraint('id', 'transaction_id'))
    op.create_index(op.f('ix_billing_infos_version_created_at'),
                    'billing_infos_version', ['created_at'],
                    unique=False)
    op.create_index(op.f('ix_billing_infos_version_end_transaction_id'),
                    'billing_infos_version', ['end_transaction_id'],
                    unique=False)
    op.create_index(op.f('ix_billing_infos_version_operation_type'),
                    'billing_infos_version', ['operation_type'],
                    unique=False)
    op.create_index(op.f('ix_billing_infos_version_slug'),
                    'billing_infos_version', ['slug'],
                    unique=False)
    op.create_index(op.f('ix_billing_infos_version_title'),
                    'billing_infos_version', ['title'],
                    unique=False)
    op.create_index(op.f('ix_billing_infos_version_transaction_id'),
                    'billing_infos_version', ['transaction_id'],
                    unique=False)
    op.create_index(op.f('ix_billing_infos_version_updated_at'),
                    'billing_infos_version', ['updated_at'],
                    unique=False)
    op.create_table(
        'customer_billing_infos_version',
        sa.Column('id', types.UUIDType(), autoincrement=False, nullable=False),
        sa.Column('customer_id',
                  types.UUIDType(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('tax_id_status',
                  types.ChoiceType(choices=TaxIdStatusCustomers,
                                   impl=sa.String(length=3)),
                  autoincrement=False,
                  nullable=True),
        sa.Column('transaction_id',
                  sa.BigInteger(),
                  autoincrement=False,
                  nullable=False),
        sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
        sa.Column('operation_type', sa.SmallInteger(), nullable=False),
        sa.PrimaryKeyConstraint('id', 'transaction_id'))
    op.create_index(op.f('ix_customer_billing_infos_version_customer_id'),
                    'customer_billing_infos_version', ['customer_id'],
                    unique=False)
    op.create_index(
        op.f('ix_customer_billing_infos_version_end_transaction_id'),
        'customer_billing_infos_version', ['end_transaction_id'],
        unique=False)
    op.create_index(op.f('ix_customer_billing_infos_version_id'),
                    'customer_billing_infos_version', ['id'],
                    unique=False)
    op.create_index(op.f('ix_customer_billing_infos_version_operation_type'),
                    'customer_billing_infos_version', ['operation_type'],
                    unique=False)
    op.create_index(op.f('ix_customer_billing_infos_version_transaction_id'),
                    'customer_billing_infos_version', ['transaction_id'],
                    unique=False)
    op.create_table(
        'professional_billing_infos_version',
        sa.Column('id', types.UUIDType(), autoincrement=False, nullable=False),
        sa.Column('professional_id',
                  types.UUIDType(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('tax_id_status',
                  types.ChoiceType(choices=TaxIdStatusProfessionals,
                                   impl=sa.String(length=3)),
                  autoincrement=False,
                  nullable=True),
        sa.Column('payment_info',
                  postgresql.JSONB(astext_type=sa.Text()),
                  autoincrement=False,
                  nullable=True),
        sa.Column('transaction_id',
                  sa.BigInteger(),
                  autoincrement=False,
                  nullable=False),
        sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
        sa.Column('operation_type', sa.SmallInteger(), nullable=False),
        sa.PrimaryKeyConstraint('id', 'transaction_id'))
    op.create_index(
        op.f('ix_professional_billing_infos_version_end_transaction_id'),
        'professional_billing_infos_version', ['end_transaction_id'],
        unique=False)
    op.create_index(op.f('ix_professional_billing_infos_version_id'),
                    'professional_billing_infos_version', ['id'],
                    unique=False)
    op.create_index(
        op.f('ix_professional_billing_infos_version_operation_type'),
        'professional_billing_infos_version', ['operation_type'],
        unique=False)
    op.create_index(
        op.f('ix_professional_billing_infos_version_professional_id'),
        'professional_billing_infos_version', ['professional_id'],
        unique=False)
    op.create_index(
        op.f('ix_professional_billing_infos_version_transaction_id'),
        'professional_billing_infos_version', ['transaction_id'],
        unique=False)
    op.create_table(
        'customer_billing_infos',
        sa.Column('id', types.UUIDType(), nullable=False),
        sa.Column('customer_id', types.UUIDType(), nullable=True),
        sa.Column('tax_id_status',
                  types.ChoiceType(choices=TaxIdStatusCustomers,
                                   impl=sa.String(length=3)),
                  nullable=True),
        sa.ForeignKeyConstraint(
            ['customer_id'],
            ['customers.id'],
        ), sa.ForeignKeyConstraint(
            ['id'],
            ['billing_infos.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_customer_billing_infos_customer_id'),
                    'customer_billing_infos', ['customer_id'],
                    unique=True)
    op.create_index(op.f('ix_customer_billing_infos_id'),
                    'customer_billing_infos', ['id'],
                    unique=True)
    op.create_table(
        'professional_billing_infos',
        sa.Column('id', types.UUIDType(), nullable=False),
        sa.Column('professional_id', types.UUIDType(), nullable=True),
        sa.Column('tax_id_status',
                  types.ChoiceType(choices=TaxIdStatusProfessionals,
                                   impl=sa.String(length=3)),
                  nullable=True),
        sa.Column('payment_info',
                  postgresql.JSONB(astext_type=sa.Text()),
                  nullable=True),
        sa.ForeignKeyConstraint(
            ['id'],
            ['billing_infos.id'],
        ), sa.ForeignKeyConstraint(
            ['professional_id'],
            ['professionals.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_professional_billing_infos_id'),
                    'professional_billing_infos', ['id'],
                    unique=True)
    op.create_index(op.f('ix_professional_billing_infos_professional_id'),
                    'professional_billing_infos', ['professional_id'],
                    unique=True)