-- 用户表
DROP TABLE IF EXISTS "user";
CREATE TABLE "user" (
    "id" INTEGER PRIMARY KEY AUTOINCREMENT,
    "username" TEXT NOT NULL,
    "password" TEXT NOT NULL,
    "email" TEXT,
    "created_at" DATETIME DEFAULT CURRENT_TIMESTAMP,
    "updated_at" DATETIME DEFAULT CURRENT_TIMESTAMP,
    "token" TEXT,
    "token_enddata" DATETIME,
    UNIQUE ("username" ASC)
);

-- Markdown文件表
CREATE TABLE IF NOT EXISTS markdown_file (
     id INTEGER PRIMARY KEY AUTOINCREMENT,
     user_id INTEGER NOT NULL,
     grouping_id TEXT,
     title TEXT NOT NULL,
     file_name TEXT NOT NULL,
     content TEXT NOT NULL,
     created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
     updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    is_deleted INTEGER DEFAULT 0,
    deleted_at DATETIME,
    deleted_by INTEGER,
    is_private INTEGER DEFAULT 0  -- 新增字段：0=公开，1=私密
    );

-- 图片表
CREATE TABLE IF NOT EXISTS image (
     id INTEGER PRIMARY KEY AUTOINCREMENT,
     user_id INTEGER NOT NULL,
     markdown_id INTEGER,
     original_name TEXT NOT NULL,
     stored_name TEXT NOT NULL UNIQUE,
     url TEXT NOT NULL,
     size INTEGER NOT NULL,
     content_type TEXT NOT NULL,
     created_at DATETIME DEFAULT CURRENT_TIMESTAMP
    );

-- 文件分组表
CREATE TABLE "grouping" (
    "id" INTEGER NOT NULL DEFAULT 0,
    "grouping" TEXT NOT NULL,
    "parentId" INTEGER,
    "is_deleted" INTEGER DEFAULT 0,
    "deleted_at" DATETIME,
    "deleted_by" INTEGER,
    PRIMARY KEY ("id")
);