autoUpload/db/createTable.py
2025-09-08 09:32:45 +08:00

42 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()