autoUpload/db/createTable.py

42 lines
1.1 KiB
Python
Raw Normal View History

2025-09-08 09:32:45 +08:00
import sqlite3
import json
import os
# 数据库文件路径(如果不存在会自动创建)
db_file = './database.db'
# 如果数据库已存在,则删除旧的表(可选)
# if os.path.exists(db_file):
# os.remove(db_file)
# 连接到SQLite数据库如果文件不存在则会自动创建
conn = sqlite3.connect(db_file)
cursor = conn.cursor()
# 创建账号记录表
cursor.execute('''
CREATE TABLE IF NOT EXISTS user_info (
id INTEGER PRIMARY KEY AUTOINCREMENT,
type INTEGER NOT NULL,
filePath TEXT NOT NULL, -- 存储文件路径
userName TEXT NOT NULL,
status INTEGER DEFAULT 0
)
''')
# 创建文件记录表
cursor.execute('''CREATE TABLE IF NOT EXISTS file_records (
id INTEGER PRIMARY KEY AUTOINCREMENT, -- 唯一标识每条记录
filename TEXT NOT NULL, -- 文件名
filesize REAL, -- 文件大小单位MB
upload_time DATETIME DEFAULT CURRENT_TIMESTAMP, -- 上传时间默认当前时间
file_path TEXT -- 文件路径
)
''')
# 提交更改
conn.commit()
print("✅ 表创建成功")
# 关闭连接
conn.close()