Saved layouts feature
This commit is contained in:
@@ -558,6 +558,72 @@ def _migration_22(conn) -> None:
|
||||
conn.execute(text("ALTER TABLE text_widget_configs ADD COLUMN font_family TEXT NOT NULL DEFAULT 'sans'"))
|
||||
|
||||
|
||||
def _migration_23(conn) -> None:
|
||||
"""New feature: named, user-owned saved layouts (see models.
|
||||
SavedLayout/SavedLayoutWidget/SavedLayoutSource/
|
||||
SavedLayoutButtonAction, routers/api_layouts.py) -- a snapshot of a
|
||||
frame's widget arrangement a user can capture and later apply to any
|
||||
frame they control whose grid matches, instead of manually rebuilding
|
||||
it widget by widget.
|
||||
|
||||
Raw CREATE TABLE, not Base.metadata.create_all, same reasoning as
|
||||
migration 20/21's own comments: create_all always reflects models.py's
|
||||
CURRENT shape, so replaying the full chain on an old database could
|
||||
collide with a later migration's ALTER TABLE on one of these same
|
||||
tables."""
|
||||
conn.execute(text(
|
||||
"CREATE TABLE saved_layouts ("
|
||||
"id INTEGER PRIMARY KEY, "
|
||||
"user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, "
|
||||
"name TEXT NOT NULL, "
|
||||
"cols INTEGER NOT NULL, "
|
||||
"rows INTEGER NOT NULL, "
|
||||
"created_at REAL NOT NULL DEFAULT 0.0, "
|
||||
"updated_at REAL NOT NULL DEFAULT 0.0)"
|
||||
))
|
||||
conn.execute(text(
|
||||
"CREATE UNIQUE INDEX ix_saved_layouts_user_name ON saved_layouts (user_id, name)"
|
||||
))
|
||||
conn.execute(text(
|
||||
"CREATE TABLE saved_layout_widgets ("
|
||||
"id INTEGER PRIMARY KEY, "
|
||||
"saved_layout_id INTEGER NOT NULL REFERENCES saved_layouts(id) ON DELETE CASCADE, "
|
||||
"widget_type TEXT NOT NULL, "
|
||||
"x INTEGER NOT NULL, y INTEGER NOT NULL, w INTEGER NOT NULL, h INTEGER NOT NULL, "
|
||||
"sort_order INTEGER NOT NULL DEFAULT 0, "
|
||||
"config TEXT NOT NULL DEFAULT '{}', "
|
||||
"image BLOB)"
|
||||
))
|
||||
conn.execute(text(
|
||||
"CREATE INDEX ix_saved_layout_widgets_layout ON saved_layout_widgets (saved_layout_id)"
|
||||
))
|
||||
conn.execute(text(
|
||||
"CREATE TABLE saved_layout_sources ("
|
||||
"id INTEGER PRIMARY KEY, "
|
||||
"saved_layout_widget_id INTEGER NOT NULL REFERENCES saved_layout_widgets(id) ON DELETE CASCADE, "
|
||||
"kind TEXT NOT NULL, "
|
||||
"user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, "
|
||||
"calendar_key TEXT NOT NULL, "
|
||||
"calendar_label TEXT NOT NULL DEFAULT '', "
|
||||
"included INTEGER NOT NULL DEFAULT 1, "
|
||||
"color_index INTEGER)"
|
||||
))
|
||||
conn.execute(text(
|
||||
"CREATE INDEX ix_saved_layout_sources_widget ON saved_layout_sources (saved_layout_widget_id)"
|
||||
))
|
||||
conn.execute(text(
|
||||
"CREATE TABLE saved_layout_button_actions ("
|
||||
"id INTEGER PRIMARY KEY, "
|
||||
"saved_layout_widget_id INTEGER NOT NULL REFERENCES saved_layout_widgets(id) ON DELETE CASCADE, "
|
||||
"button TEXT NOT NULL, "
|
||||
"action TEXT NOT NULL, "
|
||||
"sort_order INTEGER NOT NULL DEFAULT 0)"
|
||||
))
|
||||
conn.execute(text(
|
||||
"CREATE INDEX ix_saved_layout_button_actions_widget ON saved_layout_button_actions (saved_layout_widget_id)"
|
||||
))
|
||||
|
||||
|
||||
MIGRATIONS = [
|
||||
(1, _migration_1),
|
||||
(2, _migration_2),
|
||||
@@ -581,6 +647,7 @@ MIGRATIONS = [
|
||||
(20, _migration_20),
|
||||
(21, _migration_21),
|
||||
(22, _migration_22),
|
||||
(23, _migration_23),
|
||||
]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user