Commit 8c4fd68a authored by wanli's avatar wanli

🐞 fix(): 完善数据库迁移脚本

parent 05c79cbc
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
''' '''
Author: your name Author: your name
Date: 2021-07-20 19:04:27 Date: 2021-07-20 19:04:27
LastEditTime: 2021-07-20 20:45:12 LastEditTime: 2021-07-21 01:10:53
LastEditors: Please set LastEditors LastEditors: Please set LastEditors
Description: In User Settings Edit Description: In User Settings Edit
FilePath: \evm-store\tools\database_migration.py FilePath: \evm-store\tools\database_migration.py
...@@ -62,9 +62,73 @@ for line in res: ...@@ -62,9 +62,73 @@ for line in res:
target_cur.execute(string) target_cur.execute(string)
target_conn.commit() target_conn.commit()
# 更新app_url字段
sql = "select app, app_path from evm_store_build_logs"
source_cur.execute(sql)
res = source_cur.fetchall()
for line in res:
string = "update evm_store_apps set app_url = '{u}' where id = {a}".format(u=line[1], a=line[0])
target_cur.execute(string)
target_conn.commit()
# annex
source_cur.execute('SELECT id, uuid, app, title, path, size, create_by, create_at, update_by, update_at, is_delete FROM evm_store_annex')
res = source_cur.fetchall()
sql = "insert into evm_annex (id, uuid, app, title, path, size, create_at, create_by, update_at, update_by, is_delete) values ({a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, 0);"
for line in res:
sql.format(a=line[0], b=uuid.uuid1().hex, c=line[2], d=line[3], e=line[4], f=line[5], g=line[6], h=line[7], i=line[8], j=line[9])
target_cur.execute(string)
target_conn.commit()
# app # app
source_cur.execute('SELECT id, app_name, app_version, app_url, category, create_by, remarks FROM evm_store_apps') source_cur.execute('SELECT id, app_name, app_icon, app_version, category, app_url, app_desc, create_at, create_by ,update_at, update_by, is_delete FROM evm_store_apps')
res = source_cur.fetchall() res = source_cur.fetchall()
sql = "insert into evm_app (id, uuid, app_name, app_icon, app_version, category, download_url, app_screen_size, app_arch, app_review, meta_data, remarks, create_at, create_by, update_at, update_by, is_delete) values ({a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k}, {l}, {m}, {n}, {o}, {p} 0);"
for line in res:
sql.format(a=line[0], b=uuid.uuid1().hex, c=line[1], d=line[2], e=line[3], f=line[4], g=line[5], h="240 * 240", i="ASR3601", j=0, k='{}', l=line[6], m=line[7], n=line[8], o=line[9], p=line[10])
target_cur.execute(string)
target_conn.commit()
# device
source_cur.execute('SELECT id, name, imei, desc, type, create_at, create_by, update_at, update_by, is_delete FROM evm_store_device')
res = source_cur.fetchall()
sql = "insert into evm_device (id, uuid, name, imei, desc, type, create_at, create_by, update_at, update_by, is_delete) values ({a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k});"
for line in res:
sql.format(a=line[0], b=uuid.uuid1().hex, c=line[1], d=line[2], e=line[3], f=line[4], g=line[5], h=line[6], i=line[7], j=line[8], k=line[9])
target_cur.execute(string)
target_conn.commit()
# app log & build log
# 先插入app log
source_cur.execute('SELECT id, uuid, app_name, app_path, app_version, app_info, create_at, create_by FROM evm_store_app_logs')
res = source_cur.fetchall()
sql = "insert into evm_package (id, uuid, app_name, app_path, app_version, app_info, create_at, create_by, update_at, update_by, is_delete, source) values ({a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k}, {l});"
for line in res:
s = 1 if line[3].find("evueapps") > -1 else 0
sql.format(a=line[0], b=uuid.uuid1().hex, c=line[2], d=line[3], e=line[4], f=line[5], g=line[6], h=line[7], i=line[6], j=line[7], k=0, l=s)
target_cur.execute(string)
target_conn.commit()
# 然后查询出所有build log记录,遍历这些记录
# 在循环里,查询这一条记录是否已经存在(根据app_path),不存在则插入
source_cur.execute('SELECT id, uuid, app, app_path, app_info, source, create_at, create_by, update_at, update_by, is_delete FROM evm_store_build_logs')
res = source_cur.fetchall()
sql = "insert into evm_package (id, uuid, app_name, app_path, app_version, app_info, source, create_at, create_by, update_at, update_by, is_delete) values ({a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k}, {l});"
for line in res:
string = "select id, uuid, app_path from evm_store_app_logs where app_path = '{}'".format(line[3])
source_cur.execute(string)
tmp = source_cur.fetchone()
if tmp:
continue
string = "select app_name, app_version from evm_store_apps where id == {id}".format(id=line[2])
source_cur.execute(string)
app = source_cur.fetchone()
if app:
s = 1 if line[5] and line[5].find("evueapps") > -1 else 0
sql.format(a=line[0], b=uuid.uuid1().hex, c=app[0], d=line[3], e=app[1], f=line[4], g=s, h=line[6], i=line[7], j=line[8], k=line[9], l=line[10])
target_cur.execute(string)
target_conn.commit()
target_conn.commit() target_conn.commit()
target_conn.close() target_conn.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment