def upgrade():
    """Upgrade database."""
    def json_column(name, **kwargs):
        """Return JSON column."""
        return sa.Column(
            name,
            sqlalchemy_utils.types.JSONType().with_variant(
                postgresql.JSON(none_as_null=True), 'postgresql',
            ),
            **kwargs
        )

    op.create_table(
        'webhooks_events',
        sa.Column('created', sa.DateTime(), nullable=False),
        sa.Column('updated', sa.DateTime(), nullable=False),
        sa.Column(
            'id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False),
        sa.Column('receiver_id', sa.String(length=255), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=True),
        json_column('payload', nullable=True),
        json_column('payload_headers', nullable=True),
        json_column('response', nullable=True),
        json_column('response_headers', nullable=True),
        sa.Column('response_code', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['user_id'], [u'accounts_user.id'], ),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(
        op.f('ix_webhooks_events_receiver_id'),
        'webhooks_events',
        ['receiver_id'],
        unique=False
    )
def upgrade ( ) : def json_column ( name , ** kwargs ) : return sa . Column ( name , sqlalchemy_utils . types . JSONType ( ) . with_variant ( postgresql . JSON ( none_as_null = True ) , 'postgresql' , ) , ** kwargs ) op . create_table ( 'webhooks_events' , sa . Column ( 'created' , sa . DateTime ( ) , nullable = False ) , sa . Column ( 'updated' , sa . DateTime ( ) , nullable = False ) , sa . Column ( 'id' , sqlalchemy_utils . types . uuid . UUIDType ( ) , nullable = False ) , sa . Column ( 'receiver_id' , sa . String ( length = 255 ) , nullable = False ) , sa . Column ( 'user_id' , sa . Integer ( ) , nullable = True ) , json_column ( 'payload' , nullable = True ) , json_column ( 'payload_headers' , nullable = True ) , json_column ( 'response' , nullable = True ) , json_column ( 'response_headers' , nullable = True ) , sa . Column ( 'response_code' , sa . Integer ( ) , nullable = True ) , sa . ForeignKeyConstraint ( [ 'user_id' ] , [ u'accounts_user.id' ] , ) , sa . PrimaryKeyConstraint ( 'id' ) ) op . create_index ( op . f ( 'ix_webhooks_events_receiver_id' ) , 'webhooks_events' , [ 'receiver_id' ] , unique = False )
Upgrade database.