Initial commit with .gitignore
This commit is contained in:
51
reset_data.py
Normal file
51
reset_data.py
Normal file
@@ -0,0 +1,51 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
重置关系数据库脚本
|
||||
"""
|
||||
|
||||
import configparser
|
||||
import pymysql
|
||||
|
||||
|
||||
def main():
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini', encoding='utf-8')
|
||||
|
||||
print("=" * 50)
|
||||
print("重置 MySQL 数据")
|
||||
print("=" * 50)
|
||||
|
||||
db_conn = pymysql.connect(
|
||||
host=config.get('database', 'host'),
|
||||
port=config.getint('database', 'port'),
|
||||
user=config.get('database', 'user'),
|
||||
password=config.get('database', 'password'),
|
||||
database=config.get('database', 'database'),
|
||||
charset=config.get('database', 'charset'),
|
||||
cursorclass=pymysql.cursors.DictCursor
|
||||
)
|
||||
|
||||
with db_conn.cursor() as cursor:
|
||||
sql = """
|
||||
UPDATE ai_image_tags
|
||||
SET status = 'draft',
|
||||
similarity = 'draft',
|
||||
similarity_image_tags_id = 0,
|
||||
`similarity score` = 0
|
||||
WHERE status != 'draft' OR similarity != 'draft'
|
||||
"""
|
||||
affected = cursor.execute(sql)
|
||||
db_conn.commit()
|
||||
|
||||
cursor.execute("SELECT COUNT(*) as total FROM ai_image_tags WHERE status = 'draft'")
|
||||
result = cursor.fetchone()
|
||||
|
||||
db_conn.close()
|
||||
|
||||
print(f"更新记录数: {affected}")
|
||||
print(f"当前 draft 状态总数: {result['total']}")
|
||||
print("=" * 50)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user