feat: 根目录文档、脚本、gitignore
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""只读勘察:200库 与 161 两个库中 需求9197 的现状。绝不写入。"""
|
||||
import io, sys, pymysql
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
|
||||
SRC = dict(host='192.168.3.200', user='root', password='PX4fTAAsJ#T!1',
|
||||
database='zentao_dev', charset='utf8mb4', connect_timeout=15)
|
||||
DST = dict(host='192.168.1.161', user='devgps', password='dev@2021GPS',
|
||||
charset='utf8mb4', connect_timeout=15)
|
||||
|
||||
SID = 9197
|
||||
|
||||
def tables_with(cur, db, names):
|
||||
cur.execute("""SELECT table_name FROM information_schema.tables
|
||||
WHERE table_schema=%s AND table_name IN (%s)""" %
|
||||
('%s', ','.join(['%s']*len(names))), (db, *names))
|
||||
return {r[0] for r in cur.fetchall()}
|
||||
|
||||
REL = ['zt_storyspec', 'zt_storystage', 'zt_storyreview', 'zt_storyexpand',
|
||||
'zt_projectstory', 'zt_storyestimate', 'zt_task', 'zt_bug', 'zt_case']
|
||||
|
||||
def inspect(conn, db):
|
||||
cur = conn.cursor()
|
||||
print(f'\n===== {conn.host} / {db} =====')
|
||||
cur.execute(f'USE `{db}`')
|
||||
cur.execute("""SELECT id, product, branch, module, plan, parent, title, status, stage,
|
||||
version, pri, estimate, openedBy, assignedTo, reviewedBy,
|
||||
closedReason, deleted, FROM_UNIXTIME(0) FROM zt_story WHERE id=%s""", (SID,))
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
print('zt_story 9197: 不存在')
|
||||
return
|
||||
labels = ['id','product','branch','module','plan','parent','title','status','stage',
|
||||
'version','pri','estimate','openedBy','assignedTo','reviewedBy','closedReason','deleted']
|
||||
for k, v in zip(labels, row[:17]):
|
||||
print(f' {k}: {v}')
|
||||
exist = tables_with(cur, db, REL)
|
||||
for t in REL:
|
||||
if t not in exist:
|
||||
print(f' {t}: 表不存在')
|
||||
continue
|
||||
col = {'zt_storyspec': 'story', 'zt_storystage': 'story', 'zt_storyreview': 'story',
|
||||
'zt_storyexpand': 'story_id', 'zt_projectstory': 'story',
|
||||
'zt_storyestimate': 'story', 'zt_task': 'story', 'zt_bug': 'story',
|
||||
'zt_case': 'story'}[t]
|
||||
try:
|
||||
cur.execute(f'SELECT COUNT(*) FROM `{t}` WHERE `{col}`=%s', (SID,))
|
||||
print(f' {t}({col}=9197): {cur.fetchone()[0]} 行')
|
||||
except Exception as e:
|
||||
print(f' {t}: 查询失败 {e}')
|
||||
# storyspec 版本明细
|
||||
if 'zt_storyspec' in exist:
|
||||
cur.execute('SELECT story, version, LEFT(title,40), LENGTH(spec), LENGTH(verify) FROM zt_storyspec WHERE story=%s ORDER BY version', (SID,))
|
||||
for r in cur.fetchall():
|
||||
print(f' storyspec v{r[1]}: title={r[2]!r} spec_len={r[3]} verify_len={r[4]}')
|
||||
# 附件/动作条数
|
||||
for t, cond in [('zt_file', "objectType='story'"), ('zt_action', "objectType='story'")]:
|
||||
cur.execute("SELECT table_name FROM information_schema.tables WHERE table_schema=%s AND table_name=%s", (db, t))
|
||||
if cur.fetchone():
|
||||
cur.execute(f"SELECT COUNT(*) FROM `{t}` WHERE {cond} AND objectID=%s", (SID,))
|
||||
print(f' {t}(story,9197): {cur.fetchone()[0]} 行')
|
||||
|
||||
src = pymysql.connect(**SRC)
|
||||
inspect(src, 'zentao_dev')
|
||||
src.close()
|
||||
|
||||
dst = pymysql.connect(**DST)
|
||||
cur = dst.cursor()
|
||||
cur.execute('SHOW DATABASES')
|
||||
dbs = [r[0] for r in cur.fetchall()]
|
||||
print(f'\n161 上的库: {[d for d in dbs if d.startswith("zentao")]}')
|
||||
for db in dbs:
|
||||
if db.startswith('zentao'):
|
||||
inspect(dst, db)
|
||||
dst.close()
|
||||
Reference in New Issue
Block a user