<commit_before># -*- coding: utf-8 -*-
#
# Copyright 2013 - Mirantis, Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

import sqlalchemy as sa
import uuid

from mistral.db.sqlalchemy import model_base as mb
from mistral.db.sqlalchemy import types as st

## Helpers


def _generate_unicode_uuid():
    return unicode(str(uuid.uuid4()))


def _id_column():
    return sa.Column(sa.String(36),
                     primary_key=True,
                     default=_generate_unicode_uuid)


class Trigger(mb.MistralBase):
    """Contains all info about trigger."""

    __tablename__ = 'triggers'

    __table_args__ = (
        sa.UniqueConstraint('name'),
    )

    id = _id_column()
    name = sa.Column(sa.String(80), nullable=False)
    pattern = sa.Column(sa.String(20), nullable=False)
    next_execution_time = sa.Column(sa.DateTime, nullable=False)
    workbook_name = sa.Column(sa.String(80), nullable=False)


class WorkflowExecution(mb.MistralBase):
    """Contains info about particular workflow execution."""

    __tablename__ = 'workflow_executions'

    id = _id_column()
    workbook_name = sa.Column(sa.String(80))
    task = sa.Column(sa.String(80))
    state = sa.Column(sa.String(20))
    context = sa.Column(st.JsonDictType())


class Workbook(mb.MistralBase):
    """Contains info about workbook (including definition in Mistral DSL)."""

    __tablename__ = 'workbooks'

    __table_args__ = (
        sa.UniqueConstraint('name'),
    )

    id = _id_column()
    name = sa.Column(sa.String(80), primary_key=True)
    definition = sa.Column(sa.String(), nullable=True)
    description = sa.Column(sa.String())
    tags = sa.Column(st.JsonListType())
    scope = sa.Column(sa.String())
    project_id = sa.Column(sa.String())
    trust_id = sa.Column(sa.String())


class Task(mb.MistralBase):
    """Contains info about particular task."""

    __tablename__ = 'tasks'

    id = _id_column()
    name = sa.Column(sa.String(80))
    requires = sa.Column(st.JsonDictType())
    workbook_name = sa.Column(sa.String(80))
    execution_id = sa.Column(sa.String(36))
    description = sa.Column(sa.String())
    task_spec = sa.Column(st.JsonDictType())
    action_spec = sa.Column(st.JsonDictType())
    state = sa.Column(sa.String(20))
    tags = sa.Column(st.JsonListType())

    # Data Flow properties.
    in_context = sa.Column(st.JsonDictType())
    parameters = sa.Column(st.JsonDictType())
    output = sa.Column(st.JsonDictType())

    # Runtime context like iteration_no of a repeater.
    # Effectively internal engine properties which will be used to determine
    # execution of a task.
    task_runtime_context = sa.Column(st.JsonDictType())
<commit_msg>Fix work on MySQL backend<commit_after># -*- coding: utf-8 -*-
#
# Copyright 2013 - Mirantis, Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

import sqlalchemy as sa
import uuid

from mistral.db.sqlalchemy import model_base as mb
from mistral.db.sqlalchemy import types as st

## Helpers


def _generate_unicode_uuid():
    return unicode(str(uuid.uuid4()))


def _id_column():
    return sa.Column(sa.String(36),
                     primary_key=True,
                     default=_generate_unicode_uuid)


class Trigger(mb.MistralBase):
    """Contains all info about trigger."""

    __tablename__ = 'triggers'

    __table_args__ = (
        sa.UniqueConstraint('name'),
    )

    id = _id_column()
    name = sa.Column(sa.String(80), nullable=False)
    pattern = sa.Column(sa.String(20), nullable=False)
    next_execution_time = sa.Column(sa.DateTime, nullable=False)
    workbook_name = sa.Column(sa.String(80), nullable=False)


class WorkflowExecution(mb.MistralBase):
    """Contains info about particular workflow execution."""

    __tablename__ = 'workflow_executions'

    id = _id_column()
    workbook_name = sa.Column(sa.String(80))
    task = sa.Column(sa.String(80))
    state = sa.Column(sa.String(20))
    context = sa.Column(st.JsonDictType())


class Workbook(mb.MistralBase):
    """Contains info about workbook (including definition in Mistral DSL)."""

    __tablename__ = 'workbooks'

    __table_args__ = (
        sa.UniqueConstraint('name'),
    )

    id = _id_column()
    name = sa.Column(sa.String(80), primary_key=True)
    definition = sa.Column(sa.Text(), nullable=True)
    description = sa.Column(sa.String(200))
    tags = sa.Column(st.JsonListType())
    scope = sa.Column(sa.String(80))
    project_id = sa.Column(sa.String(80))
    trust_id = sa.Column(sa.String(80))


class Task(mb.MistralBase):
    """Contains info about particular task."""

    __tablename__ = 'tasks'

    id = _id_column()
    name = sa.Column(sa.String(80))
    requires = sa.Column(st.JsonDictType())
    workbook_name = sa.Column(sa.String(80))
    execution_id = sa.Column(sa.String(36))
    description = sa.Column(sa.String(200))
    task_spec = sa.Column(st.JsonDictType())
    action_spec = sa.Column(st.JsonDictType())
    state = sa.Column(sa.String(20))
    tags = sa.Column(st.JsonListType())

    # Data Flow properties.
    in_context = sa.Column(st.JsonDictType())
    parameters = sa.Column(st.JsonDictType())
    output = sa.Column(st.JsonDictType())

    # Runtime context like iteration_no of a repeater.
    # Effectively internal engine properties which will be used to determine
    # execution of a task.
    task_runtime_context = sa.Column(st.JsonDictType())

{'fraction_non_alphanumeric': 0.11883338504498914, 'fraction_numerical': 0.012410797393732548, 'mean_word_length': 3.4127310061601643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1340618', 'n_tokens_mistral': 2081, 'n_tokens_neox': 1988, 'n_words': 510}