def upgrade():
    """Upgrade database."""
    op.create_table(
        'workflows_workflow',
        sa.Column(
            'uuid',
            UUIDType,
            primary_key=True,
            nullable=False,
            default=uuid.uuid4()
        ),
        sa.Column(
            'name',
            sa.String(255),
            default='Default workflow',
            nullable=False
        ),
        sa.Column(
            'created',
            sa.DateTime,
            default=datetime.now,
            nullable=False
        ),
        sa.Column(
            'modified',
            sa.DateTime,
            default=datetime.now,
            onupdate=datetime.now,
            nullable=False
        ),
        sa.Column('id_user', sa.Integer, default=0, nullable=False),
        sa.Column(
            'extra_data',
            JSONType().with_variant(
                postgresql.JSON(none_as_null=True),
                'postgresql',
            ),
            default=lambda: dict(),
            nullable=False
        ),
        sa.Column(
            'status',
            ChoiceType(WorkflowStatus, impl=sa.Integer()),
            default=WorkflowStatus.NEW,
            nullable=False
        )
    )

    op.create_table(
        'workflows_object',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column(
            'data',
            JSONType().with_variant(
                postgresql.JSON(none_as_null=True),
                'postgresql',
            ),
            default=lambda: dict(),
            nullable=False
        ),
        sa.Column(
            'extra_data',
            JSONType().with_variant(
                postgresql.JSON(none_as_null=True),
                'postgresql',
            ),
            default=lambda: dict(),
            nullable=False
        ),
        sa.Column(
            'id_workflow',
            UUIDType,
            sa.ForeignKey('workflows_workflow.uuid', ondelete='CASCADE'),
            nullable=True,
            index=True
        ),
        sa.Column(
            'status',
            ChoiceType(ObjectStatus, impl=sa.Integer()),
            default=ObjectStatus.INITIAL,
            nullable=False,
            index=True
        ),
        sa.Column(
            'id_parent',
            sa.Integer,
            sa.ForeignKey('workflows_object.id', ondelete='CASCADE'),
            default=None,
            index=True
        ),
        sa.Column('id_user', sa.Integer, default=0, nullable=False),
        sa.Column(
            'created',
            sa.DateTime,
            default=datetime.now,
            nullable=False
        ),
        sa.Column(
            'modified',
            sa.DateTime,
            default=datetime.now,
            onupdate=datetime.now,
            nullable=False
        ),
        sa.Column(
            'data_type',
            sa.String(150),
            default='',
            nullable=True,
            index=True
        ),
        sa.Column('id_user', sa.Integer, default=0, nullable=False),
        sa.Column(
            'callback_pos',
            JSONType().with_variant(
                postgresql.JSON(none_as_null=True),
                'postgresql',
            ),
            default=lambda: list(),
            nullable=True
        )
    )