From aacbe8a128da0e749d4fc2c84d1135277e21f338 Mon Sep 17 00:00:00 2001 From: gecong1973 Date: Thu, 25 Oct 2018 01:33:24 -0700 Subject: [PATCH] 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 --- .../versions/001_freezer_api_init.py | 22 ++++++++++++++++++- freezer_api/db/sqlalchemy/models.py | 20 +++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/freezer_api/db/sqlalchemy/migrate_repo/versions/001_freezer_api_init.py b/freezer_api/db/sqlalchemy/migrate_repo/versions/001_freezer_api_init.py index e9ba8612..c20370ac 100644 --- a/freezer_api/db/sqlalchemy/migrate_repo/versions/001_freezer_api_init.py +++ b/freezer_api/db/sqlalchemy/migrate_repo/versions/001_freezer_api_init.py @@ -136,7 +136,27 @@ def define_tables(meta): 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): diff --git a/freezer_api/db/sqlalchemy/models.py b/freezer_api/db/sqlalchemy/models.py index d9d383a8..9666082c 100644 --- a/freezer_api/db/sqlalchemy/models.py +++ b/freezer_api/db/sqlalchemy/models.py @@ -148,16 +148,32 @@ class ActionReport(BASE, FreezerBase): 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): _models = (Client, Action, Job, Session, - ActionReport) + ActionReport, Backup) for _model in _models: _model.metadata.create_all(engine) def unregister_models(engine): _models = (Client, Action, Job, Session, - ActionReport) + ActionReport, Backup) for _model in _models: _model.metadata.drop_all(engine)