release nouri 0.3 household sharing and mobile polish
This commit is contained in:
+40
-3
@@ -1,13 +1,29 @@
|
||||
PRAGMA foreign_keys = ON;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS households (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
household_id INTEGER,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
email TEXT,
|
||||
display_name TEXT,
|
||||
role TEXT NOT NULL DEFAULT 'member',
|
||||
is_active INTEGER NOT NULL DEFAULT 1,
|
||||
password_hash TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
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 RESTRICT
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_users_email_unique
|
||||
ON users (email)
|
||||
WHERE email IS NOT NULL AND email != '';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS dayparts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
slug TEXT NOT NULL UNIQUE,
|
||||
@@ -17,6 +33,9 @@ CREATE TABLE IF NOT EXISTS dayparts (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS items (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
household_id INTEGER,
|
||||
owner_user_id INTEGER,
|
||||
visibility TEXT NOT NULL DEFAULT 'shared',
|
||||
kind TEXT NOT NULL CHECK (kind IN ('food', 'meal')),
|
||||
name TEXT NOT NULL,
|
||||
category TEXT,
|
||||
@@ -27,6 +46,8 @@ CREATE TABLE IF NOT EXISTS items (
|
||||
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 (created_by) REFERENCES users(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
);
|
||||
@@ -49,12 +70,17 @@ CREATE TABLE IF NOT EXISTS meal_components (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS shopping_entries (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
household_id INTEGER,
|
||||
owner_user_id INTEGER,
|
||||
visibility TEXT NOT NULL DEFAULT 'shared',
|
||||
item_id INTEGER NOT NULL,
|
||||
added_by INTEGER,
|
||||
checked_by INTEGER,
|
||||
is_checked INTEGER NOT NULL DEFAULT 0,
|
||||
added_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
checked_at TEXT,
|
||||
FOREIGN KEY (household_id) REFERENCES households(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (owner_user_id) REFERENCES users(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (added_by) REFERENCES users(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (checked_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
@@ -66,12 +92,17 @@ WHERE is_checked = 0;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS plan_entries (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
household_id INTEGER,
|
||||
owner_user_id INTEGER,
|
||||
visibility TEXT NOT NULL DEFAULT 'shared',
|
||||
plan_date TEXT NOT NULL,
|
||||
daypart_id INTEGER NOT NULL,
|
||||
item_id INTEGER NOT NULL,
|
||||
note TEXT,
|
||||
created_by INTEGER,
|
||||
created_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 (daypart_id) REFERENCES dayparts(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
@@ -80,11 +111,17 @@ CREATE TABLE IF NOT EXISTS plan_entries (
|
||||
CREATE INDEX IF NOT EXISTS idx_items_kind_name
|
||||
ON items (kind, name);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_items_availability_name
|
||||
ON items (availability_state, name);
|
||||
CREATE INDEX IF NOT EXISTS idx_items_household_visibility
|
||||
ON items (household_id, visibility, availability_state);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_item_dayparts_daypart_item
|
||||
ON item_dayparts (daypart_id, item_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_plan_entries_plan_date_daypart
|
||||
ON plan_entries (plan_date, daypart_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_plan_entries_household_visibility
|
||||
ON plan_entries (household_id, visibility, plan_date);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_shopping_entries_household_visibility
|
||||
ON shopping_entries (household_id, visibility, is_checked);
|
||||
|
||||
Reference in New Issue
Block a user