# Path: taskflow/persistence/backends/sqlalchemy/tables.py
# NAME_LENGTH = 255
# UUID_LENGTH = 64
# STATE_LENGTH = 255
# VERSION_LENGTH = 64
# class JSONType(json_type.JSONType):
#     def process_bind_param(self, value, dialect):
#     def process_result_value(self, value, dialect):
# def fetch(metadata):


import logging
import sqlalchemy as sa
from alembic import op
from taskflow.persistence.backends.sqlalchemy import tables

def _get_foreign_keys():
    f_keys = [
        # Flow details uuid -> logbook parent uuid
        {
            'constraint_name': 'flowdetails_ibfk_1',
            'source_table': 'flowdetails',
            'referent_table': 'logbooks',
            'local_cols': ['parent_uuid'],
            'remote_cols': ['uuid'],
            'ondelete': 'CASCADE',
        },
        # Task details uuid -> flow details parent uuid
        {
            'constraint_name': 'taskdetails_ibfk_1',
            'source_table': 'taskdetails',
            'referent_table': 'flowdetails',
            'local_cols': ['parent_uuid'],
            'remote_cols': ['uuid'],
            'ondelete': 'CASCADE',
        },
    ]
    return f_keys


def upgrade():
    op.create_table('logbooks',
                    sa.Column('created_at', sa.DateTime),
                    sa.Column('updated_at', sa.DateTime),
                    sa.Column('meta', sa.Text(), nullable=True),

# Path: taskflow/persistence/backends/sqlalchemy/tables.py
# NAME_LENGTH = 255
# UUID_LENGTH = 64
# STATE_LENGTH = 255
# VERSION_LENGTH = 64
# class JSONType(json_type.JSONType):
#     def process_bind_param(self, value, dialect):
#     def process_result_value(self, value, dialect):
# def fetch(metadata):


# Path: taskflow/persistence/backends/sqlalchemy/alembic/versions/1cea328f0f65_initial_logbook_deta.py
import logging
import sqlalchemy as sa
from alembic import op
from taskflow.persistence.backends.sqlalchemy import tables


def _get_foreign_keys():
    f_keys = [
        # Flow details uuid -> logbook parent uuid
        {
            'constraint_name': 'flowdetails_ibfk_1',
            'source_table': 'flowdetails',
            'referent_table': 'logbooks',
            'local_cols': ['parent_uuid'],
            'remote_cols': ['uuid'],
            'ondelete': 'CASCADE',
        },
        # Task details uuid -> flow details parent uuid
        {
            'constraint_name': 'taskdetails_ibfk_1',
            'source_table': 'taskdetails',
            'referent_table': 'flowdetails',
            'local_cols': ['parent_uuid'],
            'remote_cols': ['uuid'],
            'ondelete': 'CASCADE',
        },
    ]
    return f_keys


def upgrade():
    op.create_table('logbooks',
                    sa.Column('created_at', sa.DateTime),
                    sa.Column('updated_at', sa.DateTime),
                    sa.Column('meta', sa.Text(), nullable=True),

                    sa.Column('name', sa.String(length=tables.NAME_LENGTH),