Modify mode field in action table for sqlite

The mode field is reserved word in sqlite, the patch
change it to actionmode

Change-Id: Ia9ad6e312562c260424134251600b6d100182ac0
This commit is contained in:
gecong1973 2019-03-27 21:07:23 -07:00
parent bd512f097d
commit b52291b7e6
5 changed files with 45 additions and 11 deletions

View File

@ -464,7 +464,7 @@ def add_action(user_id, doc, project_id=None):
else:
action_doc = utilsv2.ActionDoc.create(doc, user_id, project_id)
keyt = ['action', 'mode', 'backup_name',
keyt = ['action', 'backup_name',
'container', 'src_file', 'timeout',
'priority', 'mandatory', 'log_file']
freezer_action = action_doc.get('freezer_action', {})
@ -487,6 +487,7 @@ def add_action(user_id, doc, project_id=None):
actionvalue['max_retries'] = action_doc.get('max_retries', 5)
actionvalue['max_retries_interval'] = action_doc.\
get('max_retries_interval', 6)
actionvalue['actionmode'] = freezer_action.get('mode', None)
for key in freezer_action.keys():
if key in keyt:
@ -537,7 +538,7 @@ def get_action(user_id, action_id, project_id=None):
values['freezer_action']['backup_name'] = result[0].\
get('backup_name')
values['freezer_action']['action'] = result[0].get('action')
values['freezer_action']['mode'] = result[0].get('mode')
values['freezer_action']['mode'] = result[0].get('actionmode')
values['freezer_action']['container'] = result[0].\
get('container')
values['freezer_action']['timeout'] = result[0].get('timeout')
@ -569,7 +570,7 @@ def search_action(user_id, project_id=None, offset=0,
json_decode(action.get('backup_metadata'))
actionmap['freezer_action']['backup_name'] = action.\
get('backup_name')
actionmap['freezer_action']['mode'] = action.get('mode')
actionmap['freezer_action']['mode'] = action.get('actionmode')
actionmap['freezer_action']['action'] = action.get('action')
actionmap['freezer_action']['container'] = action.\
get('container')
@ -593,7 +594,7 @@ def update_action(user_id, action_id, patch_doc, project_id=None):
else:
valid_patch = utilsv2.ActionDoc.create_patch(patch_doc)
keyt = ['action', 'mode', 'backup_name', 'container',
keyt = ['action', 'backup_name', 'container',
'src_file', 'timeout', 'priority', 'mandatory', 'log_file']
values = {}
@ -612,6 +613,7 @@ def update_action(user_id, action_id, patch_doc, project_id=None):
if key in keyt:
values[key] = freezer_action.get(key)
values['actionmode'] = freezer_action.get('mode', None)
values['backup_metadata'] = json_utils.json_encode(freezer_action)
update_tuple(tablename=models.Action, user_id=user_id, tuple_id=action_id,
@ -627,7 +629,7 @@ def replace_action(user_id, action_id, doc, project_id=None):
valid_doc = utilsv2.ActionDoc.update(doc, user_id, action_id,
project_id)
values = {}
keyt = ['action', 'mode', 'backup_name', 'container',
keyt = ['action', 'backup_name', 'container',
'src_file', 'timeout', 'priority', 'mandatory', 'log_file']
freezer_action = valid_doc.get('freezer_action', {})
@ -643,6 +645,7 @@ def replace_action(user_id, action_id, doc, project_id=None):
for key in freezer_action.keys():
if key in keyt:
values[key] = freezer_action.get(key)
values['actionmode'] = freezer_action.get('mode', None)
values['backup_metadata'] = json_utils.json_encode(freezer_action)
replace_tuple(tablename=models.Action, user_id=user_id,
tuple_id=action_id, tuple_values=values,

View File

@ -17,7 +17,7 @@ from sqlalchemy import BLOB, TIMESTAMP
CLASS_NAME = 'default'
def define_tables(meta):
def define_tables(meta, sqlite):
clients = Table(
'clients', meta,
Column('created_at', DateTime(timezone=False)),
@ -94,6 +94,11 @@ def define_tables(meta):
# The field metadata is json, including :
# nova_inst_id, engine_name, storage, remove_older_than, restore_from_date,
# command, incremental, restore_abs_path, etc
if sqlite:
column_name = 'actionmode'
else:
column_name = 'mode'
actions = Table(
'actions', meta,
Column('created_at', DateTime(timezone=False)),
@ -104,7 +109,7 @@ def define_tables(meta):
Column('action', String(255), nullable=False),
Column('project_id', String(36)),
Column('user_id', String(36), nullable=False),
Column('mode', String(255)),
Column(column_name, String(255)),
Column('src_file', String(255)),
Column('backup_name', String(255)),
Column('container', String(255)),
@ -154,7 +159,6 @@ def define_tables(meta):
mysql_engine='InnoDB',
mysql_charset='utf8'
)
return [clients, sessions, jobs, actions, action_reports, backups]
@ -164,7 +168,11 @@ def upgrade(migrate_engine):
# create all tables
# Take care on create order for those with FK dependencies
tables = define_tables(meta)
if migrate_engine.name == 'sqlite':
sqlite = True
else:
sqlite = False
tables = define_tables(meta, sqlite)
for table in tables:
table.create()

View File

@ -0,0 +1,23 @@
# 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.
from sqlalchemy import MetaData, Table
def upgrade(migrate_engine):
if migrate_engine.name == 'sqlite':
return
meta = MetaData()
meta.bind = migrate_engine
actions = Table('actions', meta, autoload=True)
actions.c.mode.alter(name="actionmode")

View File

@ -79,7 +79,7 @@ class Action(BASE, FreezerBase):
action = Column(String(255), nullable=False)
project_id = Column(String(36))
user_id = Column(String(64), nullable=False)
mode = Column(String(255))
actionmode = Column(String(255))
src_file = Column(String(255))
backup_name = Column(String(255))
container = Column(String(255))

View File

@ -209,7 +209,7 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
'action',
'project_id',
'user_id',
'mode',
'actionmode',
'src_file',
'backup_name',
'container',