TenantDrive/init_db.py

40 lines
1.0 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 os
# 确保数据库文件存放在正确的目录
DB_PATH = 'database.db'
def init_db():
# 连接到数据库(如果不存在则创建)
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
# 创建外链表
cursor.execute('''
CREATE TABLE IF NOT EXISTS exlinks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
exlink_id TEXT NOT NULL,
qr_limit INTEGER DEFAULT 3,
drivers TEXT, -- 存储为JSON字符串例如 '["quark","wechat"]'
use_limit INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
# 创建用户表(如果需要的话)
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL UNIQUE,
token TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
# 提交更改
conn.commit()
conn.close()
if __name__ == '__main__':
init_db()
print("Database initialized successfully!")