1
# Copyright 2020 Inspur
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
# not use this file except in compliance with the License. You may obtain
5
# a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations
16
SQLAlchemy models for venus data.
19
from oslo_db.sqlalchemy import models
20
from oslo_utils import timeutils
21
from sqlalchemy import Column
22
from sqlalchemy.ext.declarative import declarative_base
23
from sqlalchemy import DateTime, String
24
from venus.conf import CONF
25
BASE = declarative_base()
28
class VenusBase(models.TimestampMixin,
30
"""Base class for Venus Models."""
32
__table_args__ = {'mysql_engine': 'InnoDB'}
34
# TODO(rpodolyaka): reuse models.SoftDeleteMixin in the next stage
35
# of implementing of BP db-cleanup
36
created_at = Column(DateTime)
37
updated_at = Column(DateTime)
38
deleted_at = Column(DateTime)
39
deleted = Column(String(1), default=0)
42
def delete(self, session):
43
"""Delete this object."""
45
self.deleted_at = timeutils.utcnow()
46
self.save(session=session)
49
def register_models():
50
"""Rvenuster Models and create metadata.
52
Called from venus.db.sqlalchemy.__init__ as part of loading the driver,
53
it will never need to be called explicitly elsewhere unless the
54
connection is lost and needs to be reestablished.
56
from sqlalchemy import create_engine
59
engine = create_engine(CONF.database.connection, echo=False)
61
model.metadata.create_all(engine)
64
class RegitsterTask(BASE, VenusBase):
65
__tablename__ = 't_mo_regitster_task'
66
Id = Column(String(11), primary_key=True)
67
task_name = Column(String(255))
68
host_name = Column(String(255))
69
update_time = Column(DateTime())