Initial DB API models implementation.

This commit is contained in:
Felipe Monteiro 2017-07-17 15:36:13 +01:00
parent 5af0a79ff6
commit 03cc29116e
3 changed files with 68 additions and 0 deletions

0
deckhand/db/__init__.py Normal file
View File

65
deckhand/db/api_models.py Normal file
View File

@ -0,0 +1,65 @@
# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
#
# 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 json
from oslo_db.sqlalchemy import models
from oslo_utils import timeutils
import sqlalchemy as sa
from sqlalchemy.ext import declarative
from sqlalchemy import orm as sa_orm
from sqlalchemy import types as sa_types
class _DeckhandBase(models.ModelBase, models.TimestampMixin):
pass
# Declarative base class which maintains a catalog of classes and tables
# relative to that base.
API_BASE = declarative.declarative_base(cls=_DeckhandBase)
class JSONEncodedDict(sa_types.TypeDecorator):
"""Represents an immutable structure as a json-encoded string.
Usage::
JSONEncodedDict(255)
"""
impl = sa_types.VARCHAR
def process_bind_param(self, value, dialect):
if value is not None:
value = json.dumps(value)
return value
def process_result_value(self, value, dialect):
if value is not None:
value = json.loads(value)
return value
class Document(API_BASE):
__tablename__ = 'document'
id = sa.Column(sa.String(255), primary_key=True, autoincrement=True)
document_schema = sa.Column(sa.String(64), nullable=False)
# Represents metadata.name parameter.
instance_key = sa.Column(sa.String(64), nullable=False, unique=True)
metadata = sa.Column(JSONEncodedDict(), nullable=False)
data = sa.Column(JSONEncodedDict(), nullable=False)

View File

@ -1,5 +1,7 @@
falcon==1.1.0
SQLAlchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8,>=1.0.10 # MIT
jsonschema!=2.5.0,<3.0.0,>=2.0.0 # MIT
pbr!=2.1.0,>=2.0.0 # Apache-2.0
six>=1.9.0 # MIT
stevedore>=1.20.0 # Apache-2.0
@ -7,6 +9,7 @@ jsonschema!=2.5.0,<3.0.0,>=2.0.0 # MIT
keystoneauth1>=2.21.0 # Apache-2.0
oslo.config>=3.22.0 # Apache-2.0
oslo.context>=2.14.0 # Apache-2.0
oslo.db>=4.21.1 # Apache-2.0
oslo.log>=3.22.0 # Apache-2.0
oslo.serialization>=1.10.0 # Apache-2.0
oslo.utils>=3.20.0 # Apache-2.0