Release Nouri 1.3.3 with shopping articles
This commit is contained in:
+111
-1
@@ -15,7 +15,7 @@ from .constants import (
|
||||
DEFAULT_CATEGORY_BUILDERS,
|
||||
)
|
||||
|
||||
CURRENT_SCHEMA_VERSION = "1.3.2"
|
||||
CURRENT_SCHEMA_VERSION = "1.3.3"
|
||||
|
||||
ANIMAL_HINTS = (
|
||||
"huhn",
|
||||
@@ -423,6 +423,109 @@ def set_meta(database: sqlite3.Connection, key: str, value: str) -> None:
|
||||
)
|
||||
|
||||
|
||||
def item_kind_constraint_supports_shopping(database: sqlite3.Connection) -> bool:
|
||||
row = database.execute(
|
||||
"""
|
||||
SELECT sql
|
||||
FROM sqlite_master
|
||||
WHERE type = 'table' AND name = 'items'
|
||||
"""
|
||||
).fetchone()
|
||||
return bool(row and row["sql"] and "'shopping'" in row["sql"])
|
||||
|
||||
|
||||
def migrate_items_kind_constraint(database: sqlite3.Connection) -> None:
|
||||
if not table_exists(database, "items") or item_kind_constraint_supports_shopping(database):
|
||||
return
|
||||
|
||||
columns = table_columns(database, "items")
|
||||
if "kind" not in columns:
|
||||
return
|
||||
|
||||
foreign_keys_enabled = bool(database.execute("PRAGMA foreign_keys").fetchone()[0])
|
||||
if foreign_keys_enabled:
|
||||
database.execute("PRAGMA foreign_keys = OFF")
|
||||
try:
|
||||
database.execute("DROP TABLE IF EXISTS items_new")
|
||||
database.execute(
|
||||
"""
|
||||
CREATE TABLE items_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
household_id INTEGER,
|
||||
owner_user_id INTEGER,
|
||||
target_user_id INTEGER,
|
||||
visibility TEXT NOT NULL DEFAULT 'shared',
|
||||
kind TEXT NOT NULL CHECK (kind IN ('food', 'meal', 'shopping')),
|
||||
name TEXT NOT NULL,
|
||||
category TEXT,
|
||||
base_type TEXT NOT NULL DEFAULT 'neutral',
|
||||
flavor_profile TEXT NOT NULL DEFAULT 'neutral',
|
||||
suggestion_role TEXT NOT NULL DEFAULT 'base',
|
||||
suggestion_priority TEXT NOT NULL DEFAULT 'normal',
|
||||
can_be_meal_core INTEGER NOT NULL DEFAULT 0,
|
||||
meal_type TEXT,
|
||||
meal_tags TEXT NOT NULL DEFAULT '',
|
||||
energy_density TEXT NOT NULL DEFAULT 'neutral',
|
||||
note TEXT,
|
||||
photo_filename TEXT,
|
||||
availability_state TEXT NOT NULL DEFAULT 'idea' CHECK (availability_state IN ('idea', 'home', 'archived')),
|
||||
is_archived INTEGER NOT NULL DEFAULT 0,
|
||||
is_quick_added INTEGER NOT NULL DEFAULT 0,
|
||||
created_by INTEGER,
|
||||
updated_by INTEGER,
|
||||
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (household_id) REFERENCES households(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (owner_user_id) REFERENCES users(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (target_user_id) REFERENCES users(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
)
|
||||
"""
|
||||
)
|
||||
target_columns = [
|
||||
"id",
|
||||
"household_id",
|
||||
"owner_user_id",
|
||||
"target_user_id",
|
||||
"visibility",
|
||||
"kind",
|
||||
"name",
|
||||
"category",
|
||||
"base_type",
|
||||
"flavor_profile",
|
||||
"suggestion_role",
|
||||
"suggestion_priority",
|
||||
"can_be_meal_core",
|
||||
"meal_type",
|
||||
"meal_tags",
|
||||
"energy_density",
|
||||
"note",
|
||||
"photo_filename",
|
||||
"availability_state",
|
||||
"is_archived",
|
||||
"is_quick_added",
|
||||
"created_by",
|
||||
"updated_by",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
copy_columns = [column for column in target_columns if column in columns]
|
||||
quoted_columns = ", ".join(copy_columns)
|
||||
database.execute(
|
||||
f"""
|
||||
INSERT INTO items_new ({quoted_columns})
|
||||
SELECT {quoted_columns}
|
||||
FROM items
|
||||
"""
|
||||
)
|
||||
database.execute("DROP TABLE items")
|
||||
database.execute("ALTER TABLE items_new RENAME TO items")
|
||||
finally:
|
||||
if foreign_keys_enabled:
|
||||
database.execute("PRAGMA foreign_keys = ON")
|
||||
|
||||
|
||||
def bootstrap_legacy_schema(database: sqlite3.Connection) -> None:
|
||||
ensure_meta_table(database)
|
||||
database.execute(
|
||||
@@ -739,6 +842,7 @@ def ensure_schema_upgrades(database: sqlite3.Connection) -> None:
|
||||
add_column_if_missing(database, "items", "energy_density TEXT NOT NULL DEFAULT 'neutral'")
|
||||
add_column_if_missing(database, "items", "is_archived INTEGER NOT NULL DEFAULT 0")
|
||||
add_column_if_missing(database, "items", "is_quick_added INTEGER NOT NULL DEFAULT 0")
|
||||
migrate_items_kind_constraint(database)
|
||||
add_column_if_missing(database, "shopping_entries", "needed_for_date TEXT")
|
||||
add_column_if_missing(database, "shopping_entries", "needed_for_daypart_id INTEGER")
|
||||
add_column_if_missing(database, "shopping_entries", "shopping_note TEXT NOT NULL DEFAULT ''")
|
||||
@@ -821,6 +925,12 @@ def ensure_schema_upgrades(database: sqlite3.Connection) -> None:
|
||||
WHERE email IS NOT NULL AND email != ''
|
||||
"""
|
||||
)
|
||||
database.execute(
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS idx_items_kind_name
|
||||
ON items (kind, name)
|
||||
"""
|
||||
)
|
||||
database.execute(
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS idx_items_household_visibility
|
||||
|
||||
Reference in New Issue
Block a user