返回 Social Auto Upload
createTable.py
根目录 / db / createTable.py
1 import sqlite3
2 import json
3 import os
4
5 # 数据库文件路径(如果不存在会自动创建)
6 db_file = './database.db'
7
8 # 如果数据库已存在,则删除旧的表(可选)
9 # if os.path.exists(db_file):
10 # os.remove(db_file)
11
12 # 连接到SQLite数据库(如果文件不存在则会自动创建)
13 conn = sqlite3.connect(db_file)
14 cursor = conn.cursor()
15
16 # 创建账号记录表
17 cursor.execute('''
18 CREATE TABLE IF NOT EXISTS user_info (
19 id INTEGER PRIMARY KEY AUTOINCREMENT,
20 type INTEGER NOT NULL,
21 filePath TEXT NOT NULL, -- 存储文件路径
22 userName TEXT NOT NULL,
23 status INTEGER DEFAULT 0
24 )
25 ''')
26
27 # 创建文件记录表
28 cursor.execute('''CREATE TABLE IF NOT EXISTS file_records (
29 id INTEGER PRIMARY KEY AUTOINCREMENT, -- 唯一标识每条记录
30 filename TEXT NOT NULL, -- 文件名
31 filesize REAL, -- 文件大小(单位:MB)
32 upload_time DATETIME DEFAULT CURRENT_TIMESTAMP, -- 上传时间,默认当前时间
33 file_path TEXT -- 文件路径
34 )
35 ''')
36
37
38 # 提交更改
39 conn.commit()
40 print("✅ 表创建成功")
41 # 关闭连接
42 conn.close()
42 lines PYTHON