summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2021-10-26 22:08:33 +0000
committerGerrit Code Review <review@openstack.org>2021-10-26 22:08:33 +0000
commit6d9330a1b0afaa1fdb8c995c009b4ac90db94c00 (patch)
tree4d2abb34de5373cfd4fa25c8d6ec91591567a41e
parent05bdafd3a4430d9c94f5433656050cfeb9094584 (diff)
parent3e1f150926029b6a553cbef959f370e39ce6bb5a (diff)
downloadtaskflow-6d9330a1b0afaa1fdb8c995c009b4ac90db94c00.tar.gz
Merge "Use custom JSONType columns"4.6.3
-rw-r--r--taskflow/persistence/backends/sqlalchemy/tables.py35
1 files changed, 27 insertions, 8 deletions
diff --git a/taskflow/persistence/backends/sqlalchemy/tables.py b/taskflow/persistence/backends/sqlalchemy/tables.py
index b9b065e..062409a 100644
--- a/taskflow/persistence/backends/sqlalchemy/tables.py
+++ b/taskflow/persistence/backends/sqlalchemy/tables.py
@@ -16,10 +16,11 @@
import collections
+from oslo_serialization import jsonutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
from sqlalchemy import Table, Column, String, ForeignKey, DateTime, Enum
-import sqlalchemy_utils as su
+from sqlalchemy_utils.types import json as json_type
from taskflow.persistence import models
from taskflow import states
@@ -34,6 +35,24 @@ STATE_LENGTH = 255
VERSION_LENGTH = 64
+class JSONType(json_type.JSONType):
+ """Customized JSONType using oslo.serialization for json operations"""
+
+ def process_bind_param(self, value, dialect):
+ if dialect.name == 'postgresql' and json_type.has_postgres_json:
+ return value
+ if value is not None:
+ value = jsonutils.dumps(value)
+ return value
+
+ def process_result_value(self, value, dialect):
+ if dialect.name == 'postgresql':
+ return value
+ if value is not None:
+ value = jsonutils.loads(value)
+ return value
+
+
def fetch(metadata):
"""Returns the master set of table objects (which is also there schema)."""
logbooks = Table('logbooks', metadata,
@@ -41,7 +60,7 @@ def fetch(metadata):
default=timeutils.utcnow),
Column('updated_at', DateTime,
onupdate=timeutils.utcnow),
- Column('meta', su.JSONType),
+ Column('meta', JSONType),
Column('name', String(length=NAME_LENGTH)),
Column('uuid', String(length=UUID_LENGTH),
primary_key=True, nullable=False, unique=True,
@@ -54,7 +73,7 @@ def fetch(metadata):
Column('parent_uuid', String(length=UUID_LENGTH),
ForeignKey('logbooks.uuid',
ondelete='CASCADE')),
- Column('meta', su.JSONType),
+ Column('meta', JSONType),
Column('name', String(length=NAME_LENGTH)),
Column('state', String(length=STATE_LENGTH)),
Column('uuid', String(length=UUID_LENGTH),
@@ -65,7 +84,7 @@ def fetch(metadata):
default=timeutils.utcnow),
Column('updated_at', DateTime,
onupdate=timeutils.utcnow),
- Column('meta', su.JSONType),
+ Column('meta', JSONType),
Column('parent_uuid', String(length=UUID_LENGTH),
ForeignKey('flowdetails.uuid',
ondelete='CASCADE')),
@@ -75,10 +94,10 @@ def fetch(metadata):
Column('uuid', String(length=UUID_LENGTH),
primary_key=True, nullable=False, unique=True,
default=uuidutils.generate_uuid),
- Column('failure', su.JSONType),
- Column('results', su.JSONType),
- Column('revert_results', su.JSONType),
- Column('revert_failure', su.JSONType),
+ Column('failure', JSONType),
+ Column('results', JSONType),
+ Column('revert_results', JSONType),
+ Column('revert_failure', JSONType),
Column('atom_type', Enum(*models.ATOM_TYPES,
name='atom_types')),
Column('intention', Enum(*states.INTENTIONS,