pull/32/merge
apexliu 2017-03-20 08:47:00 +08:00
parent e80d27c1a3
commit 738a5cf01e
2 changed files with 16 additions and 1 deletions

View File

@ -506,6 +506,15 @@ class DatabaseUpgrade:
# 判断依据:
# 如果 config 表中不存在名为db_ver的数据说明是旧版本需要升级
if not self.db.is_table_exists('config'):
if not self.db.exec("""CREATE TABLE `{}config` (
`name` varchar(256) NOT NULL,
`value` varchar(256),
PRIMARY KEY (`name` ASC)
);""".format(self.db.table_prefix)):
self.step_end(_step, -1, 'config表不存在且无法创建')
return False
db_ret = self.db.query('SELECT `value` FROM `{}config` WHERE `name`="db_ver";'.format(self.db.table_prefix))
if db_ret is None:
self.step_end(_step, -1)
@ -515,6 +524,12 @@ class DatabaseUpgrade:
return True
self.step_end(_step, 0, '需要升级到v5')
_step = self.step_begin(' - 调整表名称')
if not self.db.exec('ALTER TABLE `{}cert` RENAME TO `{}key`;'.format(self.db.table_prefix, self.db.table_prefix)):
self.step_end(_step, -1)
return False
self.step_end(_step, 0)
_step = self.step_begin(' - 更新数据库版本号')
if not self.db.exec('INSERT INTO `{}config` VALUES ("db_ver", "{}");'.format(self.db.table_prefix, self.db.DB_VERSION)):
self.step_end(_step, -1)

View File

@ -19,7 +19,7 @@ __all__ = ['get_db']
class TPDatabase:
DB_VERSION = 10
DB_VERSION = 5
DB_TYPE_UNKNOWN = 0
DB_TYPE_SQLITE = 1