Notes can now be clustered into named sections in the tab bar: each tab gets a 🏷 button to assign it to a section, and clicking a section's label renames (or, given an empty name, ungroups) every page in it. note_pages gains a `section` column. Since the app has no migration framework, database.py adds the column to existing SQLite files at startup via PRAGMA table_info + ALTER TABLE. core/notes.set_section() keeps same-section pages contiguous by renumbering position whenever a page's section changes, so the tab bar and the AI-facing title list (now grouped under "## section" headings) can both treat "adjacent" as "same group" without a separate ordering field. Also fixes a bug in the tab rename input: ref="renameInput" sits inside a nested v-for, which Vue 3 binds as an array rather than a single element, so renameInput.value?.select() was throwing on every rename. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from sqlalchemy import create_engine, text
|
|
from sqlalchemy.orm import sessionmaker, DeclarativeBase
|
|
from app.core.config import DATABASE_URL
|
|
|
|
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
def _add_missing_columns() -> None:
|
|
"""マイグレーションフレームワークを使っていないため、既存DBに後から追加されたカラムを
|
|
ここで簡易的に補う。create_all() は既存テーブルへのカラム追加は行わないので必要。"""
|
|
with engine.connect() as conn:
|
|
existing = {row[1] for row in conn.execute(text("PRAGMA table_info(note_pages)"))}
|
|
if existing and "section" not in existing:
|
|
conn.execute(text("ALTER TABLE note_pages ADD COLUMN section VARCHAR"))
|
|
conn.commit()
|
|
|
|
|
|
def init_db():
|
|
from app.db import models # noqa: F401
|
|
Base.metadata.create_all(bind=engine)
|
|
_add_missing_columns()
|