Add backup table for bp add-mysql-support-for-freezer

Add backup table in v2.
The other tables,api and test will be added in following patch.

ref: https://storyboard.openstack.org/#!/story/2004132

Story: #2004132
Task: #27578

Change-Id: Iff6628fb8de4bf0481f0f73cc70a6d33512516ff
Implements: bp add-mysql-support-for-freezer
This commit is contained in:
gecong1973 2018-10-25 01:33:24 -07:00 committed by gengchc2
parent 796c41ac7d
commit aacbe8a128
2 changed files with 39 additions and 3 deletions

View File

@ -136,7 +136,27 @@ def define_tables(meta):
mysql_charset='utf8' mysql_charset='utf8'
) )
return [clients, sessions, jobs, actions, action_reports] # The field metadata is json, including :
# nova_inst_id, engine_name, storage, remove_older_than, restore_from_date,
# command, incremental, restore_abs_path, etc
backups = Table(
'backups', meta,
Column('created_at', DateTime(timezone=False)),
Column('updated_at', DateTime(timezone=False)),
Column('deleted_at', DateTime),
Column('deleted', Boolean),
Column('id', String(36), primary_key=True, nullable=False),
Column('client_id', String(255), nullable=False),
Column('job_id', String(36), nullable=False),
Column('project_id', String(36), nullable=False),
Column('user_id', String(64), nullable=False),
Column('user_name', String(64)),
Column('backup_metadata', Text),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
return [clients, sessions, jobs, actions, action_reports, backups]
def upgrade(migrate_engine): def upgrade(migrate_engine):

View File

@ -148,16 +148,32 @@ class ActionReport(BASE, FreezerBase):
log = Column(BLOB) log = Column(BLOB)
class Backup(BASE, FreezerBase):
"""Represents freezer Backup."""
# The field backup_metadata is json, including :
# nova_inst_id, engine_name, storage, remove_older_than, restore_from_date,
# command, incremental, restore_abs_path, etc
__tablename__ = 'backups'
id = Column(String(36), primary_key=True)
client_id = Column(String(255), nullable=False)
job_id = Column(String(36), nullable=False)
project_id = Column(String(36), nullable=False)
user_id = Column(String(64), nullable=False)
user_name = Column(String(64), nullable=False)
backup_metadata = Column(Text)
def register_models(engine): def register_models(engine):
_models = (Client, Action, Job, Session, _models = (Client, Action, Job, Session,
ActionReport) ActionReport, Backup)
for _model in _models: for _model in _models:
_model.metadata.create_all(engine) _model.metadata.create_all(engine)
def unregister_models(engine): def unregister_models(engine):
_models = (Client, Action, Job, Session, _models = (Client, Action, Job, Session,
ActionReport) ActionReport, Backup)
for _model in _models: for _model in _models:
_model.metadata.drop_all(engine) _model.metadata.drop_all(engine)