diff --git a/.env.example b/.env.example index b28f6d5..4b20b16 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,7 @@ # Copy to .env. Use a strong URL-safe password (for example: openssl rand -hex 32). POSTGRES_PASSWORD= PUBLIC_ORIGIN=https://tendly.example.com -TENDLY_VERSION=0.0.0-dev +TENDLY_VERSION=v1.0.0 BIND_ADDRESS=127.0.0.1 HTTP_PORT=8080 LOG_LEVEL=info diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bbc01e5..20f3255 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: node-version: '24.19.0' cache: pnpm - run: pnpm install --frozen-lockfile - - run: pnpm exec playwright install --with-deps chromium + - run: pnpm exec playwright install --with-deps chromium webkit - run: bash infrastructure/scripts/test-mailbox.sh - run: docker compose up --build --wait --wait-timeout 180 - run: pnpm test:e2e diff --git a/README.md b/README.md index 51dab0a..3cccb1e 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,17 @@ A self-hosted household task manager: simple daily use, powerful planning when n English/Swedish, mobile and desktop, and portable Docker deployment. Licensed under [AGPL-3.0-or-later](LICENSE). -**Development status:** Stage 3 task capture and planning foundation. This is not yet the Milestone 1 Viable -Product. Accounts, shared entities, task capture, six columns and guarded autosave are implemented; hierarchy, filters and the remaining workflows follow in the approved stages. M1 retains the complete approved -scope; automatic GPS and notifications follow in M2, and integrated cloud backup in M4. +**VP 1.0.0:** household planning with shared views and filters, unlimited subtasks, +recurrence/templates, rich comments, photos/files, archive/Trash and manual recovery. +See the [VP acceptance record](docs/implementation/vp-acceptance.md) for verification. +Automatic GPS and notifications remain v1.1; integrated cloud backup remains v1.3. ## Start here - [Developer setup](docs/development.md) - [Deployment and operations](docs/operations.md) - [Approved delivery stages and acceptance mapping](docs/implementation/delivery-stages.md) +- [VP acceptance record](docs/implementation/vp-acceptance.md) - [Stage 3 review](docs/implementation/stage-3-review.md) - [Stage 2 review](docs/implementation/stage-2-review.md) - [Stage 1 review](docs/implementation/stage-1-review.md) diff --git a/apps/api/drizzle/0004_brainy_spot.sql b/apps/api/drizzle/0004_brainy_spot.sql new file mode 100644 index 0000000..78e04f3 --- /dev/null +++ b/apps/api/drizzle/0004_brainy_spot.sql @@ -0,0 +1,29 @@ +CREATE TABLE "task_dependencies" ( + "blocked_task_id" uuid NOT NULL, + "blocking_task_id" uuid NOT NULL, + CONSTRAINT "task_dependencies_blocked_task_id_blocking_task_id_pk" PRIMARY KEY("blocked_task_id","blocking_task_id") +); +--> statement-breakpoint +CREATE TABLE "task_entity_exclusions" ( + "task_id" uuid NOT NULL, + "entity_id" uuid NOT NULL, + CONSTRAINT "task_entity_exclusions_task_id_entity_id_pk" PRIMARY KEY("task_id","entity_id") +); +--> statement-breakpoint +CREATE TABLE "task_relations" ( + "first_id" uuid NOT NULL, + "second_id" uuid NOT NULL, + CONSTRAINT "task_relations_first_id_second_id_pk" PRIMARY KEY("first_id","second_id") +); +--> statement-breakpoint +ALTER TABLE "tasks" ADD COLUMN "parent_id" uuid;--> statement-breakpoint +ALTER TABLE "tasks" ADD COLUMN "inherit" jsonb DEFAULT '[]'::jsonb NOT NULL;--> statement-breakpoint +ALTER TABLE "task_dependencies" ADD CONSTRAINT "task_dependencies_blocked_task_id_tasks_id_fk" FOREIGN KEY ("blocked_task_id") REFERENCES "public"."tasks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "task_entity_exclusions" ADD CONSTRAINT "task_entity_exclusions_task_id_tasks_id_fk" FOREIGN KEY ("task_id") REFERENCES "public"."tasks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "task_entity_exclusions" ADD CONSTRAINT "task_entity_exclusions_entity_id_planning_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."planning_entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "task_relations" ADD CONSTRAINT "task_relations_first_id_tasks_id_fk" FOREIGN KEY ("first_id") REFERENCES "public"."tasks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "task_relations" ADD CONSTRAINT "task_relations_second_id_tasks_id_fk" FOREIGN KEY ("second_id") REFERENCES "public"."tasks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE INDEX "dependency_blocker_idx" ON "task_dependencies" USING btree ("blocking_task_id");--> statement-breakpoint +CREATE INDEX "relation_second_idx" ON "task_relations" USING btree ("second_id");--> statement-breakpoint +ALTER TABLE "tasks" ADD CONSTRAINT "tasks_parent_id_tasks_id_fk" FOREIGN KEY ("parent_id") REFERENCES "public"."tasks"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint +CREATE INDEX "task_parent_idx" ON "tasks" USING btree ("parent_id"); \ No newline at end of file diff --git a/apps/api/drizzle/0005_giant_lilandra.sql b/apps/api/drizzle/0005_giant_lilandra.sql new file mode 100644 index 0000000..baa11e4 --- /dev/null +++ b/apps/api/drizzle/0005_giant_lilandra.sql @@ -0,0 +1,52 @@ +CREATE TABLE "filter_history" ( + "filter_id" uuid NOT NULL, + "version" integer NOT NULL, + "definition" jsonb NOT NULL, + "actor_id" uuid, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + CONSTRAINT "filter_history_filter_id_version_pk" PRIMARY KEY("filter_id","version") +); +--> statement-breakpoint +CREATE TABLE "saved_filters" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "household_id" uuid NOT NULL, + "name" text NOT NULL, + "icon" text DEFAULT 'list-filter' NOT NULL, + "color" text DEFAULT 'blue' NOT NULL, + "version" integer DEFAULT 1 NOT NULL, + "created_by" uuid, + "builtin" text, + "definition" jsonb NOT NULL +); +--> statement-breakpoint +CREATE TABLE "view_personal" ( + "view_id" uuid NOT NULL, + "user_id" uuid NOT NULL, + "version" integer DEFAULT 1 NOT NULL, + "active_filters" jsonb DEFAULT '[]'::jsonb NOT NULL, + "favorite" integer DEFAULT 0 NOT NULL, + "current_place" uuid, + CONSTRAINT "view_personal_view_id_user_id_pk" PRIMARY KEY("view_id","user_id") +); +--> statement-breakpoint +CREATE TABLE "saved_views" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "household_id" uuid NOT NULL, + "name" text NOT NULL, + "icon" text DEFAULT 'list-filter' NOT NULL, + "color" text DEFAULT 'blue' NOT NULL, + "version" integer DEFAULT 1 NOT NULL, + "created_by" uuid, + "builtin" text, + "definition" jsonb NOT NULL +); +--> statement-breakpoint +ALTER TABLE "filter_history" ADD CONSTRAINT "filter_history_filter_id_saved_filters_id_fk" FOREIGN KEY ("filter_id") REFERENCES "public"."saved_filters"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "filter_history" ADD CONSTRAINT "filter_history_actor_id_users_id_fk" FOREIGN KEY ("actor_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "saved_filters" ADD CONSTRAINT "saved_filters_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "saved_filters" ADD CONSTRAINT "saved_filters_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "view_personal" ADD CONSTRAINT "view_personal_view_id_saved_views_id_fk" FOREIGN KEY ("view_id") REFERENCES "public"."saved_views"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "view_personal" ADD CONSTRAINT "view_personal_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "saved_views" ADD CONSTRAINT "saved_views_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "saved_views" ADD CONSTRAINT "saved_views_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +CREATE UNIQUE INDEX "view_household_builtin_idx" ON "saved_views" USING btree ("household_id","builtin"); \ No newline at end of file diff --git a/apps/api/drizzle/0006_romantic_wind_dancer.sql b/apps/api/drizzle/0006_romantic_wind_dancer.sql new file mode 100644 index 0000000..f1353f4 --- /dev/null +++ b/apps/api/drizzle/0006_romantic_wind_dancer.sql @@ -0,0 +1,28 @@ +CREATE TABLE "lifecycle_settings" ( + "household_id" uuid PRIMARY KEY NOT NULL, + "version" integer DEFAULT 1 NOT NULL, + "archive_days" integer DEFAULT 30, + "trash_days" integer DEFAULT 30 NOT NULL +); +--> statement-breakpoint +CREATE TABLE "task_occurrences" ( + "template_id" uuid NOT NULL, + "date" text NOT NULL, + "root_id" uuid NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + CONSTRAINT "task_occurrences_template_id_date_pk" PRIMARY KEY("template_id","date") +); +--> statement-breakpoint +CREATE TABLE "task_templates" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "household_id" uuid NOT NULL, + "name" text NOT NULL, + "version" integer DEFAULT 1 NOT NULL, + "nodes" jsonb NOT NULL, + "recurrence" jsonb +); +--> statement-breakpoint +ALTER TABLE "tasks" ADD COLUMN "trash_root_id" uuid;--> statement-breakpoint +ALTER TABLE "lifecycle_settings" ADD CONSTRAINT "lifecycle_settings_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "task_occurrences" ADD CONSTRAINT "task_occurrences_template_id_task_templates_id_fk" FOREIGN KEY ("template_id") REFERENCES "public"."task_templates"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "task_templates" ADD CONSTRAINT "task_templates_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action; \ No newline at end of file diff --git a/apps/api/drizzle/0007_cynical_vapor.sql b/apps/api/drizzle/0007_cynical_vapor.sql new file mode 100644 index 0000000..05e8bf6 --- /dev/null +++ b/apps/api/drizzle/0007_cynical_vapor.sql @@ -0,0 +1,30 @@ +CREATE TABLE "task_comments" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "household_id" uuid NOT NULL, + "task_id" uuid NOT NULL, + "author_id" uuid, + "body" text NOT NULL, + "version" integer DEFAULT 1 NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + "updated_at" timestamp with time zone DEFAULT now() NOT NULL +); +--> statement-breakpoint +CREATE TABLE "task_files" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "household_id" uuid NOT NULL, + "task_id" uuid NOT NULL, + "comment_id" uuid, + "name" text NOT NULL, + "mime" text NOT NULL, + "size" integer NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL +); +--> statement-breakpoint +ALTER TABLE "task_comments" ADD CONSTRAINT "task_comments_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "task_comments" ADD CONSTRAINT "task_comments_task_id_tasks_id_fk" FOREIGN KEY ("task_id") REFERENCES "public"."tasks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "task_comments" ADD CONSTRAINT "task_comments_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "task_files" ADD CONSTRAINT "task_files_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "task_files" ADD CONSTRAINT "task_files_task_id_tasks_id_fk" FOREIGN KEY ("task_id") REFERENCES "public"."tasks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "task_files" ADD CONSTRAINT "task_files_comment_id_task_comments_id_fk" FOREIGN KEY ("comment_id") REFERENCES "public"."task_comments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +CREATE INDEX "comment_task_idx" ON "task_comments" USING btree ("task_id","created_at");--> statement-breakpoint +CREATE INDEX "file_task_idx" ON "task_files" USING btree ("task_id"); \ No newline at end of file diff --git a/apps/api/drizzle/0008_perfect_ikaris.sql b/apps/api/drizzle/0008_perfect_ikaris.sql new file mode 100644 index 0000000..aeb05a8 --- /dev/null +++ b/apps/api/drizzle/0008_perfect_ikaris.sql @@ -0,0 +1,37 @@ +ALTER TABLE "households" ADD COLUMN "revision" bigint DEFAULT 0 NOT NULL; +--> statement-breakpoint +CREATE FUNCTION signal_household_change() RETURNS trigger LANGUAGE plpgsql AS $$ +BEGIN + UPDATE households SET revision = revision + 1 WHERE id = COALESCE(NEW.household_id, OLD.household_id); + RETURN NULL; +END; +$$; +--> statement-breakpoint +CREATE TRIGGER tasks_change AFTER INSERT OR UPDATE OR DELETE ON tasks FOR EACH ROW EXECUTE FUNCTION signal_household_change(); +--> statement-breakpoint +CREATE TRIGGER planning_entities_change AFTER INSERT OR UPDATE OR DELETE ON planning_entities FOR EACH ROW EXECUTE FUNCTION signal_household_change(); +--> statement-breakpoint +CREATE TRIGGER saved_filters_change AFTER INSERT OR UPDATE OR DELETE ON saved_filters FOR EACH ROW EXECUTE FUNCTION signal_household_change(); +--> statement-breakpoint +CREATE TRIGGER saved_views_change AFTER INSERT OR UPDATE OR DELETE ON saved_views FOR EACH ROW EXECUTE FUNCTION signal_household_change(); +--> statement-breakpoint +CREATE TRIGGER task_templates_change AFTER INSERT OR UPDATE OR DELETE ON task_templates FOR EACH ROW EXECUTE FUNCTION signal_household_change(); +--> statement-breakpoint +CREATE TRIGGER task_comments_change AFTER INSERT OR UPDATE OR DELETE ON task_comments FOR EACH ROW EXECUTE FUNCTION signal_household_change(); +--> statement-breakpoint +CREATE TRIGGER task_files_change AFTER INSERT OR UPDATE OR DELETE ON task_files FOR EACH ROW EXECUTE FUNCTION signal_household_change(); +--> statement-breakpoint +CREATE TRIGGER memberships_change AFTER INSERT OR UPDATE OR DELETE ON memberships FOR EACH ROW EXECUTE FUNCTION signal_household_change(); +--> statement-breakpoint +CREATE TRIGGER planning_settings_change AFTER INSERT OR UPDATE OR DELETE ON planning_settings FOR EACH ROW EXECUTE FUNCTION signal_household_change(); +--> statement-breakpoint +CREATE TRIGGER lifecycle_settings_change AFTER INSERT OR UPDATE OR DELETE ON lifecycle_settings FOR EACH ROW EXECUTE FUNCTION signal_household_change(); +--> statement-breakpoint +CREATE FUNCTION signal_personal_view_change() RETURNS trigger LANGUAGE plpgsql AS $$ +BEGIN + UPDATE households SET revision = revision + 1 WHERE id = (SELECT household_id FROM saved_views WHERE id = COALESCE(NEW.view_id, OLD.view_id)); + RETURN NULL; +END; +$$; +--> statement-breakpoint +CREATE TRIGGER personal_view_change AFTER INSERT OR UPDATE OR DELETE ON view_personal FOR EACH ROW EXECUTE FUNCTION signal_personal_view_change(); diff --git a/apps/api/drizzle/0009_true_crystal.sql b/apps/api/drizzle/0009_true_crystal.sql new file mode 100644 index 0000000..6464a79 --- /dev/null +++ b/apps/api/drizzle/0009_true_crystal.sql @@ -0,0 +1 @@ +ALTER TABLE "users" ADD COLUMN "avatar" text; \ No newline at end of file diff --git a/apps/api/drizzle/0010_thin_rattler.sql b/apps/api/drizzle/0010_thin_rattler.sql new file mode 100644 index 0000000..51909a0 --- /dev/null +++ b/apps/api/drizzle/0010_thin_rattler.sql @@ -0,0 +1,4 @@ +ALTER TABLE "task_files" DROP CONSTRAINT "task_files_task_id_tasks_id_fk"; +--> statement-breakpoint +ALTER TABLE "task_files" ALTER COLUMN "task_id" DROP NOT NULL;--> statement-breakpoint +ALTER TABLE "task_files" ADD CONSTRAINT "task_files_task_id_tasks_id_fk" FOREIGN KEY ("task_id") REFERENCES "public"."tasks"("id") ON DELETE set null ON UPDATE no action; \ No newline at end of file diff --git a/apps/api/drizzle/meta/0004_snapshot.json b/apps/api/drizzle/meta/0004_snapshot.json new file mode 100644 index 0000000..60dc9fa --- /dev/null +++ b/apps/api/drizzle/meta/0004_snapshot.json @@ -0,0 +1,1570 @@ +{ + "id": "9750cf1d-a796-4c2c-8066-0355dc1edc38", + "prevId": "149e2d32-dc44-4c97-9a08-ca17dbbc0a6c", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.installation": { + "name": "installation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_challenges": { + "name": "auth_challenges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "challenge": { + "name": "challenge", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "binding_hash": { + "name": "binding_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.passkey_credentials": { + "name": "passkey_credentials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counter": { + "name": "counter", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "transports": { + "name": "transports", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credential_user_idx": { + "name": "credential_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "passkey_credentials_user_id_users_id_fk": { + "name": "passkey_credentials_user_id_users_id_fk", + "tableFrom": "passkey_credentials", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.households": { + "name": "households", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memberships": { + "name": "memberships", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "membership_user_idx": { + "name": "membership_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "memberships_household_id_households_id_fk": { + "name": "memberships_household_id_households_id_fk", + "tableFrom": "memberships", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "memberships_user_id_users_id_fk": { + "name": "memberships_user_id_users_id_fk", + "tableFrom": "memberships", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "memberships_household_id_user_id_pk": { + "name": "memberships_household_id_user_id_pk", + "columns": [ + "household_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.security_events": { + "name": "security_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "subject_id": { + "name": "subject_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "security_events_actor_id_users_id_fk": { + "name": "security_events_actor_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "security_events_subject_id_users_id_fk": { + "name": "security_events_subject_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "authenticated_at": { + "name": "authenticated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "session_user_idx": { + "name": "session_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.smtp_settings": { + "name": "smtp_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "encrypted": { + "name": "encrypted", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account_tokens": { + "name": "account_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "purpose": { + "name": "purpose", + "type": "token_purpose", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "verifies_email": { + "name": "verifies_email", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "account_tokens_user_id_users_id_fk": { + "name": "account_tokens_user_id_users_id_fk", + "tableFrom": "account_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "account_tokens_household_id_households_id_fk": { + "name": "account_tokens_household_id_households_id_fk", + "tableFrom": "account_tokens", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified_at": { + "name": "email_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "deployment_admin": { + "name": "deployment_admin", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "language": { + "name": "language", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'en'" + }, + "theme": { + "name": "theme", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_entities": { + "name": "planning_entities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "entity_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'house'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "latitude": { + "name": "latitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "longitude": { + "name": "longitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "radius": { + "name": "radius", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "entity_household_idx": { + "name": "entity_household_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "planning_entities_household_id_households_id_fk": { + "name": "planning_entities_household_id_households_id_fk", + "tableFrom": "planning_entities", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_settings": { + "name": "planning_settings", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "size_thresholds": { + "name": "size_thresholds", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[60,240,480,1440]'::jsonb" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + } + }, + "indexes": {}, + "foreignKeys": { + "planning_settings_household_id_households_id_fk": { + "name": "planning_settings_household_id_households_id_fk", + "tableFrom": "planning_settings", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_activities": { + "name": "task_activities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "fields": { + "name": "fields", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "task_activities_task_id_tasks_id_fk": { + "name": "task_activities_task_id_tasks_id_fk", + "tableFrom": "task_activities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_activities_actor_id_users_id_fk": { + "name": "task_activities_actor_id_users_id_fk", + "tableFrom": "task_activities", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_assignees": { + "name": "task_assignees", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_assignees_task_id_tasks_id_fk": { + "name": "task_assignees_task_id_tasks_id_fk", + "tableFrom": "task_assignees", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_assignees_user_id_users_id_fk": { + "name": "task_assignees_user_id_users_id_fk", + "tableFrom": "task_assignees", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_assignees_task_id_user_id_pk": { + "name": "task_assignees_task_id_user_id_pk", + "columns": [ + "task_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_dependencies": { + "name": "task_dependencies", + "schema": "", + "columns": { + "blocked_task_id": { + "name": "blocked_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "blocking_task_id": { + "name": "blocking_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "dependency_blocker_idx": { + "name": "dependency_blocker_idx", + "columns": [ + { + "expression": "blocking_task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_dependencies_blocked_task_id_tasks_id_fk": { + "name": "task_dependencies_blocked_task_id_tasks_id_fk", + "tableFrom": "task_dependencies", + "tableTo": "tasks", + "columnsFrom": [ + "blocked_task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_dependencies_blocked_task_id_blocking_task_id_pk": { + "name": "task_dependencies_blocked_task_id_blocking_task_id_pk", + "columns": [ + "blocked_task_id", + "blocking_task_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entities": { + "name": "task_entities", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entities_task_id_tasks_id_fk": { + "name": "task_entities_task_id_tasks_id_fk", + "tableFrom": "task_entities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entities_entity_id_planning_entities_id_fk": { + "name": "task_entities_entity_id_planning_entities_id_fk", + "tableFrom": "task_entities", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entities_task_id_entity_id_pk": { + "name": "task_entities_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entity_exclusions": { + "name": "task_entity_exclusions", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entity_exclusions_task_id_tasks_id_fk": { + "name": "task_entity_exclusions_task_id_tasks_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entity_exclusions_entity_id_planning_entities_id_fk": { + "name": "task_entity_exclusions_entity_id_planning_entities_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entity_exclusions_task_id_entity_id_pk": { + "name": "task_entity_exclusions_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_relations": { + "name": "task_relations", + "schema": "", + "columns": { + "first_id": { + "name": "first_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "second_id": { + "name": "second_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "relation_second_idx": { + "name": "relation_second_idx", + "columns": [ + { + "expression": "second_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_relations_first_id_tasks_id_fk": { + "name": "task_relations_first_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "first_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_relations_second_id_tasks_id_fk": { + "name": "task_relations_second_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "second_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_relations_first_id_second_id_pk": { + "name": "task_relations_first_id_second_id_pk", + "columns": [ + "first_id", + "second_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tasks": { + "name": "tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "inherit": { + "name": "inherit", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "status": { + "name": "status", + "type": "task_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'todo'" + }, + "planning_bucket": { + "name": "planning_bucket", + "type": "planning_bucket", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'someday'" + }, + "preceding_column": { + "name": "preceding_column", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "epic_id": { + "name": "epic_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "high": { + "name": "high", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "size": { + "name": "size", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estimate_minutes": { + "name": "estimate_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_date": { + "name": "deadline_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_time": { + "name": "deadline_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "field_versions": { + "name": "field_versions", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_by": { + "name": "completed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "trashed_at": { + "name": "trashed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "task_household_order_idx": { + "name": "task_household_order_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_epic_idx": { + "name": "task_epic_idx", + "columns": [ + { + "expression": "epic_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_parent_idx": { + "name": "task_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tasks_household_id_households_id_fk": { + "name": "tasks_household_id_households_id_fk", + "tableFrom": "tasks", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tasks_parent_id_tasks_id_fk": { + "name": "tasks_parent_id_tasks_id_fk", + "tableFrom": "tasks", + "tableTo": "tasks", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "tasks_epic_id_planning_entities_id_fk": { + "name": "tasks_epic_id_planning_entities_id_fk", + "tableFrom": "tasks", + "tableTo": "planning_entities", + "columnsFrom": [ + "epic_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_created_by_users_id_fk": { + "name": "tasks_created_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_completed_by_users_id_fk": { + "name": "tasks_completed_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "completed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.household_role": { + "name": "household_role", + "schema": "public", + "values": [ + "admin", + "member" + ] + }, + "public.token_purpose": { + "name": "token_purpose", + "schema": "public", + "values": [ + "bootstrap", + "invite", + "recovery", + "verify_email" + ] + }, + "public.planning_bucket": { + "name": "planning_bucket", + "schema": "public", + "values": [ + "someday", + "within_year", + "within_month", + "ready" + ] + }, + "public.entity_kind": { + "name": "entity_kind", + "schema": "public", + "values": [ + "epic", + "place", + "resource", + "tag" + ] + }, + "public.task_status": { + "name": "task_status", + "schema": "public", + "values": [ + "todo", + "in_progress", + "done" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/api/drizzle/meta/0005_snapshot.json b/apps/api/drizzle/meta/0005_snapshot.json new file mode 100644 index 0000000..889a99c --- /dev/null +++ b/apps/api/drizzle/meta/0005_snapshot.json @@ -0,0 +1,1954 @@ +{ + "id": "86d12b51-e8b0-43d4-a572-e0204f553164", + "prevId": "9750cf1d-a796-4c2c-8066-0355dc1edc38", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.installation": { + "name": "installation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_challenges": { + "name": "auth_challenges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "challenge": { + "name": "challenge", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "binding_hash": { + "name": "binding_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.passkey_credentials": { + "name": "passkey_credentials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counter": { + "name": "counter", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "transports": { + "name": "transports", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credential_user_idx": { + "name": "credential_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "passkey_credentials_user_id_users_id_fk": { + "name": "passkey_credentials_user_id_users_id_fk", + "tableFrom": "passkey_credentials", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.households": { + "name": "households", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memberships": { + "name": "memberships", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "membership_user_idx": { + "name": "membership_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "memberships_household_id_households_id_fk": { + "name": "memberships_household_id_households_id_fk", + "tableFrom": "memberships", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "memberships_user_id_users_id_fk": { + "name": "memberships_user_id_users_id_fk", + "tableFrom": "memberships", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "memberships_household_id_user_id_pk": { + "name": "memberships_household_id_user_id_pk", + "columns": [ + "household_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.security_events": { + "name": "security_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "subject_id": { + "name": "subject_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "security_events_actor_id_users_id_fk": { + "name": "security_events_actor_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "security_events_subject_id_users_id_fk": { + "name": "security_events_subject_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "authenticated_at": { + "name": "authenticated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "session_user_idx": { + "name": "session_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.smtp_settings": { + "name": "smtp_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "encrypted": { + "name": "encrypted", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account_tokens": { + "name": "account_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "purpose": { + "name": "purpose", + "type": "token_purpose", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "verifies_email": { + "name": "verifies_email", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "account_tokens_user_id_users_id_fk": { + "name": "account_tokens_user_id_users_id_fk", + "tableFrom": "account_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "account_tokens_household_id_households_id_fk": { + "name": "account_tokens_household_id_households_id_fk", + "tableFrom": "account_tokens", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified_at": { + "name": "email_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "deployment_admin": { + "name": "deployment_admin", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "language": { + "name": "language", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'en'" + }, + "theme": { + "name": "theme", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_entities": { + "name": "planning_entities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "entity_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'house'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "latitude": { + "name": "latitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "longitude": { + "name": "longitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "radius": { + "name": "radius", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "entity_household_idx": { + "name": "entity_household_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "planning_entities_household_id_households_id_fk": { + "name": "planning_entities_household_id_households_id_fk", + "tableFrom": "planning_entities", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_settings": { + "name": "planning_settings", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "size_thresholds": { + "name": "size_thresholds", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[60,240,480,1440]'::jsonb" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + } + }, + "indexes": {}, + "foreignKeys": { + "planning_settings_household_id_households_id_fk": { + "name": "planning_settings_household_id_households_id_fk", + "tableFrom": "planning_settings", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_activities": { + "name": "task_activities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "fields": { + "name": "fields", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "task_activities_task_id_tasks_id_fk": { + "name": "task_activities_task_id_tasks_id_fk", + "tableFrom": "task_activities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_activities_actor_id_users_id_fk": { + "name": "task_activities_actor_id_users_id_fk", + "tableFrom": "task_activities", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_assignees": { + "name": "task_assignees", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_assignees_task_id_tasks_id_fk": { + "name": "task_assignees_task_id_tasks_id_fk", + "tableFrom": "task_assignees", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_assignees_user_id_users_id_fk": { + "name": "task_assignees_user_id_users_id_fk", + "tableFrom": "task_assignees", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_assignees_task_id_user_id_pk": { + "name": "task_assignees_task_id_user_id_pk", + "columns": [ + "task_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_dependencies": { + "name": "task_dependencies", + "schema": "", + "columns": { + "blocked_task_id": { + "name": "blocked_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "blocking_task_id": { + "name": "blocking_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "dependency_blocker_idx": { + "name": "dependency_blocker_idx", + "columns": [ + { + "expression": "blocking_task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_dependencies_blocked_task_id_tasks_id_fk": { + "name": "task_dependencies_blocked_task_id_tasks_id_fk", + "tableFrom": "task_dependencies", + "tableTo": "tasks", + "columnsFrom": [ + "blocked_task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_dependencies_blocked_task_id_blocking_task_id_pk": { + "name": "task_dependencies_blocked_task_id_blocking_task_id_pk", + "columns": [ + "blocked_task_id", + "blocking_task_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entities": { + "name": "task_entities", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entities_task_id_tasks_id_fk": { + "name": "task_entities_task_id_tasks_id_fk", + "tableFrom": "task_entities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entities_entity_id_planning_entities_id_fk": { + "name": "task_entities_entity_id_planning_entities_id_fk", + "tableFrom": "task_entities", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entities_task_id_entity_id_pk": { + "name": "task_entities_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entity_exclusions": { + "name": "task_entity_exclusions", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entity_exclusions_task_id_tasks_id_fk": { + "name": "task_entity_exclusions_task_id_tasks_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entity_exclusions_entity_id_planning_entities_id_fk": { + "name": "task_entity_exclusions_entity_id_planning_entities_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entity_exclusions_task_id_entity_id_pk": { + "name": "task_entity_exclusions_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_relations": { + "name": "task_relations", + "schema": "", + "columns": { + "first_id": { + "name": "first_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "second_id": { + "name": "second_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "relation_second_idx": { + "name": "relation_second_idx", + "columns": [ + { + "expression": "second_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_relations_first_id_tasks_id_fk": { + "name": "task_relations_first_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "first_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_relations_second_id_tasks_id_fk": { + "name": "task_relations_second_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "second_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_relations_first_id_second_id_pk": { + "name": "task_relations_first_id_second_id_pk", + "columns": [ + "first_id", + "second_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tasks": { + "name": "tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "inherit": { + "name": "inherit", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "status": { + "name": "status", + "type": "task_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'todo'" + }, + "planning_bucket": { + "name": "planning_bucket", + "type": "planning_bucket", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'someday'" + }, + "preceding_column": { + "name": "preceding_column", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "epic_id": { + "name": "epic_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "high": { + "name": "high", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "size": { + "name": "size", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estimate_minutes": { + "name": "estimate_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_date": { + "name": "deadline_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_time": { + "name": "deadline_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "field_versions": { + "name": "field_versions", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_by": { + "name": "completed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "trashed_at": { + "name": "trashed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "task_household_order_idx": { + "name": "task_household_order_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_epic_idx": { + "name": "task_epic_idx", + "columns": [ + { + "expression": "epic_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_parent_idx": { + "name": "task_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tasks_household_id_households_id_fk": { + "name": "tasks_household_id_households_id_fk", + "tableFrom": "tasks", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tasks_parent_id_tasks_id_fk": { + "name": "tasks_parent_id_tasks_id_fk", + "tableFrom": "tasks", + "tableTo": "tasks", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "tasks_epic_id_planning_entities_id_fk": { + "name": "tasks_epic_id_planning_entities_id_fk", + "tableFrom": "tasks", + "tableTo": "planning_entities", + "columnsFrom": [ + "epic_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_created_by_users_id_fk": { + "name": "tasks_created_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_completed_by_users_id_fk": { + "name": "tasks_completed_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "completed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.filter_history": { + "name": "filter_history", + "schema": "", + "columns": { + "filter_id": { + "name": "filter_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "filter_history_filter_id_saved_filters_id_fk": { + "name": "filter_history_filter_id_saved_filters_id_fk", + "tableFrom": "filter_history", + "tableTo": "saved_filters", + "columnsFrom": [ + "filter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "filter_history_actor_id_users_id_fk": { + "name": "filter_history_actor_id_users_id_fk", + "tableFrom": "filter_history", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "filter_history_filter_id_version_pk": { + "name": "filter_history_filter_id_version_pk", + "columns": [ + "filter_id", + "version" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_filters": { + "name": "saved_filters", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'list-filter'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "saved_filters_household_id_households_id_fk": { + "name": "saved_filters_household_id_households_id_fk", + "tableFrom": "saved_filters", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "saved_filters_created_by_users_id_fk": { + "name": "saved_filters_created_by_users_id_fk", + "tableFrom": "saved_filters", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.view_personal": { + "name": "view_personal", + "schema": "", + "columns": { + "view_id": { + "name": "view_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "active_filters": { + "name": "active_filters", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "favorite": { + "name": "favorite", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "current_place": { + "name": "current_place", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "view_personal_view_id_saved_views_id_fk": { + "name": "view_personal_view_id_saved_views_id_fk", + "tableFrom": "view_personal", + "tableTo": "saved_views", + "columnsFrom": [ + "view_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "view_personal_user_id_users_id_fk": { + "name": "view_personal_user_id_users_id_fk", + "tableFrom": "view_personal", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "view_personal_view_id_user_id_pk": { + "name": "view_personal_view_id_user_id_pk", + "columns": [ + "view_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_views": { + "name": "saved_views", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'list-filter'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "view_household_builtin_idx": { + "name": "view_household_builtin_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "builtin", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "saved_views_household_id_households_id_fk": { + "name": "saved_views_household_id_households_id_fk", + "tableFrom": "saved_views", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "saved_views_created_by_users_id_fk": { + "name": "saved_views_created_by_users_id_fk", + "tableFrom": "saved_views", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.household_role": { + "name": "household_role", + "schema": "public", + "values": [ + "admin", + "member" + ] + }, + "public.token_purpose": { + "name": "token_purpose", + "schema": "public", + "values": [ + "bootstrap", + "invite", + "recovery", + "verify_email" + ] + }, + "public.planning_bucket": { + "name": "planning_bucket", + "schema": "public", + "values": [ + "someday", + "within_year", + "within_month", + "ready" + ] + }, + "public.entity_kind": { + "name": "entity_kind", + "schema": "public", + "values": [ + "epic", + "place", + "resource", + "tag" + ] + }, + "public.task_status": { + "name": "task_status", + "schema": "public", + "values": [ + "todo", + "in_progress", + "done" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/api/drizzle/meta/0006_snapshot.json b/apps/api/drizzle/meta/0006_snapshot.json new file mode 100644 index 0000000..e3881dc --- /dev/null +++ b/apps/api/drizzle/meta/0006_snapshot.json @@ -0,0 +1,2139 @@ +{ + "id": "e1b5af52-be5b-4042-9c75-37bf35273d5c", + "prevId": "86d12b51-e8b0-43d4-a572-e0204f553164", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.installation": { + "name": "installation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_challenges": { + "name": "auth_challenges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "challenge": { + "name": "challenge", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "binding_hash": { + "name": "binding_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.passkey_credentials": { + "name": "passkey_credentials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counter": { + "name": "counter", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "transports": { + "name": "transports", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credential_user_idx": { + "name": "credential_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "passkey_credentials_user_id_users_id_fk": { + "name": "passkey_credentials_user_id_users_id_fk", + "tableFrom": "passkey_credentials", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.households": { + "name": "households", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memberships": { + "name": "memberships", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "membership_user_idx": { + "name": "membership_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "memberships_household_id_households_id_fk": { + "name": "memberships_household_id_households_id_fk", + "tableFrom": "memberships", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "memberships_user_id_users_id_fk": { + "name": "memberships_user_id_users_id_fk", + "tableFrom": "memberships", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "memberships_household_id_user_id_pk": { + "name": "memberships_household_id_user_id_pk", + "columns": [ + "household_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.security_events": { + "name": "security_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "subject_id": { + "name": "subject_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "security_events_actor_id_users_id_fk": { + "name": "security_events_actor_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "security_events_subject_id_users_id_fk": { + "name": "security_events_subject_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "authenticated_at": { + "name": "authenticated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "session_user_idx": { + "name": "session_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.smtp_settings": { + "name": "smtp_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "encrypted": { + "name": "encrypted", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account_tokens": { + "name": "account_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "purpose": { + "name": "purpose", + "type": "token_purpose", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "verifies_email": { + "name": "verifies_email", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "account_tokens_user_id_users_id_fk": { + "name": "account_tokens_user_id_users_id_fk", + "tableFrom": "account_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "account_tokens_household_id_households_id_fk": { + "name": "account_tokens_household_id_households_id_fk", + "tableFrom": "account_tokens", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified_at": { + "name": "email_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "deployment_admin": { + "name": "deployment_admin", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "language": { + "name": "language", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'en'" + }, + "theme": { + "name": "theme", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_entities": { + "name": "planning_entities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "entity_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'house'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "latitude": { + "name": "latitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "longitude": { + "name": "longitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "radius": { + "name": "radius", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "entity_household_idx": { + "name": "entity_household_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "planning_entities_household_id_households_id_fk": { + "name": "planning_entities_household_id_households_id_fk", + "tableFrom": "planning_entities", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_settings": { + "name": "planning_settings", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "size_thresholds": { + "name": "size_thresholds", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[60,240,480,1440]'::jsonb" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + } + }, + "indexes": {}, + "foreignKeys": { + "planning_settings_household_id_households_id_fk": { + "name": "planning_settings_household_id_households_id_fk", + "tableFrom": "planning_settings", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_activities": { + "name": "task_activities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "fields": { + "name": "fields", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "task_activities_task_id_tasks_id_fk": { + "name": "task_activities_task_id_tasks_id_fk", + "tableFrom": "task_activities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_activities_actor_id_users_id_fk": { + "name": "task_activities_actor_id_users_id_fk", + "tableFrom": "task_activities", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_assignees": { + "name": "task_assignees", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_assignees_task_id_tasks_id_fk": { + "name": "task_assignees_task_id_tasks_id_fk", + "tableFrom": "task_assignees", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_assignees_user_id_users_id_fk": { + "name": "task_assignees_user_id_users_id_fk", + "tableFrom": "task_assignees", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_assignees_task_id_user_id_pk": { + "name": "task_assignees_task_id_user_id_pk", + "columns": [ + "task_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_dependencies": { + "name": "task_dependencies", + "schema": "", + "columns": { + "blocked_task_id": { + "name": "blocked_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "blocking_task_id": { + "name": "blocking_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "dependency_blocker_idx": { + "name": "dependency_blocker_idx", + "columns": [ + { + "expression": "blocking_task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_dependencies_blocked_task_id_tasks_id_fk": { + "name": "task_dependencies_blocked_task_id_tasks_id_fk", + "tableFrom": "task_dependencies", + "tableTo": "tasks", + "columnsFrom": [ + "blocked_task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_dependencies_blocked_task_id_blocking_task_id_pk": { + "name": "task_dependencies_blocked_task_id_blocking_task_id_pk", + "columns": [ + "blocked_task_id", + "blocking_task_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entities": { + "name": "task_entities", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entities_task_id_tasks_id_fk": { + "name": "task_entities_task_id_tasks_id_fk", + "tableFrom": "task_entities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entities_entity_id_planning_entities_id_fk": { + "name": "task_entities_entity_id_planning_entities_id_fk", + "tableFrom": "task_entities", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entities_task_id_entity_id_pk": { + "name": "task_entities_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entity_exclusions": { + "name": "task_entity_exclusions", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entity_exclusions_task_id_tasks_id_fk": { + "name": "task_entity_exclusions_task_id_tasks_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entity_exclusions_entity_id_planning_entities_id_fk": { + "name": "task_entity_exclusions_entity_id_planning_entities_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entity_exclusions_task_id_entity_id_pk": { + "name": "task_entity_exclusions_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_relations": { + "name": "task_relations", + "schema": "", + "columns": { + "first_id": { + "name": "first_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "second_id": { + "name": "second_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "relation_second_idx": { + "name": "relation_second_idx", + "columns": [ + { + "expression": "second_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_relations_first_id_tasks_id_fk": { + "name": "task_relations_first_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "first_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_relations_second_id_tasks_id_fk": { + "name": "task_relations_second_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "second_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_relations_first_id_second_id_pk": { + "name": "task_relations_first_id_second_id_pk", + "columns": [ + "first_id", + "second_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tasks": { + "name": "tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "inherit": { + "name": "inherit", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "status": { + "name": "status", + "type": "task_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'todo'" + }, + "planning_bucket": { + "name": "planning_bucket", + "type": "planning_bucket", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'someday'" + }, + "preceding_column": { + "name": "preceding_column", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "epic_id": { + "name": "epic_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "high": { + "name": "high", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "size": { + "name": "size", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estimate_minutes": { + "name": "estimate_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_date": { + "name": "deadline_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_time": { + "name": "deadline_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "field_versions": { + "name": "field_versions", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_by": { + "name": "completed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "trash_root_id": { + "name": "trash_root_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "trashed_at": { + "name": "trashed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "task_household_order_idx": { + "name": "task_household_order_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_epic_idx": { + "name": "task_epic_idx", + "columns": [ + { + "expression": "epic_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_parent_idx": { + "name": "task_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tasks_household_id_households_id_fk": { + "name": "tasks_household_id_households_id_fk", + "tableFrom": "tasks", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tasks_parent_id_tasks_id_fk": { + "name": "tasks_parent_id_tasks_id_fk", + "tableFrom": "tasks", + "tableTo": "tasks", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "tasks_epic_id_planning_entities_id_fk": { + "name": "tasks_epic_id_planning_entities_id_fk", + "tableFrom": "tasks", + "tableTo": "planning_entities", + "columnsFrom": [ + "epic_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_created_by_users_id_fk": { + "name": "tasks_created_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_completed_by_users_id_fk": { + "name": "tasks_completed_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "completed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.filter_history": { + "name": "filter_history", + "schema": "", + "columns": { + "filter_id": { + "name": "filter_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "filter_history_filter_id_saved_filters_id_fk": { + "name": "filter_history_filter_id_saved_filters_id_fk", + "tableFrom": "filter_history", + "tableTo": "saved_filters", + "columnsFrom": [ + "filter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "filter_history_actor_id_users_id_fk": { + "name": "filter_history_actor_id_users_id_fk", + "tableFrom": "filter_history", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "filter_history_filter_id_version_pk": { + "name": "filter_history_filter_id_version_pk", + "columns": [ + "filter_id", + "version" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_filters": { + "name": "saved_filters", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'list-filter'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "saved_filters_household_id_households_id_fk": { + "name": "saved_filters_household_id_households_id_fk", + "tableFrom": "saved_filters", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "saved_filters_created_by_users_id_fk": { + "name": "saved_filters_created_by_users_id_fk", + "tableFrom": "saved_filters", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.view_personal": { + "name": "view_personal", + "schema": "", + "columns": { + "view_id": { + "name": "view_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "active_filters": { + "name": "active_filters", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "favorite": { + "name": "favorite", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "current_place": { + "name": "current_place", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "view_personal_view_id_saved_views_id_fk": { + "name": "view_personal_view_id_saved_views_id_fk", + "tableFrom": "view_personal", + "tableTo": "saved_views", + "columnsFrom": [ + "view_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "view_personal_user_id_users_id_fk": { + "name": "view_personal_user_id_users_id_fk", + "tableFrom": "view_personal", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "view_personal_view_id_user_id_pk": { + "name": "view_personal_view_id_user_id_pk", + "columns": [ + "view_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_views": { + "name": "saved_views", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'list-filter'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "view_household_builtin_idx": { + "name": "view_household_builtin_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "builtin", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "saved_views_household_id_households_id_fk": { + "name": "saved_views_household_id_households_id_fk", + "tableFrom": "saved_views", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "saved_views_created_by_users_id_fk": { + "name": "saved_views_created_by_users_id_fk", + "tableFrom": "saved_views", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.lifecycle_settings": { + "name": "lifecycle_settings", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "archive_days": { + "name": "archive_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 30 + }, + "trash_days": { + "name": "trash_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 30 + } + }, + "indexes": {}, + "foreignKeys": { + "lifecycle_settings_household_id_households_id_fk": { + "name": "lifecycle_settings_household_id_households_id_fk", + "tableFrom": "lifecycle_settings", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_occurrences": { + "name": "task_occurrences", + "schema": "", + "columns": { + "template_id": { + "name": "template_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "root_id": { + "name": "root_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "task_occurrences_template_id_task_templates_id_fk": { + "name": "task_occurrences_template_id_task_templates_id_fk", + "tableFrom": "task_occurrences", + "tableTo": "task_templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_occurrences_template_id_date_pk": { + "name": "task_occurrences_template_id_date_pk", + "columns": [ + "template_id", + "date" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_templates": { + "name": "task_templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "nodes": { + "name": "nodes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "recurrence": { + "name": "recurrence", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "task_templates_household_id_households_id_fk": { + "name": "task_templates_household_id_households_id_fk", + "tableFrom": "task_templates", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.household_role": { + "name": "household_role", + "schema": "public", + "values": [ + "admin", + "member" + ] + }, + "public.token_purpose": { + "name": "token_purpose", + "schema": "public", + "values": [ + "bootstrap", + "invite", + "recovery", + "verify_email" + ] + }, + "public.planning_bucket": { + "name": "planning_bucket", + "schema": "public", + "values": [ + "someday", + "within_year", + "within_month", + "ready" + ] + }, + "public.entity_kind": { + "name": "entity_kind", + "schema": "public", + "values": [ + "epic", + "place", + "resource", + "tag" + ] + }, + "public.task_status": { + "name": "task_status", + "schema": "public", + "values": [ + "todo", + "in_progress", + "done" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/api/drizzle/meta/0007_snapshot.json b/apps/api/drizzle/meta/0007_snapshot.json new file mode 100644 index 0000000..2fefbbe --- /dev/null +++ b/apps/api/drizzle/meta/0007_snapshot.json @@ -0,0 +1,2385 @@ +{ + "id": "344ceb7b-2ed8-4b3e-81ad-98aaaaedac26", + "prevId": "e1b5af52-be5b-4042-9c75-37bf35273d5c", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.installation": { + "name": "installation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_challenges": { + "name": "auth_challenges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "challenge": { + "name": "challenge", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "binding_hash": { + "name": "binding_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.passkey_credentials": { + "name": "passkey_credentials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counter": { + "name": "counter", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "transports": { + "name": "transports", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credential_user_idx": { + "name": "credential_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "passkey_credentials_user_id_users_id_fk": { + "name": "passkey_credentials_user_id_users_id_fk", + "tableFrom": "passkey_credentials", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.households": { + "name": "households", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memberships": { + "name": "memberships", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "membership_user_idx": { + "name": "membership_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "memberships_household_id_households_id_fk": { + "name": "memberships_household_id_households_id_fk", + "tableFrom": "memberships", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "memberships_user_id_users_id_fk": { + "name": "memberships_user_id_users_id_fk", + "tableFrom": "memberships", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "memberships_household_id_user_id_pk": { + "name": "memberships_household_id_user_id_pk", + "columns": [ + "household_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.security_events": { + "name": "security_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "subject_id": { + "name": "subject_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "security_events_actor_id_users_id_fk": { + "name": "security_events_actor_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "security_events_subject_id_users_id_fk": { + "name": "security_events_subject_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "authenticated_at": { + "name": "authenticated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "session_user_idx": { + "name": "session_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.smtp_settings": { + "name": "smtp_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "encrypted": { + "name": "encrypted", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account_tokens": { + "name": "account_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "purpose": { + "name": "purpose", + "type": "token_purpose", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "verifies_email": { + "name": "verifies_email", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "account_tokens_user_id_users_id_fk": { + "name": "account_tokens_user_id_users_id_fk", + "tableFrom": "account_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "account_tokens_household_id_households_id_fk": { + "name": "account_tokens_household_id_households_id_fk", + "tableFrom": "account_tokens", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified_at": { + "name": "email_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "deployment_admin": { + "name": "deployment_admin", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "language": { + "name": "language", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'en'" + }, + "theme": { + "name": "theme", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_entities": { + "name": "planning_entities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "entity_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'house'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "latitude": { + "name": "latitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "longitude": { + "name": "longitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "radius": { + "name": "radius", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "entity_household_idx": { + "name": "entity_household_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "planning_entities_household_id_households_id_fk": { + "name": "planning_entities_household_id_households_id_fk", + "tableFrom": "planning_entities", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_settings": { + "name": "planning_settings", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "size_thresholds": { + "name": "size_thresholds", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[60,240,480,1440]'::jsonb" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + } + }, + "indexes": {}, + "foreignKeys": { + "planning_settings_household_id_households_id_fk": { + "name": "planning_settings_household_id_households_id_fk", + "tableFrom": "planning_settings", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_activities": { + "name": "task_activities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "fields": { + "name": "fields", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "task_activities_task_id_tasks_id_fk": { + "name": "task_activities_task_id_tasks_id_fk", + "tableFrom": "task_activities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_activities_actor_id_users_id_fk": { + "name": "task_activities_actor_id_users_id_fk", + "tableFrom": "task_activities", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_assignees": { + "name": "task_assignees", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_assignees_task_id_tasks_id_fk": { + "name": "task_assignees_task_id_tasks_id_fk", + "tableFrom": "task_assignees", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_assignees_user_id_users_id_fk": { + "name": "task_assignees_user_id_users_id_fk", + "tableFrom": "task_assignees", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_assignees_task_id_user_id_pk": { + "name": "task_assignees_task_id_user_id_pk", + "columns": [ + "task_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_dependencies": { + "name": "task_dependencies", + "schema": "", + "columns": { + "blocked_task_id": { + "name": "blocked_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "blocking_task_id": { + "name": "blocking_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "dependency_blocker_idx": { + "name": "dependency_blocker_idx", + "columns": [ + { + "expression": "blocking_task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_dependencies_blocked_task_id_tasks_id_fk": { + "name": "task_dependencies_blocked_task_id_tasks_id_fk", + "tableFrom": "task_dependencies", + "tableTo": "tasks", + "columnsFrom": [ + "blocked_task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_dependencies_blocked_task_id_blocking_task_id_pk": { + "name": "task_dependencies_blocked_task_id_blocking_task_id_pk", + "columns": [ + "blocked_task_id", + "blocking_task_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entities": { + "name": "task_entities", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entities_task_id_tasks_id_fk": { + "name": "task_entities_task_id_tasks_id_fk", + "tableFrom": "task_entities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entities_entity_id_planning_entities_id_fk": { + "name": "task_entities_entity_id_planning_entities_id_fk", + "tableFrom": "task_entities", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entities_task_id_entity_id_pk": { + "name": "task_entities_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entity_exclusions": { + "name": "task_entity_exclusions", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entity_exclusions_task_id_tasks_id_fk": { + "name": "task_entity_exclusions_task_id_tasks_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entity_exclusions_entity_id_planning_entities_id_fk": { + "name": "task_entity_exclusions_entity_id_planning_entities_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entity_exclusions_task_id_entity_id_pk": { + "name": "task_entity_exclusions_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_relations": { + "name": "task_relations", + "schema": "", + "columns": { + "first_id": { + "name": "first_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "second_id": { + "name": "second_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "relation_second_idx": { + "name": "relation_second_idx", + "columns": [ + { + "expression": "second_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_relations_first_id_tasks_id_fk": { + "name": "task_relations_first_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "first_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_relations_second_id_tasks_id_fk": { + "name": "task_relations_second_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "second_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_relations_first_id_second_id_pk": { + "name": "task_relations_first_id_second_id_pk", + "columns": [ + "first_id", + "second_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tasks": { + "name": "tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "inherit": { + "name": "inherit", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "status": { + "name": "status", + "type": "task_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'todo'" + }, + "planning_bucket": { + "name": "planning_bucket", + "type": "planning_bucket", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'someday'" + }, + "preceding_column": { + "name": "preceding_column", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "epic_id": { + "name": "epic_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "high": { + "name": "high", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "size": { + "name": "size", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estimate_minutes": { + "name": "estimate_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_date": { + "name": "deadline_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_time": { + "name": "deadline_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "field_versions": { + "name": "field_versions", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_by": { + "name": "completed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "trash_root_id": { + "name": "trash_root_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "trashed_at": { + "name": "trashed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "task_household_order_idx": { + "name": "task_household_order_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_epic_idx": { + "name": "task_epic_idx", + "columns": [ + { + "expression": "epic_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_parent_idx": { + "name": "task_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tasks_household_id_households_id_fk": { + "name": "tasks_household_id_households_id_fk", + "tableFrom": "tasks", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tasks_parent_id_tasks_id_fk": { + "name": "tasks_parent_id_tasks_id_fk", + "tableFrom": "tasks", + "tableTo": "tasks", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "tasks_epic_id_planning_entities_id_fk": { + "name": "tasks_epic_id_planning_entities_id_fk", + "tableFrom": "tasks", + "tableTo": "planning_entities", + "columnsFrom": [ + "epic_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_created_by_users_id_fk": { + "name": "tasks_created_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_completed_by_users_id_fk": { + "name": "tasks_completed_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "completed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.filter_history": { + "name": "filter_history", + "schema": "", + "columns": { + "filter_id": { + "name": "filter_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "filter_history_filter_id_saved_filters_id_fk": { + "name": "filter_history_filter_id_saved_filters_id_fk", + "tableFrom": "filter_history", + "tableTo": "saved_filters", + "columnsFrom": [ + "filter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "filter_history_actor_id_users_id_fk": { + "name": "filter_history_actor_id_users_id_fk", + "tableFrom": "filter_history", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "filter_history_filter_id_version_pk": { + "name": "filter_history_filter_id_version_pk", + "columns": [ + "filter_id", + "version" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_filters": { + "name": "saved_filters", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'list-filter'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "saved_filters_household_id_households_id_fk": { + "name": "saved_filters_household_id_households_id_fk", + "tableFrom": "saved_filters", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "saved_filters_created_by_users_id_fk": { + "name": "saved_filters_created_by_users_id_fk", + "tableFrom": "saved_filters", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.view_personal": { + "name": "view_personal", + "schema": "", + "columns": { + "view_id": { + "name": "view_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "active_filters": { + "name": "active_filters", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "favorite": { + "name": "favorite", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "current_place": { + "name": "current_place", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "view_personal_view_id_saved_views_id_fk": { + "name": "view_personal_view_id_saved_views_id_fk", + "tableFrom": "view_personal", + "tableTo": "saved_views", + "columnsFrom": [ + "view_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "view_personal_user_id_users_id_fk": { + "name": "view_personal_user_id_users_id_fk", + "tableFrom": "view_personal", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "view_personal_view_id_user_id_pk": { + "name": "view_personal_view_id_user_id_pk", + "columns": [ + "view_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_views": { + "name": "saved_views", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'list-filter'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "view_household_builtin_idx": { + "name": "view_household_builtin_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "builtin", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "saved_views_household_id_households_id_fk": { + "name": "saved_views_household_id_households_id_fk", + "tableFrom": "saved_views", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "saved_views_created_by_users_id_fk": { + "name": "saved_views_created_by_users_id_fk", + "tableFrom": "saved_views", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.lifecycle_settings": { + "name": "lifecycle_settings", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "archive_days": { + "name": "archive_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 30 + }, + "trash_days": { + "name": "trash_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 30 + } + }, + "indexes": {}, + "foreignKeys": { + "lifecycle_settings_household_id_households_id_fk": { + "name": "lifecycle_settings_household_id_households_id_fk", + "tableFrom": "lifecycle_settings", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_occurrences": { + "name": "task_occurrences", + "schema": "", + "columns": { + "template_id": { + "name": "template_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "root_id": { + "name": "root_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "task_occurrences_template_id_task_templates_id_fk": { + "name": "task_occurrences_template_id_task_templates_id_fk", + "tableFrom": "task_occurrences", + "tableTo": "task_templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_occurrences_template_id_date_pk": { + "name": "task_occurrences_template_id_date_pk", + "columns": [ + "template_id", + "date" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_templates": { + "name": "task_templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "nodes": { + "name": "nodes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "recurrence": { + "name": "recurrence", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "task_templates_household_id_households_id_fk": { + "name": "task_templates_household_id_households_id_fk", + "tableFrom": "task_templates", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_comments": { + "name": "task_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "comment_task_idx": { + "name": "comment_task_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_comments_household_id_households_id_fk": { + "name": "task_comments_household_id_households_id_fk", + "tableFrom": "task_comments", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_comments_task_id_tasks_id_fk": { + "name": "task_comments_task_id_tasks_id_fk", + "tableFrom": "task_comments", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_comments_author_id_users_id_fk": { + "name": "task_comments_author_id_users_id_fk", + "tableFrom": "task_comments", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_files": { + "name": "task_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "comment_id": { + "name": "comment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "file_task_idx": { + "name": "file_task_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_files_household_id_households_id_fk": { + "name": "task_files_household_id_households_id_fk", + "tableFrom": "task_files", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_files_task_id_tasks_id_fk": { + "name": "task_files_task_id_tasks_id_fk", + "tableFrom": "task_files", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_files_comment_id_task_comments_id_fk": { + "name": "task_files_comment_id_task_comments_id_fk", + "tableFrom": "task_files", + "tableTo": "task_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.household_role": { + "name": "household_role", + "schema": "public", + "values": [ + "admin", + "member" + ] + }, + "public.token_purpose": { + "name": "token_purpose", + "schema": "public", + "values": [ + "bootstrap", + "invite", + "recovery", + "verify_email" + ] + }, + "public.planning_bucket": { + "name": "planning_bucket", + "schema": "public", + "values": [ + "someday", + "within_year", + "within_month", + "ready" + ] + }, + "public.entity_kind": { + "name": "entity_kind", + "schema": "public", + "values": [ + "epic", + "place", + "resource", + "tag" + ] + }, + "public.task_status": { + "name": "task_status", + "schema": "public", + "values": [ + "todo", + "in_progress", + "done" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/api/drizzle/meta/0008_snapshot.json b/apps/api/drizzle/meta/0008_snapshot.json new file mode 100644 index 0000000..ea1b99a --- /dev/null +++ b/apps/api/drizzle/meta/0008_snapshot.json @@ -0,0 +1,2392 @@ +{ + "id": "8a86497d-3802-4225-bcf8-5cde056f3a52", + "prevId": "344ceb7b-2ed8-4b3e-81ad-98aaaaedac26", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.installation": { + "name": "installation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_challenges": { + "name": "auth_challenges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "challenge": { + "name": "challenge", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "binding_hash": { + "name": "binding_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.passkey_credentials": { + "name": "passkey_credentials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counter": { + "name": "counter", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "transports": { + "name": "transports", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credential_user_idx": { + "name": "credential_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "passkey_credentials_user_id_users_id_fk": { + "name": "passkey_credentials_user_id_users_id_fk", + "tableFrom": "passkey_credentials", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.households": { + "name": "households", + "schema": "", + "columns": { + "revision": { + "name": "revision", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memberships": { + "name": "memberships", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "membership_user_idx": { + "name": "membership_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "memberships_household_id_households_id_fk": { + "name": "memberships_household_id_households_id_fk", + "tableFrom": "memberships", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "memberships_user_id_users_id_fk": { + "name": "memberships_user_id_users_id_fk", + "tableFrom": "memberships", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "memberships_household_id_user_id_pk": { + "name": "memberships_household_id_user_id_pk", + "columns": [ + "household_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.security_events": { + "name": "security_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "subject_id": { + "name": "subject_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "security_events_actor_id_users_id_fk": { + "name": "security_events_actor_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "security_events_subject_id_users_id_fk": { + "name": "security_events_subject_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "authenticated_at": { + "name": "authenticated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "session_user_idx": { + "name": "session_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.smtp_settings": { + "name": "smtp_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "encrypted": { + "name": "encrypted", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account_tokens": { + "name": "account_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "purpose": { + "name": "purpose", + "type": "token_purpose", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "verifies_email": { + "name": "verifies_email", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "account_tokens_user_id_users_id_fk": { + "name": "account_tokens_user_id_users_id_fk", + "tableFrom": "account_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "account_tokens_household_id_households_id_fk": { + "name": "account_tokens_household_id_households_id_fk", + "tableFrom": "account_tokens", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified_at": { + "name": "email_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "deployment_admin": { + "name": "deployment_admin", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "language": { + "name": "language", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'en'" + }, + "theme": { + "name": "theme", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_entities": { + "name": "planning_entities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "entity_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'house'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "latitude": { + "name": "latitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "longitude": { + "name": "longitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "radius": { + "name": "radius", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "entity_household_idx": { + "name": "entity_household_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "planning_entities_household_id_households_id_fk": { + "name": "planning_entities_household_id_households_id_fk", + "tableFrom": "planning_entities", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_settings": { + "name": "planning_settings", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "size_thresholds": { + "name": "size_thresholds", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[60,240,480,1440]'::jsonb" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + } + }, + "indexes": {}, + "foreignKeys": { + "planning_settings_household_id_households_id_fk": { + "name": "planning_settings_household_id_households_id_fk", + "tableFrom": "planning_settings", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_activities": { + "name": "task_activities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "fields": { + "name": "fields", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "task_activities_task_id_tasks_id_fk": { + "name": "task_activities_task_id_tasks_id_fk", + "tableFrom": "task_activities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_activities_actor_id_users_id_fk": { + "name": "task_activities_actor_id_users_id_fk", + "tableFrom": "task_activities", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_assignees": { + "name": "task_assignees", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_assignees_task_id_tasks_id_fk": { + "name": "task_assignees_task_id_tasks_id_fk", + "tableFrom": "task_assignees", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_assignees_user_id_users_id_fk": { + "name": "task_assignees_user_id_users_id_fk", + "tableFrom": "task_assignees", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_assignees_task_id_user_id_pk": { + "name": "task_assignees_task_id_user_id_pk", + "columns": [ + "task_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_dependencies": { + "name": "task_dependencies", + "schema": "", + "columns": { + "blocked_task_id": { + "name": "blocked_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "blocking_task_id": { + "name": "blocking_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "dependency_blocker_idx": { + "name": "dependency_blocker_idx", + "columns": [ + { + "expression": "blocking_task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_dependencies_blocked_task_id_tasks_id_fk": { + "name": "task_dependencies_blocked_task_id_tasks_id_fk", + "tableFrom": "task_dependencies", + "tableTo": "tasks", + "columnsFrom": [ + "blocked_task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_dependencies_blocked_task_id_blocking_task_id_pk": { + "name": "task_dependencies_blocked_task_id_blocking_task_id_pk", + "columns": [ + "blocked_task_id", + "blocking_task_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entities": { + "name": "task_entities", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entities_task_id_tasks_id_fk": { + "name": "task_entities_task_id_tasks_id_fk", + "tableFrom": "task_entities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entities_entity_id_planning_entities_id_fk": { + "name": "task_entities_entity_id_planning_entities_id_fk", + "tableFrom": "task_entities", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entities_task_id_entity_id_pk": { + "name": "task_entities_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entity_exclusions": { + "name": "task_entity_exclusions", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entity_exclusions_task_id_tasks_id_fk": { + "name": "task_entity_exclusions_task_id_tasks_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entity_exclusions_entity_id_planning_entities_id_fk": { + "name": "task_entity_exclusions_entity_id_planning_entities_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entity_exclusions_task_id_entity_id_pk": { + "name": "task_entity_exclusions_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_relations": { + "name": "task_relations", + "schema": "", + "columns": { + "first_id": { + "name": "first_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "second_id": { + "name": "second_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "relation_second_idx": { + "name": "relation_second_idx", + "columns": [ + { + "expression": "second_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_relations_first_id_tasks_id_fk": { + "name": "task_relations_first_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "first_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_relations_second_id_tasks_id_fk": { + "name": "task_relations_second_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "second_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_relations_first_id_second_id_pk": { + "name": "task_relations_first_id_second_id_pk", + "columns": [ + "first_id", + "second_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tasks": { + "name": "tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "inherit": { + "name": "inherit", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "status": { + "name": "status", + "type": "task_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'todo'" + }, + "planning_bucket": { + "name": "planning_bucket", + "type": "planning_bucket", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'someday'" + }, + "preceding_column": { + "name": "preceding_column", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "epic_id": { + "name": "epic_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "high": { + "name": "high", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "size": { + "name": "size", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estimate_minutes": { + "name": "estimate_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_date": { + "name": "deadline_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_time": { + "name": "deadline_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "field_versions": { + "name": "field_versions", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_by": { + "name": "completed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "trash_root_id": { + "name": "trash_root_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "trashed_at": { + "name": "trashed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "task_household_order_idx": { + "name": "task_household_order_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_epic_idx": { + "name": "task_epic_idx", + "columns": [ + { + "expression": "epic_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_parent_idx": { + "name": "task_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tasks_household_id_households_id_fk": { + "name": "tasks_household_id_households_id_fk", + "tableFrom": "tasks", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tasks_parent_id_tasks_id_fk": { + "name": "tasks_parent_id_tasks_id_fk", + "tableFrom": "tasks", + "tableTo": "tasks", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "tasks_epic_id_planning_entities_id_fk": { + "name": "tasks_epic_id_planning_entities_id_fk", + "tableFrom": "tasks", + "tableTo": "planning_entities", + "columnsFrom": [ + "epic_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_created_by_users_id_fk": { + "name": "tasks_created_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_completed_by_users_id_fk": { + "name": "tasks_completed_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "completed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.filter_history": { + "name": "filter_history", + "schema": "", + "columns": { + "filter_id": { + "name": "filter_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "filter_history_filter_id_saved_filters_id_fk": { + "name": "filter_history_filter_id_saved_filters_id_fk", + "tableFrom": "filter_history", + "tableTo": "saved_filters", + "columnsFrom": [ + "filter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "filter_history_actor_id_users_id_fk": { + "name": "filter_history_actor_id_users_id_fk", + "tableFrom": "filter_history", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "filter_history_filter_id_version_pk": { + "name": "filter_history_filter_id_version_pk", + "columns": [ + "filter_id", + "version" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_filters": { + "name": "saved_filters", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'list-filter'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "saved_filters_household_id_households_id_fk": { + "name": "saved_filters_household_id_households_id_fk", + "tableFrom": "saved_filters", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "saved_filters_created_by_users_id_fk": { + "name": "saved_filters_created_by_users_id_fk", + "tableFrom": "saved_filters", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.view_personal": { + "name": "view_personal", + "schema": "", + "columns": { + "view_id": { + "name": "view_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "active_filters": { + "name": "active_filters", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "favorite": { + "name": "favorite", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "current_place": { + "name": "current_place", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "view_personal_view_id_saved_views_id_fk": { + "name": "view_personal_view_id_saved_views_id_fk", + "tableFrom": "view_personal", + "tableTo": "saved_views", + "columnsFrom": [ + "view_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "view_personal_user_id_users_id_fk": { + "name": "view_personal_user_id_users_id_fk", + "tableFrom": "view_personal", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "view_personal_view_id_user_id_pk": { + "name": "view_personal_view_id_user_id_pk", + "columns": [ + "view_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_views": { + "name": "saved_views", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'list-filter'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "view_household_builtin_idx": { + "name": "view_household_builtin_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "builtin", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "saved_views_household_id_households_id_fk": { + "name": "saved_views_household_id_households_id_fk", + "tableFrom": "saved_views", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "saved_views_created_by_users_id_fk": { + "name": "saved_views_created_by_users_id_fk", + "tableFrom": "saved_views", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.lifecycle_settings": { + "name": "lifecycle_settings", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "archive_days": { + "name": "archive_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 30 + }, + "trash_days": { + "name": "trash_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 30 + } + }, + "indexes": {}, + "foreignKeys": { + "lifecycle_settings_household_id_households_id_fk": { + "name": "lifecycle_settings_household_id_households_id_fk", + "tableFrom": "lifecycle_settings", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_occurrences": { + "name": "task_occurrences", + "schema": "", + "columns": { + "template_id": { + "name": "template_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "root_id": { + "name": "root_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "task_occurrences_template_id_task_templates_id_fk": { + "name": "task_occurrences_template_id_task_templates_id_fk", + "tableFrom": "task_occurrences", + "tableTo": "task_templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_occurrences_template_id_date_pk": { + "name": "task_occurrences_template_id_date_pk", + "columns": [ + "template_id", + "date" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_templates": { + "name": "task_templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "nodes": { + "name": "nodes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "recurrence": { + "name": "recurrence", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "task_templates_household_id_households_id_fk": { + "name": "task_templates_household_id_households_id_fk", + "tableFrom": "task_templates", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_comments": { + "name": "task_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "comment_task_idx": { + "name": "comment_task_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_comments_household_id_households_id_fk": { + "name": "task_comments_household_id_households_id_fk", + "tableFrom": "task_comments", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_comments_task_id_tasks_id_fk": { + "name": "task_comments_task_id_tasks_id_fk", + "tableFrom": "task_comments", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_comments_author_id_users_id_fk": { + "name": "task_comments_author_id_users_id_fk", + "tableFrom": "task_comments", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_files": { + "name": "task_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "comment_id": { + "name": "comment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "file_task_idx": { + "name": "file_task_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_files_household_id_households_id_fk": { + "name": "task_files_household_id_households_id_fk", + "tableFrom": "task_files", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_files_task_id_tasks_id_fk": { + "name": "task_files_task_id_tasks_id_fk", + "tableFrom": "task_files", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_files_comment_id_task_comments_id_fk": { + "name": "task_files_comment_id_task_comments_id_fk", + "tableFrom": "task_files", + "tableTo": "task_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.household_role": { + "name": "household_role", + "schema": "public", + "values": [ + "admin", + "member" + ] + }, + "public.token_purpose": { + "name": "token_purpose", + "schema": "public", + "values": [ + "bootstrap", + "invite", + "recovery", + "verify_email" + ] + }, + "public.planning_bucket": { + "name": "planning_bucket", + "schema": "public", + "values": [ + "someday", + "within_year", + "within_month", + "ready" + ] + }, + "public.entity_kind": { + "name": "entity_kind", + "schema": "public", + "values": [ + "epic", + "place", + "resource", + "tag" + ] + }, + "public.task_status": { + "name": "task_status", + "schema": "public", + "values": [ + "todo", + "in_progress", + "done" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/api/drizzle/meta/0009_snapshot.json b/apps/api/drizzle/meta/0009_snapshot.json new file mode 100644 index 0000000..4c70c25 --- /dev/null +++ b/apps/api/drizzle/meta/0009_snapshot.json @@ -0,0 +1,2398 @@ +{ + "id": "1003e8e1-836d-4124-affc-5b4b0604fbca", + "prevId": "8a86497d-3802-4225-bcf8-5cde056f3a52", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.installation": { + "name": "installation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_challenges": { + "name": "auth_challenges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "challenge": { + "name": "challenge", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "binding_hash": { + "name": "binding_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.passkey_credentials": { + "name": "passkey_credentials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counter": { + "name": "counter", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "transports": { + "name": "transports", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credential_user_idx": { + "name": "credential_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "passkey_credentials_user_id_users_id_fk": { + "name": "passkey_credentials_user_id_users_id_fk", + "tableFrom": "passkey_credentials", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.households": { + "name": "households", + "schema": "", + "columns": { + "revision": { + "name": "revision", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memberships": { + "name": "memberships", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "membership_user_idx": { + "name": "membership_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "memberships_household_id_households_id_fk": { + "name": "memberships_household_id_households_id_fk", + "tableFrom": "memberships", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "memberships_user_id_users_id_fk": { + "name": "memberships_user_id_users_id_fk", + "tableFrom": "memberships", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "memberships_household_id_user_id_pk": { + "name": "memberships_household_id_user_id_pk", + "columns": [ + "household_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.security_events": { + "name": "security_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "subject_id": { + "name": "subject_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "security_events_actor_id_users_id_fk": { + "name": "security_events_actor_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "security_events_subject_id_users_id_fk": { + "name": "security_events_subject_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "authenticated_at": { + "name": "authenticated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "session_user_idx": { + "name": "session_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.smtp_settings": { + "name": "smtp_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "encrypted": { + "name": "encrypted", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account_tokens": { + "name": "account_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "purpose": { + "name": "purpose", + "type": "token_purpose", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "verifies_email": { + "name": "verifies_email", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "account_tokens_user_id_users_id_fk": { + "name": "account_tokens_user_id_users_id_fk", + "tableFrom": "account_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "account_tokens_household_id_households_id_fk": { + "name": "account_tokens_household_id_households_id_fk", + "tableFrom": "account_tokens", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "avatar": { + "name": "avatar", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email_verified_at": { + "name": "email_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "deployment_admin": { + "name": "deployment_admin", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "language": { + "name": "language", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'en'" + }, + "theme": { + "name": "theme", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_entities": { + "name": "planning_entities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "entity_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'house'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "latitude": { + "name": "latitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "longitude": { + "name": "longitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "radius": { + "name": "radius", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "entity_household_idx": { + "name": "entity_household_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "planning_entities_household_id_households_id_fk": { + "name": "planning_entities_household_id_households_id_fk", + "tableFrom": "planning_entities", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_settings": { + "name": "planning_settings", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "size_thresholds": { + "name": "size_thresholds", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[60,240,480,1440]'::jsonb" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + } + }, + "indexes": {}, + "foreignKeys": { + "planning_settings_household_id_households_id_fk": { + "name": "planning_settings_household_id_households_id_fk", + "tableFrom": "planning_settings", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_activities": { + "name": "task_activities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "fields": { + "name": "fields", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "task_activities_task_id_tasks_id_fk": { + "name": "task_activities_task_id_tasks_id_fk", + "tableFrom": "task_activities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_activities_actor_id_users_id_fk": { + "name": "task_activities_actor_id_users_id_fk", + "tableFrom": "task_activities", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_assignees": { + "name": "task_assignees", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_assignees_task_id_tasks_id_fk": { + "name": "task_assignees_task_id_tasks_id_fk", + "tableFrom": "task_assignees", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_assignees_user_id_users_id_fk": { + "name": "task_assignees_user_id_users_id_fk", + "tableFrom": "task_assignees", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_assignees_task_id_user_id_pk": { + "name": "task_assignees_task_id_user_id_pk", + "columns": [ + "task_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_dependencies": { + "name": "task_dependencies", + "schema": "", + "columns": { + "blocked_task_id": { + "name": "blocked_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "blocking_task_id": { + "name": "blocking_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "dependency_blocker_idx": { + "name": "dependency_blocker_idx", + "columns": [ + { + "expression": "blocking_task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_dependencies_blocked_task_id_tasks_id_fk": { + "name": "task_dependencies_blocked_task_id_tasks_id_fk", + "tableFrom": "task_dependencies", + "tableTo": "tasks", + "columnsFrom": [ + "blocked_task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_dependencies_blocked_task_id_blocking_task_id_pk": { + "name": "task_dependencies_blocked_task_id_blocking_task_id_pk", + "columns": [ + "blocked_task_id", + "blocking_task_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entities": { + "name": "task_entities", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entities_task_id_tasks_id_fk": { + "name": "task_entities_task_id_tasks_id_fk", + "tableFrom": "task_entities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entities_entity_id_planning_entities_id_fk": { + "name": "task_entities_entity_id_planning_entities_id_fk", + "tableFrom": "task_entities", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entities_task_id_entity_id_pk": { + "name": "task_entities_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entity_exclusions": { + "name": "task_entity_exclusions", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entity_exclusions_task_id_tasks_id_fk": { + "name": "task_entity_exclusions_task_id_tasks_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entity_exclusions_entity_id_planning_entities_id_fk": { + "name": "task_entity_exclusions_entity_id_planning_entities_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entity_exclusions_task_id_entity_id_pk": { + "name": "task_entity_exclusions_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_relations": { + "name": "task_relations", + "schema": "", + "columns": { + "first_id": { + "name": "first_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "second_id": { + "name": "second_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "relation_second_idx": { + "name": "relation_second_idx", + "columns": [ + { + "expression": "second_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_relations_first_id_tasks_id_fk": { + "name": "task_relations_first_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "first_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_relations_second_id_tasks_id_fk": { + "name": "task_relations_second_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "second_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_relations_first_id_second_id_pk": { + "name": "task_relations_first_id_second_id_pk", + "columns": [ + "first_id", + "second_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tasks": { + "name": "tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "inherit": { + "name": "inherit", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "status": { + "name": "status", + "type": "task_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'todo'" + }, + "planning_bucket": { + "name": "planning_bucket", + "type": "planning_bucket", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'someday'" + }, + "preceding_column": { + "name": "preceding_column", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "epic_id": { + "name": "epic_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "high": { + "name": "high", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "size": { + "name": "size", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estimate_minutes": { + "name": "estimate_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_date": { + "name": "deadline_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_time": { + "name": "deadline_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "field_versions": { + "name": "field_versions", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_by": { + "name": "completed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "trash_root_id": { + "name": "trash_root_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "trashed_at": { + "name": "trashed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "task_household_order_idx": { + "name": "task_household_order_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_epic_idx": { + "name": "task_epic_idx", + "columns": [ + { + "expression": "epic_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_parent_idx": { + "name": "task_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tasks_household_id_households_id_fk": { + "name": "tasks_household_id_households_id_fk", + "tableFrom": "tasks", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tasks_parent_id_tasks_id_fk": { + "name": "tasks_parent_id_tasks_id_fk", + "tableFrom": "tasks", + "tableTo": "tasks", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "tasks_epic_id_planning_entities_id_fk": { + "name": "tasks_epic_id_planning_entities_id_fk", + "tableFrom": "tasks", + "tableTo": "planning_entities", + "columnsFrom": [ + "epic_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_created_by_users_id_fk": { + "name": "tasks_created_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_completed_by_users_id_fk": { + "name": "tasks_completed_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "completed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.filter_history": { + "name": "filter_history", + "schema": "", + "columns": { + "filter_id": { + "name": "filter_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "filter_history_filter_id_saved_filters_id_fk": { + "name": "filter_history_filter_id_saved_filters_id_fk", + "tableFrom": "filter_history", + "tableTo": "saved_filters", + "columnsFrom": [ + "filter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "filter_history_actor_id_users_id_fk": { + "name": "filter_history_actor_id_users_id_fk", + "tableFrom": "filter_history", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "filter_history_filter_id_version_pk": { + "name": "filter_history_filter_id_version_pk", + "columns": [ + "filter_id", + "version" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_filters": { + "name": "saved_filters", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'list-filter'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "saved_filters_household_id_households_id_fk": { + "name": "saved_filters_household_id_households_id_fk", + "tableFrom": "saved_filters", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "saved_filters_created_by_users_id_fk": { + "name": "saved_filters_created_by_users_id_fk", + "tableFrom": "saved_filters", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.view_personal": { + "name": "view_personal", + "schema": "", + "columns": { + "view_id": { + "name": "view_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "active_filters": { + "name": "active_filters", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "favorite": { + "name": "favorite", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "current_place": { + "name": "current_place", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "view_personal_view_id_saved_views_id_fk": { + "name": "view_personal_view_id_saved_views_id_fk", + "tableFrom": "view_personal", + "tableTo": "saved_views", + "columnsFrom": [ + "view_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "view_personal_user_id_users_id_fk": { + "name": "view_personal_user_id_users_id_fk", + "tableFrom": "view_personal", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "view_personal_view_id_user_id_pk": { + "name": "view_personal_view_id_user_id_pk", + "columns": [ + "view_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_views": { + "name": "saved_views", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'list-filter'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "view_household_builtin_idx": { + "name": "view_household_builtin_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "builtin", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "saved_views_household_id_households_id_fk": { + "name": "saved_views_household_id_households_id_fk", + "tableFrom": "saved_views", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "saved_views_created_by_users_id_fk": { + "name": "saved_views_created_by_users_id_fk", + "tableFrom": "saved_views", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.lifecycle_settings": { + "name": "lifecycle_settings", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "archive_days": { + "name": "archive_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 30 + }, + "trash_days": { + "name": "trash_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 30 + } + }, + "indexes": {}, + "foreignKeys": { + "lifecycle_settings_household_id_households_id_fk": { + "name": "lifecycle_settings_household_id_households_id_fk", + "tableFrom": "lifecycle_settings", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_occurrences": { + "name": "task_occurrences", + "schema": "", + "columns": { + "template_id": { + "name": "template_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "root_id": { + "name": "root_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "task_occurrences_template_id_task_templates_id_fk": { + "name": "task_occurrences_template_id_task_templates_id_fk", + "tableFrom": "task_occurrences", + "tableTo": "task_templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_occurrences_template_id_date_pk": { + "name": "task_occurrences_template_id_date_pk", + "columns": [ + "template_id", + "date" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_templates": { + "name": "task_templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "nodes": { + "name": "nodes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "recurrence": { + "name": "recurrence", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "task_templates_household_id_households_id_fk": { + "name": "task_templates_household_id_households_id_fk", + "tableFrom": "task_templates", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_comments": { + "name": "task_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "comment_task_idx": { + "name": "comment_task_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_comments_household_id_households_id_fk": { + "name": "task_comments_household_id_households_id_fk", + "tableFrom": "task_comments", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_comments_task_id_tasks_id_fk": { + "name": "task_comments_task_id_tasks_id_fk", + "tableFrom": "task_comments", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_comments_author_id_users_id_fk": { + "name": "task_comments_author_id_users_id_fk", + "tableFrom": "task_comments", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_files": { + "name": "task_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "comment_id": { + "name": "comment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "file_task_idx": { + "name": "file_task_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_files_household_id_households_id_fk": { + "name": "task_files_household_id_households_id_fk", + "tableFrom": "task_files", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_files_task_id_tasks_id_fk": { + "name": "task_files_task_id_tasks_id_fk", + "tableFrom": "task_files", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_files_comment_id_task_comments_id_fk": { + "name": "task_files_comment_id_task_comments_id_fk", + "tableFrom": "task_files", + "tableTo": "task_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.household_role": { + "name": "household_role", + "schema": "public", + "values": [ + "admin", + "member" + ] + }, + "public.token_purpose": { + "name": "token_purpose", + "schema": "public", + "values": [ + "bootstrap", + "invite", + "recovery", + "verify_email" + ] + }, + "public.planning_bucket": { + "name": "planning_bucket", + "schema": "public", + "values": [ + "someday", + "within_year", + "within_month", + "ready" + ] + }, + "public.entity_kind": { + "name": "entity_kind", + "schema": "public", + "values": [ + "epic", + "place", + "resource", + "tag" + ] + }, + "public.task_status": { + "name": "task_status", + "schema": "public", + "values": [ + "todo", + "in_progress", + "done" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/api/drizzle/meta/0010_snapshot.json b/apps/api/drizzle/meta/0010_snapshot.json new file mode 100644 index 0000000..9980665 --- /dev/null +++ b/apps/api/drizzle/meta/0010_snapshot.json @@ -0,0 +1,2398 @@ +{ + "id": "a57a1d50-0455-4eb9-b90b-78160a63b085", + "prevId": "1003e8e1-836d-4124-affc-5b4b0604fbca", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.installation": { + "name": "installation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_challenges": { + "name": "auth_challenges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "challenge": { + "name": "challenge", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "binding_hash": { + "name": "binding_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.passkey_credentials": { + "name": "passkey_credentials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counter": { + "name": "counter", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "transports": { + "name": "transports", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credential_user_idx": { + "name": "credential_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "passkey_credentials_user_id_users_id_fk": { + "name": "passkey_credentials_user_id_users_id_fk", + "tableFrom": "passkey_credentials", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.households": { + "name": "households", + "schema": "", + "columns": { + "revision": { + "name": "revision", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memberships": { + "name": "memberships", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "membership_user_idx": { + "name": "membership_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "memberships_household_id_households_id_fk": { + "name": "memberships_household_id_households_id_fk", + "tableFrom": "memberships", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "memberships_user_id_users_id_fk": { + "name": "memberships_user_id_users_id_fk", + "tableFrom": "memberships", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "memberships_household_id_user_id_pk": { + "name": "memberships_household_id_user_id_pk", + "columns": [ + "household_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.security_events": { + "name": "security_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "subject_id": { + "name": "subject_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "security_events_actor_id_users_id_fk": { + "name": "security_events_actor_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "security_events_subject_id_users_id_fk": { + "name": "security_events_subject_id_users_id_fk", + "tableFrom": "security_events", + "tableTo": "users", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "authenticated_at": { + "name": "authenticated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "session_user_idx": { + "name": "session_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.smtp_settings": { + "name": "smtp_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "encrypted": { + "name": "encrypted", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account_tokens": { + "name": "account_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "purpose": { + "name": "purpose", + "type": "token_purpose", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "verifies_email": { + "name": "verifies_email", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "household_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "account_tokens_user_id_users_id_fk": { + "name": "account_tokens_user_id_users_id_fk", + "tableFrom": "account_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "account_tokens_household_id_households_id_fk": { + "name": "account_tokens_household_id_households_id_fk", + "tableFrom": "account_tokens", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "avatar": { + "name": "avatar", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email_verified_at": { + "name": "email_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "deployment_admin": { + "name": "deployment_admin", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "language": { + "name": "language", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'en'" + }, + "theme": { + "name": "theme", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_entities": { + "name": "planning_entities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "entity_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'house'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "latitude": { + "name": "latitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "longitude": { + "name": "longitude", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "radius": { + "name": "radius", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "entity_household_idx": { + "name": "entity_household_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "planning_entities_household_id_households_id_fk": { + "name": "planning_entities_household_id_households_id_fk", + "tableFrom": "planning_entities", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.planning_settings": { + "name": "planning_settings", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "size_thresholds": { + "name": "size_thresholds", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[60,240,480,1440]'::jsonb" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + } + }, + "indexes": {}, + "foreignKeys": { + "planning_settings_household_id_households_id_fk": { + "name": "planning_settings_household_id_households_id_fk", + "tableFrom": "planning_settings", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_activities": { + "name": "task_activities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "fields": { + "name": "fields", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "task_activities_task_id_tasks_id_fk": { + "name": "task_activities_task_id_tasks_id_fk", + "tableFrom": "task_activities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_activities_actor_id_users_id_fk": { + "name": "task_activities_actor_id_users_id_fk", + "tableFrom": "task_activities", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_assignees": { + "name": "task_assignees", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_assignees_task_id_tasks_id_fk": { + "name": "task_assignees_task_id_tasks_id_fk", + "tableFrom": "task_assignees", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_assignees_user_id_users_id_fk": { + "name": "task_assignees_user_id_users_id_fk", + "tableFrom": "task_assignees", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_assignees_task_id_user_id_pk": { + "name": "task_assignees_task_id_user_id_pk", + "columns": [ + "task_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_dependencies": { + "name": "task_dependencies", + "schema": "", + "columns": { + "blocked_task_id": { + "name": "blocked_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "blocking_task_id": { + "name": "blocking_task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "dependency_blocker_idx": { + "name": "dependency_blocker_idx", + "columns": [ + { + "expression": "blocking_task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_dependencies_blocked_task_id_tasks_id_fk": { + "name": "task_dependencies_blocked_task_id_tasks_id_fk", + "tableFrom": "task_dependencies", + "tableTo": "tasks", + "columnsFrom": [ + "blocked_task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_dependencies_blocked_task_id_blocking_task_id_pk": { + "name": "task_dependencies_blocked_task_id_blocking_task_id_pk", + "columns": [ + "blocked_task_id", + "blocking_task_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entities": { + "name": "task_entities", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entities_task_id_tasks_id_fk": { + "name": "task_entities_task_id_tasks_id_fk", + "tableFrom": "task_entities", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entities_entity_id_planning_entities_id_fk": { + "name": "task_entities_entity_id_planning_entities_id_fk", + "tableFrom": "task_entities", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entities_task_id_entity_id_pk": { + "name": "task_entities_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_entity_exclusions": { + "name": "task_entity_exclusions", + "schema": "", + "columns": { + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "task_entity_exclusions_task_id_tasks_id_fk": { + "name": "task_entity_exclusions_task_id_tasks_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_entity_exclusions_entity_id_planning_entities_id_fk": { + "name": "task_entity_exclusions_entity_id_planning_entities_id_fk", + "tableFrom": "task_entity_exclusions", + "tableTo": "planning_entities", + "columnsFrom": [ + "entity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_entity_exclusions_task_id_entity_id_pk": { + "name": "task_entity_exclusions_task_id_entity_id_pk", + "columns": [ + "task_id", + "entity_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_relations": { + "name": "task_relations", + "schema": "", + "columns": { + "first_id": { + "name": "first_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "second_id": { + "name": "second_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "relation_second_idx": { + "name": "relation_second_idx", + "columns": [ + { + "expression": "second_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_relations_first_id_tasks_id_fk": { + "name": "task_relations_first_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "first_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_relations_second_id_tasks_id_fk": { + "name": "task_relations_second_id_tasks_id_fk", + "tableFrom": "task_relations", + "tableTo": "tasks", + "columnsFrom": [ + "second_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_relations_first_id_second_id_pk": { + "name": "task_relations_first_id_second_id_pk", + "columns": [ + "first_id", + "second_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tasks": { + "name": "tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "inherit": { + "name": "inherit", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "status": { + "name": "status", + "type": "task_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'todo'" + }, + "planning_bucket": { + "name": "planning_bucket", + "type": "planning_bucket", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'someday'" + }, + "preceding_column": { + "name": "preceding_column", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "epic_id": { + "name": "epic_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "high": { + "name": "high", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "size": { + "name": "size", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estimate_minutes": { + "name": "estimate_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_date": { + "name": "deadline_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deadline_time": { + "name": "deadline_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "field_versions": { + "name": "field_versions", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "sort_order": { + "name": "sort_order", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_by": { + "name": "completed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "trash_root_id": { + "name": "trash_root_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "trashed_at": { + "name": "trashed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "task_household_order_idx": { + "name": "task_household_order_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_epic_idx": { + "name": "task_epic_idx", + "columns": [ + { + "expression": "epic_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_parent_idx": { + "name": "task_parent_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tasks_household_id_households_id_fk": { + "name": "tasks_household_id_households_id_fk", + "tableFrom": "tasks", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tasks_parent_id_tasks_id_fk": { + "name": "tasks_parent_id_tasks_id_fk", + "tableFrom": "tasks", + "tableTo": "tasks", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "tasks_epic_id_planning_entities_id_fk": { + "name": "tasks_epic_id_planning_entities_id_fk", + "tableFrom": "tasks", + "tableTo": "planning_entities", + "columnsFrom": [ + "epic_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_created_by_users_id_fk": { + "name": "tasks_created_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_completed_by_users_id_fk": { + "name": "tasks_completed_by_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "completed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.filter_history": { + "name": "filter_history", + "schema": "", + "columns": { + "filter_id": { + "name": "filter_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "filter_history_filter_id_saved_filters_id_fk": { + "name": "filter_history_filter_id_saved_filters_id_fk", + "tableFrom": "filter_history", + "tableTo": "saved_filters", + "columnsFrom": [ + "filter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "filter_history_actor_id_users_id_fk": { + "name": "filter_history_actor_id_users_id_fk", + "tableFrom": "filter_history", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "filter_history_filter_id_version_pk": { + "name": "filter_history_filter_id_version_pk", + "columns": [ + "filter_id", + "version" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_filters": { + "name": "saved_filters", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'list-filter'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "saved_filters_household_id_households_id_fk": { + "name": "saved_filters_household_id_households_id_fk", + "tableFrom": "saved_filters", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "saved_filters_created_by_users_id_fk": { + "name": "saved_filters_created_by_users_id_fk", + "tableFrom": "saved_filters", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.view_personal": { + "name": "view_personal", + "schema": "", + "columns": { + "view_id": { + "name": "view_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "active_filters": { + "name": "active_filters", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "favorite": { + "name": "favorite", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "current_place": { + "name": "current_place", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "view_personal_view_id_saved_views_id_fk": { + "name": "view_personal_view_id_saved_views_id_fk", + "tableFrom": "view_personal", + "tableTo": "saved_views", + "columnsFrom": [ + "view_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "view_personal_user_id_users_id_fk": { + "name": "view_personal_user_id_users_id_fk", + "tableFrom": "view_personal", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "view_personal_view_id_user_id_pk": { + "name": "view_personal_view_id_user_id_pk", + "columns": [ + "view_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_views": { + "name": "saved_views", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'list-filter'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blue'" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "definition": { + "name": "definition", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "view_household_builtin_idx": { + "name": "view_household_builtin_idx", + "columns": [ + { + "expression": "household_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "builtin", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "saved_views_household_id_households_id_fk": { + "name": "saved_views_household_id_households_id_fk", + "tableFrom": "saved_views", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "saved_views_created_by_users_id_fk": { + "name": "saved_views_created_by_users_id_fk", + "tableFrom": "saved_views", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.lifecycle_settings": { + "name": "lifecycle_settings", + "schema": "", + "columns": { + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "archive_days": { + "name": "archive_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 30 + }, + "trash_days": { + "name": "trash_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 30 + } + }, + "indexes": {}, + "foreignKeys": { + "lifecycle_settings_household_id_households_id_fk": { + "name": "lifecycle_settings_household_id_households_id_fk", + "tableFrom": "lifecycle_settings", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_occurrences": { + "name": "task_occurrences", + "schema": "", + "columns": { + "template_id": { + "name": "template_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "root_id": { + "name": "root_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "task_occurrences_template_id_task_templates_id_fk": { + "name": "task_occurrences_template_id_task_templates_id_fk", + "tableFrom": "task_occurrences", + "tableTo": "task_templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "task_occurrences_template_id_date_pk": { + "name": "task_occurrences_template_id_date_pk", + "columns": [ + "template_id", + "date" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_templates": { + "name": "task_templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "nodes": { + "name": "nodes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "recurrence": { + "name": "recurrence", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "task_templates_household_id_households_id_fk": { + "name": "task_templates_household_id_households_id_fk", + "tableFrom": "task_templates", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_comments": { + "name": "task_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "comment_task_idx": { + "name": "comment_task_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_comments_household_id_households_id_fk": { + "name": "task_comments_household_id_households_id_fk", + "tableFrom": "task_comments", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_comments_task_id_tasks_id_fk": { + "name": "task_comments_task_id_tasks_id_fk", + "tableFrom": "task_comments", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_comments_author_id_users_id_fk": { + "name": "task_comments_author_id_users_id_fk", + "tableFrom": "task_comments", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_files": { + "name": "task_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "household_id": { + "name": "household_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "comment_id": { + "name": "comment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "file_task_idx": { + "name": "file_task_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_files_household_id_households_id_fk": { + "name": "task_files_household_id_households_id_fk", + "tableFrom": "task_files", + "tableTo": "households", + "columnsFrom": [ + "household_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_files_task_id_tasks_id_fk": { + "name": "task_files_task_id_tasks_id_fk", + "tableFrom": "task_files", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "task_files_comment_id_task_comments_id_fk": { + "name": "task_files_comment_id_task_comments_id_fk", + "tableFrom": "task_files", + "tableTo": "task_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.household_role": { + "name": "household_role", + "schema": "public", + "values": [ + "admin", + "member" + ] + }, + "public.token_purpose": { + "name": "token_purpose", + "schema": "public", + "values": [ + "bootstrap", + "invite", + "recovery", + "verify_email" + ] + }, + "public.planning_bucket": { + "name": "planning_bucket", + "schema": "public", + "values": [ + "someday", + "within_year", + "within_month", + "ready" + ] + }, + "public.entity_kind": { + "name": "entity_kind", + "schema": "public", + "values": [ + "epic", + "place", + "resource", + "tag" + ] + }, + "public.task_status": { + "name": "task_status", + "schema": "public", + "values": [ + "todo", + "in_progress", + "done" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/api/drizzle/meta/_journal.json b/apps/api/drizzle/meta/_journal.json index 8bbb1b8..c056429 100644 --- a/apps/api/drizzle/meta/_journal.json +++ b/apps/api/drizzle/meta/_journal.json @@ -29,6 +29,55 @@ "when": 1791993728147, "tag": "0003_easy_elektra", "breakpoints": true + }, + { + "idx": 4, + "version": "7", + "when": 1792001240021, + "tag": "0004_brainy_spot", + "breakpoints": true + }, + { + "idx": 5, + "version": "7", + "when": 1792011422429, + "tag": "0005_giant_lilandra", + "breakpoints": true + }, + { + "idx": 6, + "version": "7", + "when": 1792011813690, + "tag": "0006_romantic_wind_dancer", + "breakpoints": true + }, + { + "idx": 7, + "version": "7", + "when": 1792012233995, + "tag": "0007_cynical_vapor", + "breakpoints": true + }, + { + "idx": 8, + "version": "7", + "when": 1792012303285, + "tag": "0008_perfect_ikaris", + "breakpoints": true + }, + { + "idx": 9, + "version": "7", + "when": 1792012641120, + "tag": "0009_true_crystal", + "breakpoints": true + }, + { + "idx": 10, + "version": "7", + "when": 1792013299693, + "tag": "0010_thin_rattler", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/api/package.json b/apps/api/package.json index 7993a7c..7bcf91e 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -1,7 +1,7 @@ { "name": "@tendly/api", "private": true, - "version": "0.0.0", + "version": "1.0.0", "license": "AGPL-3.0-or-later", "type": "module", "scripts": { @@ -33,7 +33,8 @@ "exports": { "./config": "./dist/config.js", "./logging": "./dist/logging.js", - "./mail-worker": "./dist/accounts/mail-worker.js" + "./mail-worker": "./dist/accounts/mail-worker.js", + "./lifecycle-worker": "./dist/lifecycle/worker.js" }, "devDependencies": { "@types/nodemailer": "8.0.2", diff --git a/apps/api/src/accounts/access.ts b/apps/api/src/accounts/access.ts index 8ef1c89..dea6521 100644 --- a/apps/api/src/accounts/access.ts +++ b/apps/api/src/accounts/access.ts @@ -39,7 +39,7 @@ export async function accountView(db: QueryDatabase, actor: Actor) { .from(memberships).innerJoin(households, eq(households.id, memberships.householdId)) .where(eq(memberships.userId, actor.user.id)); return { - id: actor.user.id, name: actor.user.name, email: actor.user.email, + id: actor.user.id, avatar: actor.user.avatar ? '/api/v1/avatars/' + actor.user.avatar : null, name: actor.user.name, email: actor.user.email, emailVerified: !!actor.user.emailVerifiedAt, deploymentAdmin: actor.user.deploymentAdmin, language: actor.user.language as 'en' | 'sv', theme: actor.user.theme as 'system' | 'light' | 'dark', households: rows, }; diff --git a/apps/api/src/accounts/accounts.integration.test.ts b/apps/api/src/accounts/accounts.integration.test.ts index a56bb4c..a770f24 100644 --- a/apps/api/src/accounts/accounts.integration.test.ts +++ b/apps/api/src/accounts/accounts.integration.test.ts @@ -58,6 +58,12 @@ it('denies cross-household access, foreign websocket subscriptions, and deployme await expect(app.injectWS(`/api/v1/households/${householdB}/events`, { headers: headers(sessionA), socket: { remoteAddress: '127.0.0.1' } })).rejects.toThrow(); const socket = await app.injectWS(`/api/v1/households/${householdA}/events`, { headers: headers(sessionA), socket: { remoteAddress: '127.0.0.1' } }); socket.close(); + // Existing sockets must lose access too, not only newly authenticated requests. + const temporarySession = await service.session(db, userA); + const revoked = await app.injectWS(`/api/v1/households/${householdA}/events`, { headers: headers(temporarySession), socket: { remoteAddress: '127.0.0.1' } }); + const closed = new Promise(resolve => revoked.once('close', code => resolve(code))); + await app.inject({ method: 'POST', url: '/api/v1/auth/logout', headers: headers(temporarySession), payload: {} }); + expect(await closed).toBe(1008); expect((await app.inject({ method: 'POST', url: '/api/v1/auth/logout', headers: { ...headers(sessionA), origin: 'https://attacker.test' }, payload: {} })).statusCode).toBe(403); }); it('issues single-use 30-minute invitation codes without SMTP or email verification', async () => { diff --git a/apps/api/src/accounts/avatar.ts b/apps/api/src/accounts/avatar.ts new file mode 100644 index 0000000..0137b14 --- /dev/null +++ b/apps/api/src/accounts/avatar.ts @@ -0,0 +1,29 @@ +import { randomUUID } from 'node:crypto'; +import { mkdir, writeFile, unlink, readFile } from 'node:fs/promises'; +import { join } from 'node:path'; +import { and, eq, inArray } from 'drizzle-orm'; +import type { Database } from './database.js'; +import type { Actor } from './access.js'; +import { memberships, users } from './schema.js'; +import { AccountError } from './errors.js'; +export async function saveAvatar(db: Database, actor: Actor, directory: string, image: string | null) { + let id: string | null = null; + if (image) { + const match = image.match(/^data:image\/jpeg;base64,([A-Za-z0-9+/]+=*)$/); + if (!match) throw new AccountError('invalid_file'); + const bytes = Buffer.from(match[1]!, 'base64'); + if (!bytes.subarray(0, 3).equals(Buffer.from([255, 216, 255]))) throw new AccountError('invalid_file'); + id = randomUUID(); await mkdir(directory, { recursive: true, mode: 0o700 }); await writeFile(join(directory, id), bytes, { flag: 'wx', mode: 0o600 }); + } + try { await db.update(users).set({ avatar: id }).where(eq(users.id, actor.user.id)); } + catch (error) { if (id) await unlink(join(directory, id)).catch(() => {}); throw error; } +} +export async function readAvatar(db: Database, actor: Actor, directory: string, id: string) { + const [owner] = await db.select({ id: users.id }).from(users).where(eq(users.avatar, id)); + if (!owner) throw new AccountError('file_not_found', 404); + if (owner.id !== actor.user.id) { + const own = await db.select({ householdId: memberships.householdId }).from(memberships).where(eq(memberships.userId, actor.user.id)); + if (!own.length || !(await db.select().from(memberships).where(and(eq(memberships.userId, owner.id), inArray(memberships.householdId, own.map(m => m.householdId))))).length) throw new AccountError('file_not_found', 404); + } + try { return await readFile(join(directory, id)); } catch { throw new AccountError('file_not_found', 404); } +} diff --git a/apps/api/src/accounts/routes.ts b/apps/api/src/accounts/routes.ts index e203299..f188d25 100644 --- a/apps/api/src/accounts/routes.ts +++ b/apps/api/src/accounts/routes.ts @@ -1,3 +1,4 @@ +import { saveAvatar, readAvatar } from './avatar.js'; import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'; import type { ZodTypeProvider } from 'fastify-type-provider-zod'; import cookie from '@fastify/cookie'; @@ -6,12 +7,12 @@ import websocket from '@fastify/websocket'; import { z } from 'zod'; import { and, eq, gt } from 'drizzle-orm'; import type { RegistrationResponseJSON, AuthenticationResponseJSON } from '@simplewebauthn/server'; -import { emailSchema, errorSchema, nameSchema, okSchema, registrationInput, roleSchema, sessionSchema, smtpSchema, verificationInput } from '@tendly/shared'; +import { emailSchema, errorSchema, timezoneSchema, nameSchema, okSchema, registrationInput, roleSchema, sessionSchema, smtpSchema, verificationInput } from '@tendly/shared'; import { AccountService } from './service.js'; import { MailService } from './mail.js'; import { AccountError } from './errors.js'; import { accountView, deploymentAdmin, householdAccess, lockAccounts, recent, signedIn } from './access.js'; -import { credentials, memberships, securityEvents, sessions, tokens, users } from './schema.js'; +import { credentials, households, memberships, securityEvents, sessions, tokens, users } from './schema.js'; import { digest, randomToken } from './crypto.js'; const ok = { ok: true as const }; @@ -20,7 +21,7 @@ const idParam = z.object({ id: z.uuid() }); const memberParam = z.object({ id: z.uuid(), userId: z.uuid() }); const linkInput = z.object({ token: z.string().min(20).max(128) }); -export async function registerAccountRoutes(server: FastifyInstance, service: AccountService, mail: MailService) { +export async function registerAccountRoutes(server: FastifyInstance, service: AccountService, mail: MailService, filesPath = '/data/attachments') { const app = server.withTypeProvider(); const db = service.db; const secure = new URL(service.origin).protocol === 'https:'; @@ -140,6 +141,16 @@ export async function registerAccountRoutes(server: FastifyInstance, service: Ac await db.update(users).set(request.body).where(eq(users.id, current.user.id)); return ok; }); + app.put('/api/v1/account/avatar', { schema: { body: z.object({ image: z.string().max(200000).nullable() }), response: { 200: okSchema } } }, async request => { + const current = await actor(request); signedIn(current); + await saveAvatar(db, current, filesPath, request.body.image); + return ok; + }); + app.get('/api/v1/avatars/:id', { schema: { params: idParam } }, async (request, reply) => { + const current = await actor(request); signedIn(current); + const bytes = await readAvatar(db, current, filesPath, request.params.id); + return reply.header('Cache-Control', 'private, no-store').header('X-Content-Type-Options', 'nosniff').type('image/jpeg').send(bytes); + }); app.get('/api/v1/account/passkeys', { schema: { response: { 200: z.array(z.object({ id: z.string(), name: z.string(), createdAt: z.string() })) } } }, async (request) => { const current = await actor(request); signedIn(current); const rows = await db.select({ id: credentials.id, name: credentials.name, createdAt: credentials.createdAt }).from(credentials).where(eq(credentials.userId, current.user.id)); @@ -159,10 +170,11 @@ export async function registerAccountRoutes(server: FastifyInstance, service: Ac await db.delete(sessions).where(and(eq(sessions.id, request.params.sessionId), eq(sessions.userId, current.user.id))); return ok; }); - app.get('/api/v1/households/:id/members', { schema: { params: idParam, response: { 200: z.array(z.object({ id: z.uuid(), name: z.string(), email: z.string(), role: roleSchema })) } } }, async (request) => { + app.get('/api/v1/households/:id/members', { schema: { params: idParam, response: { 200: z.array(z.object({ id: z.uuid(), name: z.string(), avatar: z.string().nullable(), email: z.string(), role: roleSchema })) } } }, async (request) => { const current = await actor(request); await householdAccess(db, current, request.params.id); - return db.select({ id: users.id, name: users.name, email: users.email, role: memberships.role }).from(memberships).innerJoin(users, eq(users.id, memberships.userId)).where(eq(memberships.householdId, request.params.id)); + const rows = await db.select({ id: users.id, avatar: users.avatar, name: users.name, email: users.email, role: memberships.role }).from(memberships).innerJoin(users, eq(users.id, memberships.userId)).where(eq(memberships.householdId, request.params.id)); + return rows.map(row => ({ ...row, avatar: row.avatar ? '/api/v1/avatars/' + row.avatar : null })); }); app.post('/api/v1/households/:id/invitations', { schema: { params: idParam, body: z.object({ email: emailSchema, role: roleSchema }), response: { 200: okSchema } } }, async (request) => { const current = await actor(request); recent(current); @@ -216,6 +228,17 @@ export async function registerAccountRoutes(server: FastifyInstance, service: Ac await mail.send(current.user.email, 'Tendly · Email test', 'Your Tendly email configuration works.'); return ok; }); + app.put('/api/v1/households/:id', { schema: { params: idParam, body: z.object({ name: nameSchema, timezone: timezoneSchema, previousName: z.string(), previousTimezone: z.string() }), response: { 200: okSchema } } }, async request => { + const current = await actor(request); + await db.transaction(async tx => { + await householdAccess(tx, current, request.params.id, true); + const [old] = await tx.select().from(households).where(eq(households.id, request.params.id)).for('update'); + await householdAccess(tx, current, request.params.id, true); + if (!old || old.name !== request.body.previousName || old.timezone !== request.body.previousTimezone) throw new AccountError('planning_conflict', 409); + await tx.update(households).set({ name: request.body.name, timezone: request.body.timezone, revision: old.revision + 1 }).where(eq(households.id, old.id)); + }); + return ok; + }); // Authorization happens before upgrade and again while the socket is alive. // Future broadcasts must recheck membership before sending household content. app.get('/api/v1/households/:id/events', { @@ -225,9 +248,23 @@ export async function registerAccountRoutes(server: FastifyInstance, service: Ac await householdAccess(db, await actor(request), request.params.id); }, }, (socket, request) => { - const timer = setInterval(() => { - void actor(request).then((current) => householdAccess(db, current, request.params.id)).catch(() => socket.close(1008, 'Access revoked')); - }, 15_000); + let revision = -1, checking = false, lastPing = Date.now(); + const tick = async () => { + if (checking) return; + checking = true; + try { + // A WebSocket outlives its upgrade request: never reuse the request's cached session. + const current = await service.findSession(request.cookies[sessionName]); + await householdAccess(db, current, request.params.id); + // Idle households still need traffic so reverse proxies keep the upgraded connection alive. + if (Date.now() - lastPing >= 20_000) { socket.ping(); lastPing = Date.now(); } + const [household] = await db.select({ revision: households.revision }).from(households).where(eq(households.id, request.params.id)); + if (household && household.revision !== revision) { revision = household.revision; socket.send(JSON.stringify({ type: 'changed', revision })); } + } catch { socket.close(1008, 'Access revoked'); } + finally { checking = false; } + }; + const timer = setInterval(() => { void tick(); }, 2000); + void tick(); socket.on('close', () => clearInterval(timer)); socket.on('error', () => clearInterval(timer)); }); diff --git a/apps/api/src/accounts/schema.ts b/apps/api/src/accounts/schema.ts index e5e68dd..40c99fe 100644 --- a/apps/api/src/accounts/schema.ts +++ b/apps/api/src/accounts/schema.ts @@ -6,6 +6,7 @@ export const users = pgTable('users', { id: uuid('id').primaryKey(), email: text('email').notNull().unique(), name: text('name').notNull(), + avatar: text('avatar'), emailVerifiedAt: timestamp('email_verified_at', { withTimezone: true }), deploymentAdmin: boolean('deployment_admin').notNull().default(false), language: text('language').notNull().default('en'), @@ -13,6 +14,7 @@ export const users = pgTable('users', { createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(), }); export const households = pgTable('households', { + revision: bigint('revision', { mode: 'number' }).notNull().default(0), id: uuid('id').primaryKey().defaultRandom(), name: text('name').notNull(), timezone: text('timezone').notNull(), diff --git a/apps/api/src/accounts/service.ts b/apps/api/src/accounts/service.ts index 02f0ebd..71b812d 100644 --- a/apps/api/src/accounts/service.ts +++ b/apps/api/src/accounts/service.ts @@ -1,4 +1,5 @@ import { tasks, taskAssignees, taskActivities } from '../tasks/schema.js'; +import { templates } from '../lifecycle/schema.js'; import { randomUUID } from 'node:crypto'; import { and, eq, gt, isNull, lt } from 'drizzle-orm'; import { @@ -218,6 +219,10 @@ export class AccountService { await tx.insert(taskActivities).values({ taskId: task.id, actorId: current.user.id, version: task.version + 1, fields: ['assignees'] }); } await tx.delete(memberships).where(scope); + const saved = await tx.select().from(templates).where(eq(templates.householdId, params.id)); + for (const template of saved) if (template.nodes.some(node => node.value.assignees.includes(params.userId))) { + await tx.update(templates).set({ version: template.version + 1, nodes: template.nodes.map(node => ({ ...node, value: { ...node.value, assignees: node.value.assignees.filter(id => id !== params.userId) } })) }).where(eq(templates.id, template.id)); + } } await tx.insert(securityEvents).values({ actorId: current.user.id, subjectId: target.userId, action: role ? 'household_role_changed' : 'household_member_removed' }); }); diff --git a/apps/api/src/app.ts b/apps/api/src/app.ts index 11a8dd2..75e3d40 100644 --- a/apps/api/src/app.ts +++ b/apps/api/src/app.ts @@ -1,14 +1,19 @@ +import { registerSearchRoutes } from './content/search.js'; +import { registerContentRoutes } from './content/routes.js'; +import { registerLifecycleRoutes } from './lifecycle/routes.js'; +import { registerPlanningRoutes } from './planning/routes.js'; import { registerTaskRoutes } from './tasks/routes.js'; import { registerAccountRoutes } from './accounts/routes.js'; import type { AccountService } from './accounts/service.js'; import type { MailService } from './accounts/mail.js'; import Fastify, { LogController } from 'fastify'; import swagger from '@fastify/swagger'; -import { jsonSchemaTransform, serializerCompiler, validatorCompiler, type ZodTypeProvider } from 'fastify-type-provider-zod'; +import { jsonSchemaTransform, jsonSchemaTransformObject, serializerCompiler, validatorCompiler, type ZodTypeProvider } from 'fastify-type-provider-zod'; import { healthSchema, versionSchema } from '@tendly/shared'; import { logRedaction } from './logging.js'; interface AppOptions { + filesPath?: string; accounts?: { service: AccountService; mail: MailService }; checkDatabase: () => Promise; closeDatabase?: () => Promise; @@ -23,6 +28,7 @@ export async function buildApp(options: AppOptions) { await app.register(swagger, { openapi: { info: { title: 'Tendly API', version: options.version ?? '0.0.0-dev' } }, transform: jsonSchemaTransform, + transformObject: jsonSchemaTransformObject, }); // Do not log URL query strings: later recovery links carry single-use secrets. app.addHook('onResponse', async (request, reply) => { @@ -39,8 +45,12 @@ export async function buildApp(options: AppOptions) { }); app.get('/api/v1/version', { schema: { operationId: 'getVersion', response: { 200: versionSchema } } }, async () => ({ name: 'Tendly' as const, version: options.version ?? '0.0.0-dev' })); if (options.accounts) { - await registerAccountRoutes(app, options.accounts.service, options.accounts.mail); + await registerAccountRoutes(app, options.accounts.service, options.accounts.mail, options.filesPath); await registerTaskRoutes(app, options.accounts.service); + await registerPlanningRoutes(app, options.accounts.service); + await registerLifecycleRoutes(app, options.accounts.service); + await registerContentRoutes(app, options.accounts.service, options.filesPath ?? '/data/attachments'); + await registerSearchRoutes(app, options.accounts.service); } await app.ready(); return app; diff --git a/apps/api/src/content/cleanup.ts b/apps/api/src/content/cleanup.ts new file mode 100644 index 0000000..b48315a --- /dev/null +++ b/apps/api/src/content/cleanup.ts @@ -0,0 +1,25 @@ +import { eq, isNull } from 'drizzle-orm'; +import { fileIsReferenced } from './references.js'; +import { users, households } from '../accounts/schema.js'; +import { readdir, stat, unlink } from 'node:fs/promises'; +import { join } from 'node:path'; +import type { Database } from '../accounts/database.js'; +import { files } from './schema.js'; +export async function cleanOrphanFiles(db: Database, directory: string) { + // A template or copied rich-text document may still reference an image after its original task is deleted. + for (const file of await db.select().from(files).where(isNull(files.taskId))) { + await db.transaction(async tx => { + const [household] = await tx.select().from(households).where(eq(households.id, file.householdId)).for('update'); + if (household && !await fileIsReferenced(tx, household.id, file.id)) await tx.delete(files).where(eq(files.id, file.id)); + }); + } + const known = new Set((await db.select({ id: files.id }).from(files)).map(f => f.id)); + for (const user of await db.select({ avatar: users.avatar }).from(users)) if (user.avatar) known.add(user.avatar); + const names = await readdir(directory).catch(() => [] as string[]); + for (const name of names) { + if (!/^[0-9a-f-]{36}$/i.test(name) || known.has(name)) continue; + const path = join(directory, name), info = await stat(path).catch(() => null); + // Uploads write bytes before committing metadata. A grace period avoids racing an in-flight upload. + if (info?.isFile() && Date.now() - info.mtimeMs > 86400000) await unlink(path).catch(() => {}); + } +} diff --git a/apps/api/src/content/references.ts b/apps/api/src/content/references.ts new file mode 100644 index 0000000..fa46af8 --- /dev/null +++ b/apps/api/src/content/references.ts @@ -0,0 +1,10 @@ +import { sql } from 'drizzle-orm'; +import type { QueryDatabase } from '../accounts/database.js'; +export async function fileIsReferenced(db: QueryDatabase, householdId: string, id: string) { + const result = await db.execute(sql`SELECT 1 FROM ( + SELECT id FROM tasks WHERE household_id = ${householdId} AND position(${id} in description) > 0 + UNION ALL SELECT id FROM task_comments WHERE household_id = ${householdId} AND position(${id} in body) > 0 + UNION ALL SELECT id FROM task_templates WHERE household_id = ${householdId} AND position(${id} in nodes::text) > 0 + ) references_to_file LIMIT 1`); + return result.rows.length > 0; +} diff --git a/apps/api/src/content/rich-text.ts b/apps/api/src/content/rich-text.ts new file mode 100644 index 0000000..068ef7a --- /dev/null +++ b/apps/api/src/content/rich-text.ts @@ -0,0 +1,29 @@ +import { z } from 'zod'; +import { readRichText, type RichNode } from '@tendly/shared'; +import { AccountError } from '../accounts/errors.js'; +export function inspectRichText(value: string) { + let root: RichNode; + try { root = readRichText(value); } catch { throw new AccountError('invalid_rich_text'); } + const mentions = new Set(), images = new Set(); + const stack = [{ node: root, depth: 0 }], text: string[] = []; + let count = 0; + while (stack.length) { + const { node, depth } = stack.pop()!; + if (++count > 10000 || depth > 30 || !node || typeof node !== 'object' || !['doc', 'paragraph', 'text', 'heading', 'bulletList', 'orderedList', 'listItem', 'taskList', 'taskItem', 'blockquote', 'codeBlock', 'hardBreak', 'horizontalRule', 'image', 'mention'].includes(node.type)) throw new AccountError('invalid_rich_text'); + if (node.text !== undefined) { if (typeof node.text !== 'string') throw new AccountError('invalid_rich_text'); text.push(node.text); } + if (node.type === 'mention') { if (typeof node.attrs?.id !== 'string') throw new AccountError('invalid_rich_text'); mentions.add(node.attrs.id); } + if (node.type === 'image') { const match = typeof node.attrs?.src === 'string' && node.attrs.src.match(/^\/api\/v1\/households\/([0-9a-f-]{36})\/files\/([0-9a-f-]{36})$/i); if (!match || !z.uuid().safeParse(match[1]).success || !z.uuid().safeParse(match[2]).success) throw new AccountError('invalid_rich_text'); images.add(match[2]!); } + if (node.attrs && Object.values(node.attrs).some(v => v !== null && !['string', 'boolean', 'number'].includes(typeof v))) throw new AccountError('invalid_rich_text'); + if (node.attrs && Object.keys(node.attrs).some(key => !['level', 'start', 'checked', 'language', 'src', 'alt', 'title', 'id', 'label', 'mentionSuggestionChar', 'width', 'height'].includes(key))) throw new AccountError('invalid_rich_text'); + if (node.marks !== undefined && !Array.isArray(node.marks)) throw new AccountError('invalid_rich_text'); + for (const mark of node.marks ?? []) { + if (!mark || typeof mark !== 'object' || !['bold', 'italic', 'strike', 'underline', 'code', 'link'].includes(mark.type)) throw new AccountError('invalid_rich_text'); + if (mark.type === 'link' && (typeof mark.attrs?.href !== 'string' || !/^(https?:\/\/|mailto:)/i.test(mark.attrs.href))) throw new AccountError('invalid_rich_text'); + if (mark.attrs && Object.keys(mark.attrs).some(k => !['href', 'target', 'rel', 'class'].includes(k))) throw new AccountError('invalid_rich_text'); + if (mark.attrs?.target && !['_blank', '_self'].includes(String(mark.attrs.target))) throw new AccountError('invalid_rich_text'); + } + if (node.content !== undefined && !Array.isArray(node.content)) throw new AccountError('invalid_rich_text'); + for (const child of node.content ?? []) stack.push({ node: child, depth: depth + 1 }); + } + return { mentions: [...mentions], images: [...images], text: text.reverse().join(' ') }; +} diff --git a/apps/api/src/content/routes.ts b/apps/api/src/content/routes.ts new file mode 100644 index 0000000..7a4c9de --- /dev/null +++ b/apps/api/src/content/routes.ts @@ -0,0 +1,22 @@ +import type { FastifyInstance, FastifyRequest } from 'fastify'; +import type { ZodTypeProvider } from 'fastify-type-provider-zod'; +import { z } from 'zod'; +import { taskContentSchema, fileSchema, okSchema } from '@tendly/shared'; +import type { AccountService } from '../accounts/service.js'; +import { signedIn } from '../accounts/access.js'; +import { ContentService } from './service.js'; +const scope = z.object({ householdId: z.uuid() }), item = scope.extend({ id: z.uuid() }), task = scope.extend({ taskId: z.uuid() }); +export async function registerContentRoutes(server: FastifyInstance, accounts: AccountService, directory: string) { + const app = server.withTypeProvider(), service = new ContentService(accounts.db, directory); + const actor = async (r: FastifyRequest) => { const current = await accounts.findSession(r.cookies[accounts.origin.startsWith('https:') ? '__Host-tendly' : 'tendly_session']); signedIn(current); return current; }; + app.get('/api/v1/households/:householdId/tasks/:taskId/content', { schema: { params: task, response: { 200: taskContentSchema } } }, async r => service.list(await actor(r), r.params.householdId, r.params.taskId)); + app.post('/api/v1/households/:householdId/tasks/:taskId/comments', { schema: { params: task, body: z.object({ body: z.string().min(1).max(100000) }), response: { 200: okSchema } } }, async r => { await service.comment(await actor(r), r.params.householdId, r.params.taskId, r.body.body); return { ok: true as const }; }); + app.put('/api/v1/households/:householdId/tasks/:taskId/comments/:id', { schema: { params: task.extend({ id: z.uuid() }), body: z.object({ body: z.string().min(1).max(100000), baseVersion: z.number().int().min(1) }), response: { 200: okSchema } } }, async r => { await service.comment(await actor(r), r.params.householdId, r.params.taskId, r.body.body, r.params.id, r.body.baseVersion); return { ok: true as const }; }); + app.delete('/api/v1/households/:householdId/comments/:id', { schema: { params: item, body: z.object({ baseVersion: z.number().int().min(1) }), response: { 200: okSchema } } }, async r => { await service.removeComment(await actor(r), r.params.householdId, r.params.id, r.body.baseVersion); return { ok: true as const }; }); + app.post('/api/v1/households/:householdId/tasks/:taskId/files', { bodyLimit: 23 * 1024 * 1024, schema: { params: task, body: z.object({ name: z.string().min(1).max(255).refine(name => [...name].every(char => char.charCodeAt(0) >= 32 && char.charCodeAt(0) !== 127)), base64: z.string().max(23 * 1024 * 1024), commentId: z.uuid().nullable().optional() }), response: { 200: fileSchema } } }, async r => service.upload(await actor(r), r.params.householdId, r.params.taskId, r.body)); + app.get('/api/v1/households/:householdId/files/:id', { schema: { params: item } }, async (r, reply) => { + const { file, bytes } = await service.download(await actor(r), r.params.householdId, r.params.id); + return reply.header('Cache-Control', 'private, no-store').header('X-Content-Type-Options', 'nosniff').header('Content-Security-Policy', "default-src 'none'; sandbox").header('Content-Disposition', `${file.mime.startsWith('image/') ? 'inline' : 'attachment'}; filename*=UTF-8''${encodeURIComponent(file.name)}`).type(file.mime).send(bytes); + }); + app.delete('/api/v1/households/:householdId/files/:id', { schema: { params: item, body: z.object({}), response: { 200: okSchema } } }, async r => { await service.removeFile(await actor(r), r.params.householdId, r.params.id); return { ok: true as const }; }); +} diff --git a/apps/api/src/content/schema.ts b/apps/api/src/content/schema.ts new file mode 100644 index 0000000..5813c91 --- /dev/null +++ b/apps/api/src/content/schema.ts @@ -0,0 +1,5 @@ +import { pgTable, uuid, text, integer, timestamp, index } from 'drizzle-orm/pg-core'; +import { households, users } from '../accounts/schema.js'; +import { tasks } from '../tasks/schema.js'; +export const comments = pgTable('task_comments', { id: uuid('id').primaryKey().defaultRandom(), householdId: uuid('household_id').notNull().references(() => households.id, { onDelete: 'cascade' }), taskId: uuid('task_id').notNull().references(() => tasks.id, { onDelete: 'cascade' }), authorId: uuid('author_id').references(() => users.id, { onDelete: 'set null' }), body: text('body').notNull(), version: integer('version').notNull().default(1), createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(), updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow() }, t => [index('comment_task_idx').on(t.taskId, t.createdAt)]); +export const files = pgTable('task_files', { id: uuid('id').primaryKey().defaultRandom(), householdId: uuid('household_id').notNull().references(() => households.id, { onDelete: 'cascade' }), taskId: uuid('task_id').references(() => tasks.id, { onDelete: 'set null' }), commentId: uuid('comment_id').references(() => comments.id, { onDelete: 'set null' }), name: text('name').notNull(), mime: text('mime').notNull(), size: integer('size').notNull(), createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow() }, t => [index('file_task_idx').on(t.taskId)]); diff --git a/apps/api/src/content/search.ts b/apps/api/src/content/search.ts new file mode 100644 index 0000000..6e4f5d5 --- /dev/null +++ b/apps/api/src/content/search.ts @@ -0,0 +1,30 @@ +import type { FastifyInstance, FastifyRequest } from 'fastify'; +import type { ZodTypeProvider } from 'fastify-type-provider-zod'; +import { z } from 'zod'; +import { eq } from 'drizzle-orm'; +import { taskSchema, entitySchema, filterAstSchema, allFilter } from '@tendly/shared'; +import type { AccountService } from '../accounts/service.js'; +import { signedIn } from '../accounts/access.js'; +import { TaskService } from '../tasks/service.js'; +import { entities } from '../tasks/schema.js'; +import { comments } from './schema.js'; +import { inspectRichText } from './rich-text.js'; +import { filterTasks } from '../planning/filter.js'; +export async function registerSearchRoutes(server: FastifyInstance, accounts: AccountService) { + const app = server.withTypeProvider(), service = new TaskService(accounts.db); + const actor = async (r: FastifyRequest) => { const current = await accounts.findSession(r.cookies[accounts.origin.startsWith('https:') ? '__Host-tendly' : 'tendly_session']); signedIn(current); return current; }; + app.post('/api/v1/households/:householdId/search', { schema: { params: z.object({ householdId: z.uuid() }), body: z.object({ query: z.string().max(200), definition: filterAstSchema.nullable(), currentPlace: z.uuid().nullable(), offset: z.number().int().min(0).default(0) }), response: { 200: z.object({ tasks: z.array(z.object({ task: taskSchema, archived: z.boolean() })), entities: z.array(entitySchema), count: z.number().int(), nextOffset: z.number().nullable() }) } } }, async r => { + const current = await actor(r), householdId = r.params.householdId; + return accounts.db.transaction(async tx => { + const household = await service.scope(tx, current, householdId), graph = await service.graph(tx, householdId, household.timezone); + const query = r.body.query.trim().toLocaleLowerCase(), matches = (text: string) => text.toLocaleLowerCase().includes(query); + const catalog = await tx.select().from(entities).where(eq(entities.householdId, householdId)); + const matchedEntities = catalog.filter(e => matches(e.name) || matches(e.description)), ids = new Set(matchedEntities.map(e => e.id)); + const matchedComments = new Set((await tx.select().from(comments).where(eq(comments.householdId, householdId))).filter(c => matches(inspectRichText(c.body).text)).map(c => c.taskId)); + const candidates = graph.rows.filter(row => !row.trashedAt).map(row => graph.task(row.id)).filter(task => matches(task.title) || matches(inspectRichText(task.description).text) || matchedComments.has(task.id) || !!task.epicId && ids.has(task.epicId) || task.tags.some(id => ids.has(id))); + const found = await filterTasks(tx, candidates, [r.body.definition ?? allFilter], { userId: current.user.id, currentPlace: r.body.currentPlace, timezone: household.timezone }); + const archived = new Set(graph.rows.filter(row => row.archivedAt).map(row => row.id)); + return { tasks: found.slice(r.body.offset, r.body.offset + 50).map(task => ({ task, archived: archived.has(task.id) })), entities: matchedEntities.map(e => entitySchema.parse(e)), count: found.length, nextOffset: found.length > r.body.offset + 50 ? r.body.offset + 50 : null }; + }, { isolationLevel: 'repeatable read' }); + }); +} diff --git a/apps/api/src/content/service.ts b/apps/api/src/content/service.ts new file mode 100644 index 0000000..46a3cb7 --- /dev/null +++ b/apps/api/src/content/service.ts @@ -0,0 +1,90 @@ +import { fileIsReferenced } from './references.js'; +import { inspectRichText } from './rich-text.js'; +import { randomUUID } from 'node:crypto'; +import { mkdir, writeFile, unlink, readFile } from 'node:fs/promises'; +import { join } from 'node:path'; +import { and, asc, eq } from 'drizzle-orm'; +import type { Database } from '../accounts/database.js'; +import type { Actor } from '../accounts/access.js'; +import { users } from '../accounts/schema.js'; +import { AccountError } from '../accounts/errors.js'; +import { TaskService } from '../tasks/service.js'; +import { taskActivities } from '../tasks/schema.js'; +import { comments, files } from './schema.js'; +export class ContentService { + readonly tasks: TaskService; + constructor(readonly db: Database, readonly directory: string) { this.tasks = new TaskService(db); } + async list(actor: Actor, householdId: string, taskId: string) { + return this.db.transaction(async tx => { + const household = await this.tasks.scope(tx, actor, householdId); + await this.tasks.get(tx, householdId, taskId, household.timezone); + const commentRows = await tx.select({ comment: comments, author: users.name }).from(comments).leftJoin(users, eq(users.id, comments.authorId)).where(and(eq(comments.householdId, householdId), eq(comments.taskId, taskId))).orderBy(asc(comments.createdAt)); + const activity = await tx.select({ activity: taskActivities, actor: users.name }).from(taskActivities).leftJoin(users, eq(users.id, taskActivities.actorId)).where(eq(taskActivities.taskId, taskId)).orderBy(asc(taskActivities.createdAt)); + const fileRows = await tx.select().from(files).where(and(eq(files.householdId, householdId), eq(files.taskId, taskId))); + return { comments: commentRows.map(({ comment: c, author }) => ({ ...c, author: author ?? '—', createdAt: c.createdAt.toISOString(), updatedAt: c.updatedAt.toISOString() })), files: fileRows.map(f => ({ ...f, createdAt: f.createdAt.toISOString() })), activity: activity.map(({ activity: a, actor }) => ({ ...a, actor, createdAt: a.createdAt.toISOString() })) }; + }, { isolationLevel: 'repeatable read' }); + } + async comment(actor: Actor, householdId: string, taskId: string, body: string, id?: string, version?: number) { + await this.db.transaction(async tx => { + const household = await this.tasks.scope(tx, actor, householdId, true); + await this.tasks.get(tx, householdId, taskId, household.timezone); + await this.tasks.validateContent(tx, householdId, body); + const content = inspectRichText(body); + if (!content.text.trim() && !content.images.length && !content.mentions.length) throw new AccountError('empty_comment'); + if (id) { + const [old] = await tx.select().from(comments).where(and(eq(comments.id, id), eq(comments.householdId, householdId), eq(comments.taskId, taskId))); + if (!old) throw new AccountError('comment_not_found', 404); + if (old.authorId !== actor.user.id) throw new AccountError('comment_author_required', 403); + if (old.version !== version) throw new AccountError('planning_conflict', 409); + await tx.update(comments).set({ body, version: old.version + 1, updatedAt: new Date() }).where(eq(comments.id, id)); + } else await tx.insert(comments).values({ taskId, householdId, authorId: actor.user.id, body }); + }); + } + async removeComment(actor: Actor, householdId: string, id: string, version: number) { + await this.db.transaction(async tx => { + await this.tasks.scope(tx, actor, householdId, true); + const [old] = await tx.select().from(comments).where(and(eq(comments.id, id), eq(comments.householdId, householdId))); + if (!old) throw new AccountError('comment_not_found', 404); + if (old.authorId !== actor.user.id) throw new AccountError('comment_author_required', 403); + if (old.version !== version) throw new AccountError('planning_conflict', 409); + await tx.delete(comments).where(eq(comments.id, id)); + }); + } + async upload(actor: Actor, householdId: string, taskId: string, input: { name: string; base64: string; commentId?: string | null | undefined }) { + const bytes = Buffer.from(input.base64, 'base64'); + if (!bytes.length || bytes.length > 16 * 1024 * 1024 || bytes.toString('base64') !== input.base64) throw new AccountError('invalid_file'); + const mime = bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) ? 'image/png' : bytes.subarray(0, 3).equals(Buffer.from([255, 216, 255])) ? 'image/jpeg' : ['GIF87a', 'GIF89a'].includes(bytes.subarray(0, 6).toString()) ? 'image/gif' : bytes.subarray(0, 4).toString() === 'RIFF' && bytes.subarray(8, 12).toString() === 'WEBP' ? 'image/webp' : 'application/octet-stream'; + const id = randomUUID(); + try { + return await this.db.transaction(async tx => { + const household = await this.tasks.scope(tx, actor, householdId, true); + await this.tasks.get(tx, householdId, taskId, household.timezone); + if (input.commentId) { + const [comment] = await tx.select().from(comments).where(and(eq(comments.id, input.commentId), eq(comments.taskId, taskId), eq(comments.householdId, householdId))); + if (!comment || comment.authorId !== actor.user.id) throw new AccountError('comment_author_required', 403); + } + await mkdir(this.directory, { recursive: true, mode: 0o700 }); + await writeFile(join(this.directory, id), bytes, { flag: 'wx', mode: 0o600 }); + const [file] = await tx.insert(files).values({ id, householdId, taskId, name: input.name, mime, size: bytes.length, commentId: input.commentId ?? null }).returning(); + return { ...file!, createdAt: file!.createdAt.toISOString() }; + }); + } catch (error) { await unlink(join(this.directory, id)).catch(() => {}); throw error; } + } + async download(actor: Actor, householdId: string, id: string) { + await this.tasks.scope(this.db, actor, householdId); + const [file] = await this.db.select().from(files).where(and(eq(files.id, id), eq(files.householdId, householdId))); + if (!file) throw new AccountError('file_not_found', 404); + try { return { file, bytes: await readFile(join(this.directory, file.id)) }; } catch { throw new AccountError('file_not_found', 404); } + } + async removeFile(actor: Actor, householdId: string, id: string) { + await this.db.transaction(async tx => { + await this.tasks.scope(tx, actor, householdId, true); + const [file] = await tx.select().from(files).where(and(eq(files.id, id), eq(files.householdId, householdId))); + if (!file) throw new AccountError('file_not_found', 404); + if (await fileIsReferenced(tx, householdId, id)) throw new AccountError('file_in_use'); + await tx.delete(files).where(eq(files.id, id)); + }); + // Metadata commits first. A crash may leave an orphan file, never a live record pointing at deleted bytes. + await unlink(join(this.directory, id)).catch(() => {}); + } +} diff --git a/apps/api/src/db/schema.ts b/apps/api/src/db/schema.ts index 639e9c8..c0e7805 100644 --- a/apps/api/src/db/schema.ts +++ b/apps/api/src/db/schema.ts @@ -6,3 +6,6 @@ export const installation = pgTable('installation', { }); export * from '../accounts/schema.js'; export * from '../tasks/schema.js'; +export * from '../planning/schema.js'; +export * from '../lifecycle/schema.js'; +export * from '../content/schema.js'; diff --git a/apps/api/src/lifecycle/recurrence.test.ts b/apps/api/src/lifecycle/recurrence.test.ts new file mode 100644 index 0000000..0076f85 --- /dev/null +++ b/apps/api/src/lifecycle/recurrence.test.ts @@ -0,0 +1,20 @@ +import { expect, it } from 'vitest'; +import { occurrenceDate, dueOccurrences, materializeNodes } from './recurrence.js'; +import { taskFields } from '@tendly/shared'; +it('clamps from the original calendar anchor and materializes on the configured lead day', () => { + const monthly = { anchor: '2027-01-31', interval: 1, unit: 'months' as const, leadDays: 14, enabled: true }; + expect([0, 1, 2].map(i => occurrenceDate(monthly, i))).toEqual(['2027-01-31', '2027-02-28', '2027-03-31']); + expect(occurrenceDate({ ...monthly, anchor: '2024-02-29', unit: 'years' }, 4)).toBe('2028-02-29'); + const yearly = { ...monthly, anchor: '2027-10-01', unit: 'years' as const }; + expect([...dueOccurrences(yearly, '2027-09-16')]).toEqual([]); + expect([...dueOccurrences(yearly, '2027-09-17')]).toEqual(['2027-10-01']); + expect(occurrenceDate({ ...monthly, interval: 3, unit: 'weeks' }, 2)).toBe('2027-03-14'); +}); +it('remaps internal dependencies while preserving external blockers and relative dates', () => { + const value = taskFields.parse({ parentId: null, inherit: [], placeExclusions: [], resourceExclusions: [], tagExclusions: [], blockers: [], related: [], title: 'Root', description: '', column: 'todo', epicId: null, high: false, size: null, estimateMinutes: null, startDate: null, startTime: null, deadlineDate: null, deadlineTime: null, assignees: [], places: [], resources: [], tags: [] }); + let counter = 0; + const result = materializeNodes([{ sourceId: 'root', value, startOffset: 0, deadlineOffset: 14 }, { sourceId: 'a', value: { ...value, parentId: 'root' }, startOffset: null, deadlineOffset: null }, { sourceId: 'b', value: { ...value, parentId: 'root', blockers: ['a', 'external'] }, startOffset: 2, deadlineOffset: 7 }], '2027-10-01', () => String(++counter)); + expect(result[2]!.value.blockers).toEqual(['2', 'external']); + expect(result[2]!.value.parentId).toBe('1'); + expect(result[0]!.value.deadlineDate).toBe('2027-10-15'); +}); diff --git a/apps/api/src/lifecycle/recurrence.ts b/apps/api/src/lifecycle/recurrence.ts new file mode 100644 index 0000000..80a53d6 --- /dev/null +++ b/apps/api/src/lifecycle/recurrence.ts @@ -0,0 +1,27 @@ +import { Temporal } from '@js-temporal/polyfill'; +import type { Recurrence, TemplateNode } from '@tendly/shared'; +export function occurrenceDate(schedule: Recurrence, index: number) { + // Always add to the original anchor: Jan 31 → Feb 28 → Mar 31, without drift. + return Temporal.PlainDate.from(schedule.anchor).add({ [schedule.unit]: schedule.interval * index }, { overflow: 'constrain' }).toString(); +} +export function* dueOccurrences(schedule: Recurrence, today: string) { + if (!schedule.enabled) return; + const horizon = Temporal.PlainDate.from(today).add({ days: schedule.leadDays }).toString(); + for (let i = 0; ; i++) { + const date = occurrenceDate(schedule, i); + if (date > horizon) break; + yield date; + } +} +export function materializeNodes(nodes: TemplateNode[], date: string, id: () => string) { + const mapping = new Map(nodes.map(n => [n.sourceId, id()])); + return nodes.map(node => ({ id: mapping.get(node.sourceId)!, value: { ...node.value, + parentId: node.value.parentId ? mapping.get(node.value.parentId) ?? null : null, + blockers: node.value.blockers.map(target => mapping.get(target) ?? target), + related: node.value.related.map(target => mapping.get(target) ?? target), + startTime: node.startOffset === null ? null : node.value.startTime, + deadlineTime: node.deadlineOffset === null ? null : node.value.deadlineTime, + startDate: node.startOffset === null ? null : Temporal.PlainDate.from(date).add({ days: node.startOffset }).toString(), + deadlineDate: node.deadlineOffset === null ? null : Temporal.PlainDate.from(date).add({ days: node.deadlineOffset }).toString(), + } })); +} diff --git a/apps/api/src/lifecycle/routes.ts b/apps/api/src/lifecycle/routes.ts new file mode 100644 index 0000000..156a82b --- /dev/null +++ b/apps/api/src/lifecycle/routes.ts @@ -0,0 +1,22 @@ +import type { FastifyInstance, FastifyRequest } from 'fastify'; +import type { ZodTypeProvider } from 'fastify-type-provider-zod'; +import { z } from 'zod'; +import { templateSchema, templateInputSchema, recurrenceSchema, taskSchema, lifecycleSettingsSchema, lifecycleItemSchema, okSchema } from '@tendly/shared'; +import type { AccountService } from '../accounts/service.js'; +import { signedIn } from '../accounts/access.js'; +import { TemplateService } from './templates.js'; +import { LifecycleService } from './service.js'; +const scope = z.object({ householdId: z.uuid() }), item = scope.extend({ id: z.uuid() }); +export async function registerLifecycleRoutes(server: FastifyInstance, accounts: AccountService) { + const app = server.withTypeProvider(), templates = new TemplateService(accounts.db), lifecycle = new LifecycleService(accounts.db); + const actor = async (request: FastifyRequest) => { const value = await accounts.findSession(request.cookies[accounts.origin.startsWith('https:') ? '__Host-tendly' : 'tendly_session']); signedIn(value); return value; }; + app.get('/api/v1/households/:householdId/templates', { schema: { params: scope, response: { 200: z.array(templateSchema) } } }, async r => templates.list(await actor(r), r.params.householdId)); + app.post('/api/v1/households/:householdId/templates', { schema: { params: scope, body: z.object({ taskId: z.uuid(), name: z.string().trim().min(1).max(100), recurrence: recurrenceSchema.nullable() }), response: { 200: templateSchema } } }, async r => templates.capture(await actor(r), r.params.householdId, r.body.taskId, r.body.name, r.body.recurrence)); + app.put('/api/v1/households/:householdId/templates/:id', { schema: { params: item, body: templateInputSchema.extend({ baseVersion: z.number().int().min(1) }), response: { 200: templateSchema } } }, async r => templates.save(await actor(r), r.params.householdId, r.body, r.params.id, r.body.baseVersion)); + app.post('/api/v1/households/:householdId/templates/:id/create', { schema: { params: item, body: z.object({ date: z.iso.date() }), response: { 200: taskSchema } } }, async r => templates.createInstance(await actor(r), r.params.householdId, r.params.id, r.body.date)); + app.delete('/api/v1/households/:householdId/templates/:id', { schema: { params: item, body: z.object({ baseVersion: z.number().int().min(1) }), response: { 200: okSchema } } }, async r => { await templates.remove(await actor(r), r.params.householdId, r.params.id, r.body.baseVersion); return { ok: true as const }; }); + app.get('/api/v1/households/:householdId/lifecycle', { schema: { params: scope, querystring: z.object({ kind: z.enum(['archive', 'trash']) }), response: { 200: z.array(lifecycleItemSchema) } } }, async r => lifecycle.list(await actor(r), r.params.householdId, r.query.kind)); + app.post('/api/v1/households/:householdId/tasks/:id/lifecycle', { schema: { params: item, body: z.object({ baseVersion: z.number().int().min(1), action: z.enum(['archive', 'unarchive', 'trash', 'restore', 'delete']), confirmed: z.boolean().default(false) }), response: { 200: okSchema } } }, async r => { await lifecycle.change(await actor(r), r.params.householdId, r.params.id, r.body.baseVersion, r.body.action, r.body.confirmed); return { ok: true as const }; }); + app.get('/api/v1/households/:householdId/lifecycle-settings', { schema: { params: scope, response: { 200: lifecycleSettingsSchema } } }, async r => { await lifecycle.tasks.scope(accounts.db, await actor(r), r.params.householdId); return lifecycle.settings(r.params.householdId); }); + app.put('/api/v1/households/:householdId/lifecycle-settings', { schema: { params: scope, body: lifecycleSettingsSchema, response: { 200: lifecycleSettingsSchema } } }, async r => lifecycle.saveSettings(await actor(r), r.params.householdId, r.body)); +} diff --git a/apps/api/src/lifecycle/schema.ts b/apps/api/src/lifecycle/schema.ts new file mode 100644 index 0000000..f66651b --- /dev/null +++ b/apps/api/src/lifecycle/schema.ts @@ -0,0 +1,8 @@ +import { pgTable, uuid, text, integer, jsonb, timestamp, primaryKey } from 'drizzle-orm/pg-core'; +import type { Recurrence, TemplateNode } from '@tendly/shared'; +import { households } from '../accounts/schema.js'; +export const templates = pgTable('task_templates', { + id: uuid('id').primaryKey().defaultRandom(), householdId: uuid('household_id').notNull().references(() => households.id, { onDelete: 'cascade' }), name: text('name').notNull(), version: integer('version').notNull().default(1), nodes: jsonb('nodes').$type().notNull(), recurrence: jsonb('recurrence').$type(), +}); +export const occurrences = pgTable('task_occurrences', { templateId: uuid('template_id').notNull().references(() => templates.id, { onDelete: 'cascade' }), date: text('date').notNull(), rootId: uuid('root_id').notNull(), createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow() }, t => [primaryKey({ columns: [t.templateId, t.date] })]); +export const lifecycleSettings = pgTable('lifecycle_settings', { householdId: uuid('household_id').primaryKey().references(() => households.id, { onDelete: 'cascade' }), version: integer('version').notNull().default(1), archiveDays: integer('archive_days').default(30), trashDays: integer('trash_days').notNull().default(30) }); diff --git a/apps/api/src/lifecycle/service.ts b/apps/api/src/lifecycle/service.ts new file mode 100644 index 0000000..3a89145 --- /dev/null +++ b/apps/api/src/lifecycle/service.ts @@ -0,0 +1,71 @@ +import { and, eq, inArray, isNull, sql } from 'drizzle-orm'; +import type { Database, Transaction } from '../accounts/database.js'; +import type { Actor } from '../accounts/access.js'; +import { AccountError } from '../accounts/errors.js'; +import { TaskService } from '../tasks/service.js'; +import { tasks, taskActivities, taskDependencies } from '../tasks/schema.js'; +import { lifecycleSettings } from './schema.js'; +export class LifecycleService { + readonly tasks: TaskService; + constructor(readonly db: Database) { this.tasks = new TaskService(db); } + async settings(householdId: string, db = this.db) { + const [row] = await db.select().from(lifecycleSettings).where(eq(lifecycleSettings.householdId, householdId)); + return row ? { version: row.version, archiveDays: row.archiveDays, trashDays: row.trashDays } : { version: 0, archiveDays: 30, trashDays: 30 }; + } + async saveSettings(actor: Actor, householdId: string, input: { version: number; archiveDays: number | null; trashDays: number }) { + return this.db.transaction(async tx => { + await this.tasks.scope(tx, actor, householdId, true, true); + const [old] = await tx.select().from(lifecycleSettings).where(eq(lifecycleSettings.householdId, householdId)); + if ((old?.version ?? 0) !== input.version) throw new AccountError('planning_conflict', 409); + const value = { ...input, version: input.version + 1 }; + await tx.insert(lifecycleSettings).values({ ...value, householdId }).onConflictDoUpdate({ target: lifecycleSettings.householdId, set: value }); + return value; + }); + } + async list(actor: Actor, householdId: string, kind: 'archive' | 'trash') { + await this.tasks.scope(this.db, actor, householdId); + return (await this.db.select().from(tasks).where(eq(tasks.householdId, householdId))).filter(row => kind === 'trash' ? !!row.trashedAt : !!row.archivedAt && !row.trashedAt).map(row => ({ id: row.id, title: row.title, version: row.version, parentId: row.parentId, archivedAt: row.archivedAt?.toISOString() ?? null, trashedAt: row.trashedAt?.toISOString() ?? null })); + } + async subtree(tx: Transaction, householdId: string, id: string) { + const result = await tx.execute<{ id: string }>(sql`WITH RECURSIVE tree AS (SELECT id FROM tasks WHERE id = ${id} AND household_id = ${householdId} UNION SELECT t.id FROM tasks t JOIN tree p ON t.parent_id = p.id WHERE t.household_id = ${householdId}) SELECT id FROM tree`); + return result.rows.map(r => r.id); + } + async permanentlyDelete(tx: Transaction, householdId: string, ids: string[]) { + if (!ids.length) return; + // Detach only nodes being removed so restrictive parent FKs cannot depend on row deletion order. + await tx.update(tasks).set({ parentId: null }).where(and(eq(tasks.householdId, householdId), inArray(tasks.id, ids))); + await tx.delete(tasks).where(and(eq(tasks.householdId, householdId), inArray(tasks.id, ids))); + } + async change(actor: Actor, householdId: string, id: string, version: number, action: 'archive' | 'unarchive' | 'trash' | 'restore' | 'delete', confirmed: boolean) { + await this.db.transaction(async tx => { + await this.tasks.scope(tx, actor, householdId, true, action === 'delete'); + const [row] = await tx.select().from(tasks).where(and(eq(tasks.id, id), eq(tasks.householdId, householdId))); + if (!row) throw new AccountError('task_not_found', 404); + if (row.version !== version) throw new AccountError('planning_conflict', 409); + if (row.trashedAt && !['restore', 'delete'].includes(action)) throw new AccountError('task_not_found', 404); + let ids = action === 'trash' || action === 'delete' ? await this.subtree(tx, householdId, id) : [id]; + if (action === 'trash' || action === 'delete') { + const dependents = await tx.select({ id: tasks.id }).from(taskDependencies).innerJoin(tasks, eq(tasks.id, taskDependencies.blockedTaskId)).where(and(eq(tasks.householdId, householdId), inArray(taskDependencies.blockingTaskId, ids), isNull(tasks.trashedAt))); + if (!confirmed && dependents.some(d => !ids.includes(d.id))) throw new AccountError('confirm_dependent_deletion', 409); + } + if (action === 'delete') { await this.permanentlyDelete(tx, householdId, ids); return; } + if (action === 'restore') { + if (!row.trashedAt) return; + const batch = row.trashRootId ?? row.id; + ids = (await tx.select({ id: tasks.id }).from(tasks).where(and(eq(tasks.householdId, householdId), eq(tasks.trashRootId, batch)))).map(r => r.id); + if (!ids.length) ids = [id]; + const roots = await tx.select().from(tasks).where(and(eq(tasks.householdId, householdId), inArray(tasks.id, ids))); + const parents = roots.flatMap(r => r.parentId && !ids.includes(r.parentId) ? [r.parentId] : []); + if (parents.length && (await tx.select().from(tasks).where(inArray(tasks.id, parents))).some(p => p.trashedAt)) throw new AccountError('restore_parent_first'); + } + const affected = await tx.select().from(tasks).where(and(eq(tasks.householdId, householdId), inArray(tasks.id, ids))); + for (const task of affected) { + if (action === 'trash' && task.trashedAt) continue; + const version = task.version + 1; + const value = action === 'archive' ? { archivedAt: new Date() } : action === 'unarchive' ? { archivedAt: null } : action === 'trash' ? { trashedAt: new Date(), trashRootId: id } : { trashedAt: null, trashRootId: null }; + await tx.update(tasks).set({ ...value, version, updatedAt: new Date(), fieldVersions: { ...task.fieldVersions, lifecycle: version } }).where(eq(tasks.id, task.id)); + await tx.insert(taskActivities).values({ taskId: task.id, actorId: actor.user.id, version, fields: [action] }); + } + }); + } +} diff --git a/apps/api/src/lifecycle/templates.ts b/apps/api/src/lifecycle/templates.ts new file mode 100644 index 0000000..14ad7fe --- /dev/null +++ b/apps/api/src/lifecycle/templates.ts @@ -0,0 +1,109 @@ +import { randomUUID } from 'node:crypto'; +import { and, eq, inArray, max } from 'drizzle-orm'; +import { Temporal } from '@js-temporal/polyfill'; +import { templateSchema, type TemplateNode, type Recurrence } from '@tendly/shared'; +import type { Database, Transaction } from '../accounts/database.js'; +import type { Actor } from '../accounts/access.js'; +import { AccountError } from '../accounts/errors.js'; +import { TaskService } from '../tasks/service.js'; +import { tasks, taskActivities } from '../tasks/schema.js'; +import { resolveGraph } from '../tasks/graph.js'; +import { moveTaskToColumn } from '../tasks/domain.js'; +import { templates, occurrences } from './schema.js'; +import { materializeNodes } from './recurrence.js'; +export class TemplateService { + readonly tasks: TaskService; + constructor(readonly db: Database) { this.tasks = new TaskService(db); } + async list(actor: Actor, householdId: string) { + await this.tasks.scope(this.db, actor, householdId); + return (await this.db.select().from(templates).where(eq(templates.householdId, householdId))).map(t => templateSchema.parse(t)); + } + async capture(actor: Actor, householdId: string, taskId: string, name: string, recurrence: Recurrence | null) { + return this.db.transaction(async tx => { + const household = await this.tasks.scope(tx, actor, householdId, true); + const snapshot = await this.tasks.graph(tx, householdId, household.timezone); + const root = snapshot.task(taskId), selected = new Set([taskId]); + let last = 0; + while (last !== selected.size) { last = selected.size; for (const row of snapshot.rows) if (!row.trashedAt && row.parentId && selected.has(row.parentId)) selected.add(row.id); } + const anchor = recurrence?.anchor ?? root.startDate ?? Temporal.Now.plainDateISO(household.timezone).toString(); + const offset = (date: string | null) => date ? Temporal.PlainDate.from(anchor).until(date).days : null; + const nodes = [...selected].map(id => { const task = snapshot.task(id); return { sourceId: id, value: id === taskId ? { ...task.local, parentId: null, inherit: [], blockers: task.effectiveBlockers.map(b => b.id), epicId: task.epicId, high: task.high, assignees: task.assignees, places: task.places, resources: task.resources, tags: task.tags, startDate: task.startDate, startTime: task.startTime, deadlineDate: task.deadlineDate, deadlineTime: task.deadlineTime } : task.local, startOffset: offset(id === taskId ? task.startDate : task.local.startDate), deadlineOffset: offset(id === taskId ? task.deadlineDate : task.local.deadlineDate) }; }); + if (recurrence) nodes[0]!.startOffset = 0; + return this.write(tx, householdId, { name, nodes, recurrence }); + }); + } + async validate(tx: Transaction, householdId: string, nodes: TemplateNode[], retainedTemplate = false) { + const ids = new Set(nodes.map(n => n.sourceId)); + if (ids.size !== nodes.length || nodes.filter(n => !n.value.parentId).length !== 1 || nodes.some(n => n.value.parentId && !ids.has(n.value.parentId))) throw new AccountError('invalid_template_tree'); + resolveGraph(nodes.map(n => ({ id: n.sourceId, local: n.value, trashed: false })), 'UTC').validateDependencies(); + for (const node of nodes) { + const external = [...node.value.blockers, ...node.value.related].filter(id => !ids.has(id)); + const found = external.length ? await tx.select().from(tasks).where(inArray(tasks.id, external)) : []; + if (found.some(t => t.householdId !== householdId)) throw new AccountError('invalid_task_reference'); + await this.tasks.validate(tx, householdId, { ...node.value, startDate: node.startOffset === null ? null : '2000-01-01', startTime: node.startOffset === null ? null : node.value.startTime, deadlineDate: node.deadlineOffset === null ? null : '2000-01-01', deadlineTime: node.deadlineOffset === null ? null : node.value.deadlineTime, parentId: null, blockers: [], related: [] }, undefined, retainedTemplate); + } + } + async write(tx: Transaction, householdId: string, value: { name: string; nodes: TemplateNode[]; recurrence: Recurrence | null }, id?: string, version?: number) { + await this.validate(tx, householdId, value.nodes); + if (value.recurrence) { + const root = value.nodes.find(n => !n.value.parentId)!; + if (root.startOffset === null) root.startOffset = 0; + } + if (id) { + const [old] = await tx.select().from(templates).where(and(eq(templates.id, id), eq(templates.householdId, householdId))); + if (!old) throw new AccountError('template_not_found', 404); + if (old.version !== version) throw new AccountError('planning_conflict', 409); + const [updated] = await tx.update(templates).set({ ...value, version: old.version + 1 }).where(eq(templates.id, id)).returning(); + return templateSchema.parse(updated); + } + const [created] = await tx.insert(templates).values({ ...value, householdId }).returning(); + return templateSchema.parse(created); + } + async save(actor: Actor, householdId: string, value: { name: string; nodes: TemplateNode[]; recurrence: Recurrence | null }, id: string, version: number) { + return this.db.transaction(async tx => { await this.tasks.scope(tx, actor, householdId, true); return this.write(tx, householdId, value, id, version); }); + } + async instantiate(tx: Transaction, template: typeof templates.$inferSelect, date: string, timezone: string, actorId: string | null, scheduled: boolean) { + if (scheduled) { + const [existing] = await tx.select().from(occurrences).where(and(eq(occurrences.templateId, template.id), eq(occurrences.date, date))); + if (existing) return existing.rootId; + } + // Archiving an entity hides new assignments but preserves existing template references. + await this.validate(tx, template.householdId, template.nodes, true); + const nodes = materializeNodes(template.nodes, date, randomUUID), rootId = nodes.find(n => !n.value.parentId)!.id; + const [last] = await tx.select({ order: max(tasks.order) }).from(tasks).where(eq(tasks.householdId, template.householdId)); + const remaining = new Map(nodes.map(n => [n.id, n])), written = new Set(); + // Parent-first insertion satisfies the FK; dependency edges are written only after every node exists. + while (remaining.size) for (const [id, node] of remaining) if (!node.value.parentId || written.has(node.value.parentId)) { + await tx.insert(tasks).values({ ...this.tasks.values(node.value), ...moveTaskToColumn({ status: 'todo', bucket: 'someday', precedingColumn: null }, node.value.column), id, householdId: template.householdId, order: (last?.order ?? 0) + (written.size + 1) * 1024, createdBy: actorId, completedAt: node.value.column === 'done' ? new Date() : null, completedBy: node.value.column === 'done' ? actorId : null }); + written.add(id); remaining.delete(id); + } + for (const node of nodes) { + await this.tasks.collections(tx, node.id, node.value); + // Related external tasks may have been removed since capture; blockers intentionally retain missing targets. + const existingRelated = node.value.related.length ? await tx.select({ id: tasks.id }).from(tasks).where(and(eq(tasks.householdId, template.householdId), inArray(tasks.id, node.value.related))) : []; + await this.tasks.graphCollections(tx, node.id, { ...node.value, related: existingRelated.map(t => t.id) }, actorId); + await tx.insert(taskActivities).values({ taskId: node.id, actorId, version: 1, fields: [scheduled ? 'recurrence_created' : 'template_created'] }); + } + (await this.tasks.graph(tx, template.householdId, timezone)).graph.validateDependencies(); + if (scheduled) await tx.insert(occurrences).values({ templateId: template.id, date, rootId }); + return rootId; + } + async createInstance(actor: Actor, householdId: string, id: string, date: string) { + return this.db.transaction(async tx => { + const household = await this.tasks.scope(tx, actor, householdId, true); + const [template] = await tx.select().from(templates).where(and(eq(templates.id, id), eq(templates.householdId, householdId))); + if (!template) throw new AccountError('template_not_found', 404); + const rootId = await this.instantiate(tx, template, date, household.timezone, actor.user.id, false); + return this.tasks.get(tx, householdId, rootId, household.timezone); + }); + } + async remove(actor: Actor, householdId: string, id: string, version: number) { + await this.db.transaction(async tx => { + await this.tasks.scope(tx, actor, householdId, true); + const [row] = await tx.select().from(templates).where(and(eq(templates.id, id), eq(templates.householdId, householdId))); + if (!row) throw new AccountError('template_not_found', 404); + if (row.version !== version) throw new AccountError('planning_conflict', 409); + await tx.delete(templates).where(eq(templates.id, id)); + }); + } +} diff --git a/apps/api/src/lifecycle/worker.ts b/apps/api/src/lifecycle/worker.ts new file mode 100644 index 0000000..a1a1659 --- /dev/null +++ b/apps/api/src/lifecycle/worker.ts @@ -0,0 +1,78 @@ +import { moveTaskToColumn, promotedColumn } from '../tasks/domain.js'; +import { cleanOrphanFiles } from '../content/cleanup.js'; +import pg from 'pg'; +import { drizzle } from 'drizzle-orm/node-postgres'; +import { and, eq, inArray } from 'drizzle-orm'; +import { Temporal } from '@js-temporal/polyfill'; +import type { PgBoss } from 'pg-boss'; +import * as schema from '../db/schema.js'; +import type { Database } from '../accounts/database.js'; +import type { readConfig } from '../config.js'; +import { TemplateService } from './templates.js'; +import { LifecycleService } from './service.js'; +import { dueOccurrences } from './recurrence.js'; +export async function maintainHousehold(db: Database, householdId: string, now = new Date()) { + const templates = new TemplateService(db), lifecycle = new LifecycleService(db); + await db.transaction(async tx => { + // Jobs have no user session: constrain and lock their household explicitly, just like HTTP mutations. + const [household] = await tx.select().from(schema.households).where(eq(schema.households.id, householdId)).for('update'); + if (!household) return; + const localNow = Temporal.Instant.fromEpochMilliseconds(now.getTime()).toZonedDateTimeISO(household.timezone); + const today = localNow.toPlainDate().toString(); + const series = await tx.select().from(schema.templates).where(eq(schema.templates.householdId, householdId)); + for (const template of series) if (template.recurrence?.enabled) { + const existing = new Set((await tx.select().from(schema.occurrences).where(eq(schema.occurrences.templateId, template.id))).map(o => o.date)); + let created = 0; + for (const date of dueOccurrences(template.recurrence, today)) if (!existing.has(date)) { + await templates.instantiate(tx, template, date, household.timezone, null, true); + if (++created >= 100) break; // Bound catch-up transactions; the next run safely resumes. + } + } + const [settings] = await tx.select().from(schema.lifecycleSettings).where(eq(schema.lifecycleSettings.householdId, householdId)); + const archiveDays = settings ? settings.archiveDays : 30, trashDays = settings?.trashDays ?? 30; + const archiveCutoff = archiveDays === null ? null : localNow.subtract({ days: archiveDays }).epochMilliseconds; + const graph = await lifecycle.tasks.graph(tx, householdId, household.timezone); + for (const task of graph.rows) { + if (!task.trashedAt && !task.archivedAt) { + const effective = graph.task(task.id); + const column = promotedColumn(effective, household.timezone, now.getTime()); + if (column !== effective.column) { + const version = task.version + 1; + await tx.update(schema.tasks).set({ ...moveTaskToColumn(task, column), version, fieldVersions: { ...task.fieldVersions, column: version }, updatedAt: now }).where(and(eq(schema.tasks.id, task.id), eq(schema.tasks.householdId, householdId))); + await tx.insert(schema.taskActivities).values({ taskId: task.id, version, fields: ['column'] }); + } + } + if (task.trashedAt || task.archivedAt || archiveDays === null || !task.completedAt || archiveCutoff === null || task.completedAt.getTime() > archiveCutoff || graph.task(task.id).unfinishedDescendants) continue; + await tx.update(schema.tasks).set({ archivedAt: now, version: task.version + 1, fieldVersions: { ...task.fieldVersions, lifecycle: task.version + 1 }, updatedAt: now }).where(and(eq(schema.tasks.id, task.id), eq(schema.tasks.householdId, householdId))); + await tx.insert(schema.taskActivities).values({ taskId: task.id, version: task.version + 1, fields: ['auto_archived'] }); + } + const cutoff = localNow.subtract({ days: trashDays }).epochMilliseconds, removed = new Set(); + for (const task of graph.rows) if (task.trashedAt && task.trashedAt.getTime() <= cutoff && !removed.has(task.id)) { + const ids = await lifecycle.subtree(tx, householdId, task.id); + const rows = await tx.select().from(schema.tasks).where(and(eq(schema.tasks.householdId, householdId), inArray(schema.tasks.id, ids))); + if (rows.some(r => !r.trashedAt || r.trashedAt.getTime() > cutoff)) continue; + await lifecycle.permanentlyDelete(tx, householdId, ids); + ids.forEach(id => removed.add(id)); + } + }); +} +export async function registerLifecycleJobs(boss: PgBoss, config: ReturnType) { + const pool = new pg.Pool({ connectionString: config.DATABASE_URL, connectionTimeoutMillis: 5000 }); + pool.on('error', () => console.error('Lifecycle worker database connection failed')); + const db = drizzle(pool, { schema }); + await boss.createQueue('household-maintenance'); + await boss.work('household-maintenance', async () => { + const households = await db.select({ id: schema.households.id }).from(schema.households); + // Independent transactions let one household retry without duplicating another household's instances. + const failures: unknown[] = []; + for (const household of households) { + try { await maintainHousehold(db, household.id); } + catch (error) { failures.push(error); } + } + await cleanOrphanFiles(db, '/data/attachments'); + // A broken series must not starve later households; still fail the job so pg-boss retries it. + if (failures.length) throw new AggregateError(failures, 'Household maintenance needs retry'); + }); + await boss.schedule('household-maintenance', '* * * * *'); + return () => pool.end(); +} diff --git a/apps/api/src/planning/filter.ts b/apps/api/src/planning/filter.ts new file mode 100644 index 0000000..a7c94a4 --- /dev/null +++ b/apps/api/src/planning/filter.ts @@ -0,0 +1,46 @@ +import { sql, type SQL } from 'drizzle-orm'; +import { Temporal } from '@js-temporal/polyfill'; +import { filterAstSchema, type FilterAst, type Task } from '@tendly/shared'; +import type { QueryDatabase } from '../accounts/database.js'; +export type FilterContext = { userId: string; currentPlace: string | null; timezone: string }; +export function compileFilter(input: FilterAst, context: FilterContext): SQL { + const ast = filterAstSchema.parse(input); + function compile(node: FilterAst): SQL { + if (node.type === 'group') { + const children = node.children.map(compile); + if (node.operator === 'not') return sql`NOT (${children[0]!})`; + if (!children.length) return sql.raw(node.operator === 'and' ? 'TRUE' : 'FALSE'); + return sql`(${sql.join(children, sql.raw(node.operator === 'and' ? ' AND ' : ' OR '))})`; + } + // Field names and operators are validated allowlists; every operand remains a parameter. + const raw = sql`(item -> ${node.field})`, text = sql`(item ->> ${node.field})`; + if (node.operator === 'empty') return sql`(${raw} IS NULL OR ${raw} = 'null'::jsonb OR ${raw} = '[]'::jsonb OR ${raw} = '""'::jsonb)`; + const values = (Array.isArray(node.value) ? node.value : [node.value]).map(value => value === '$user' ? context.userId : value === '$place' ? context.currentPlace : value === '$today' ? Temporal.Now.plainDateISO(context.timezone).toString() : value); + if (values.includes(null)) return sql`FALSE`; + const collection = ['assignees', 'places', 'resources', 'tags'].includes(node.field); + if (collection) { + const desired = sql`${JSON.stringify(values)}::jsonb`; + if (node.operator === 'feasible') return sql`${desired} @> ${raw}`; + if (node.operator === 'all') return sql`${raw} @> ${desired}`; + const intersection = sql`EXISTS (SELECT 1 FROM jsonb_array_elements_text(${raw}) e WHERE e.value IN (SELECT jsonb_array_elements_text(${desired})))`; + return node.operator === 'compatible' ? sql`(${raw} = '[]'::jsonb OR ${intersection})` : intersection; + } + if (node.operator === 'contains') return sql`position(lower(${String(values[0])}) in lower(${text})) > 0`; + if (node.operator === 'in' || node.operator === 'not_in') { + const inside = values.length ? sql`${text} IN (${sql.join(values.map(v => sql`${String(v)}`), sql`, `)})` : sql`FALSE`; + return node.operator === 'not_in' ? sql`NOT COALESCE((${inside}), FALSE)` : inside; + } + const left = node.field === 'estimateMinutes' ? sql`(${text})::numeric` : text; + const right = node.field === 'estimateMinutes' ? sql`${Number(values[0])}::numeric` : sql`${String(values[0])}`; + const operator = { eq: '=', ne: '<>', before: '<', after: '>', lte: '<=', gte: '>=' }[node.operator as 'eq']; + return sql`COALESCE((${left} ${sql.raw(operator)} ${right}), FALSE)`; + } + return compile(ast); +} +export async function filterTasks(db: QueryDatabase, tasks: Task[], ast: FilterAst[], context: FilterContext) { + const predicate = sql.join(ast.map(expression => sql`(${compileFilter(expression, context)})`), sql` AND `); + // Filter the canonical effective snapshot, before sorting/pagination, through PostgreSQL. + // No user-controlled SQL fragments or second client-side rule evaluator exist. + const rows = await db.execute<{ item: Task }>(sql`SELECT item FROM jsonb_array_elements(${JSON.stringify(tasks)}::jsonb) AS snapshot(item) WHERE ${predicate}`); + return rows.rows.map(row => row.item); +} diff --git a/apps/api/src/planning/routes.ts b/apps/api/src/planning/routes.ts new file mode 100644 index 0000000..89f62a4 --- /dev/null +++ b/apps/api/src/planning/routes.ts @@ -0,0 +1,27 @@ +import type { FastifyInstance, FastifyRequest } from 'fastify'; +import type { ZodTypeProvider } from 'fastify-type-provider-zod'; +import { z } from 'zod'; +import { filterAstSchema, filterInput, viewInput, filterDocumentSchema, viewDocumentSchema, planningLibrarySchema, personalViewSchema, viewResultsSchema, okSchema } from '@tendly/shared'; +import { signedIn } from '../accounts/access.js'; +import type { AccountService } from '../accounts/service.js'; +import { PlanningService } from './service.js'; +const scope = z.object({ householdId: z.uuid() }), item = scope.extend({ id: z.uuid() }); +const version = z.object({ baseVersion: z.number().int().min(1) }); +export async function registerPlanningRoutes(server: FastifyInstance, accounts: AccountService) { + const app = server.withTypeProvider(), service = new PlanningService(accounts.db); + const actor = async (request: FastifyRequest) => { + const current = await accounts.findSession(request.cookies[accounts.origin.startsWith('https:') ? '__Host-tendly' : 'tendly_session']); + signedIn(current); return current; + }; + app.get('/api/v1/households/:householdId/planning', { schema: { params: scope, response: { 200: planningLibrarySchema } } }, async r => service.library(await actor(r), r.params.householdId)); + app.post('/api/v1/households/:householdId/filters', { schema: { params: scope, body: filterInput, response: { 200: filterDocumentSchema } } }, async r => service.saveFilter(await actor(r), r.params.householdId, r.body)); + app.put('/api/v1/households/:householdId/filters/:id', { schema: { params: item, body: filterInput.extend(version.shape), response: { 200: filterDocumentSchema } } }, async r => service.saveFilter(await actor(r), r.params.householdId, r.body, r.params.id, r.body.baseVersion)); + app.get('/api/v1/households/:householdId/filters/:id/history', { schema: { params: item, response: { 200: z.array(z.object({ version: z.number(), definition: filterAstSchema, createdAt: z.string() })) } } }, async r => service.history(await actor(r), r.params.householdId, r.params.id)); + app.post('/api/v1/households/:householdId/filter-preview', { schema: { params: scope, body: z.object({ definition: filterAstSchema, currentPlace: z.uuid().nullable() }), response: { 200: viewResultsSchema } } }, async r => service.results(await actor(r), r.params.householdId, { preview: r.body.definition, currentPlace: r.body.currentPlace, offset: 0, limit: 20 })); + app.post('/api/v1/households/:householdId/views', { schema: { params: scope, body: viewInput, response: { 200: viewDocumentSchema } } }, async r => service.saveView(await actor(r), r.params.householdId, r.body)); + app.put('/api/v1/households/:householdId/views/:id', { schema: { params: item, body: viewInput.extend(version.shape), response: { 200: viewDocumentSchema } } }, async r => service.saveView(await actor(r), r.params.householdId, r.body, r.params.id, r.body.baseVersion)); + app.put('/api/v1/households/:householdId/views/:id/personal', { schema: { params: item, body: personalViewSchema, response: { 200: personalViewSchema } } }, async r => service.personal(await actor(r), r.params.householdId, r.params.id, r.body)); + app.get('/api/v1/households/:householdId/views/:id/tasks', { schema: { params: item, querystring: z.object({ offset: z.coerce.number().int().min(0).default(0), limit: z.coerce.number().int().min(1).max(100).default(100) }), response: { 200: viewResultsSchema } } }, async r => service.results(await actor(r), r.params.householdId, { viewId: r.params.id, ...r.query })); + app.delete('/api/v1/households/:householdId/filters/:id', { schema: { params: item, body: version, response: { 200: okSchema } } }, async r => { await service.remove(await actor(r), r.params.householdId, 'filter', r.params.id, r.body.baseVersion); return { ok: true as const }; }); + app.delete('/api/v1/households/:householdId/views/:id', { schema: { params: item, body: version, response: { 200: okSchema } } }, async r => { await service.remove(await actor(r), r.params.householdId, 'view', r.params.id, r.body.baseVersion); return { ok: true as const }; }); +} diff --git a/apps/api/src/planning/schema.ts b/apps/api/src/planning/schema.ts new file mode 100644 index 0000000..e6e5671 --- /dev/null +++ b/apps/api/src/planning/schema.ts @@ -0,0 +1,8 @@ +import { pgTable, uuid, text, integer, jsonb, timestamp, primaryKey, uniqueIndex } from 'drizzle-orm/pg-core'; +import type { FilterAst, ViewDefinition } from '@tendly/shared'; +import { households, users } from '../accounts/schema.js'; +const common = () => ({ id: uuid('id').primaryKey().defaultRandom(), householdId: uuid('household_id').notNull().references(() => households.id, { onDelete: 'cascade' }), name: text('name').notNull(), icon: text('icon').notNull().default('list-filter'), color: text('color').notNull().default('blue'), version: integer('version').notNull().default(1), createdBy: uuid('created_by').references(() => users.id, { onDelete: 'set null' }), builtin: text('builtin') }); +export const filters = pgTable('saved_filters', { ...common(), definition: jsonb('definition').$type().notNull() }); +export const filterHistory = pgTable('filter_history', { filterId: uuid('filter_id').notNull().references(() => filters.id, { onDelete: 'cascade' }), version: integer('version').notNull(), definition: jsonb('definition').$type().notNull(), actorId: uuid('actor_id').references(() => users.id, { onDelete: 'set null' }), createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow() }, t => [primaryKey({ columns: [t.filterId, t.version] })]); +export const views = pgTable('saved_views', { ...common(), definition: jsonb('definition').$type().notNull() }, t => [uniqueIndex('view_household_builtin_idx').on(t.householdId, t.builtin)]); +export const viewPersonal = pgTable('view_personal', { viewId: uuid('view_id').notNull().references(() => views.id, { onDelete: 'cascade' }), userId: uuid('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }), version: integer('version').notNull().default(1), activeFilters: jsonb('active_filters').$type().notNull().default([]), favorite: integer('favorite').notNull().default(0), currentPlace: uuid('current_place') }, t => [primaryKey({ columns: [t.viewId, t.userId] })]); diff --git a/apps/api/src/planning/service.ts b/apps/api/src/planning/service.ts new file mode 100644 index 0000000..5c62399 --- /dev/null +++ b/apps/api/src/planning/service.ts @@ -0,0 +1,136 @@ +import { and, asc, eq, inArray } from 'drizzle-orm'; +import { defaultView, filterDocumentSchema, viewDocumentSchema, personalViewSchema, type FilterAst, type PersonalView, type ViewDefinition } from '@tendly/shared'; +import type { Actor } from '../accounts/access.js'; +import type { Database, QueryDatabase } from '../accounts/database.js'; +import { AccountError } from '../accounts/errors.js'; +import { TaskService } from '../tasks/service.js'; +import { entities } from '../tasks/schema.js'; +import { filters, filterHistory, views, viewPersonal } from './schema.js'; +import { filterTasks } from './filter.js'; +type Identity = { name: string; icon: string; color: string }; +export class PlanningService { + readonly tasks: TaskService; + constructor(readonly db: Database) { this.tasks = new TaskService(db); } + async library(actor: Actor, householdId: string) { + return this.db.transaction(async tx => { + await this.tasks.scope(tx, actor, householdId, true); + for (const builtin of ['now', 'board'] as const) await tx.insert(views).values({ householdId, name: builtin === 'now' ? 'Now' : 'Board', icon: builtin === 'now' ? 'house' : 'layout-grid', color: 'blue', builtin, definition: defaultView(builtin === 'now') }).onConflictDoNothing(); + const savedViews = await tx.select().from(views).where(eq(views.householdId, householdId)); + const savedFilters = await tx.select().from(filters).where(eq(filters.householdId, householdId)); + const personal = savedViews.length ? await tx.select().from(viewPersonal).where(and(eq(viewPersonal.userId, actor.user.id), inArray(viewPersonal.viewId, savedViews.map(v => v.id)))) : []; + return { views: savedViews.map(v => viewDocumentSchema.parse(v)), filters: savedFilters.map(f => filterDocumentSchema.parse(f)), personal: Object.fromEntries(savedViews.map(v => { + const row = personal.find(p => p.viewId === v.id); + return [v.id, row ? { ...row, favorite: !!row.favorite } : { version: 0, activeFilters: [], favorite: !!v.builtin, currentPlace: null }]; + })) }; + }); + } + async references(db: QueryDatabase, householdId: string, ids: string[]) { + if (!ids.length) return; + const found = await db.select().from(filters).where(and(eq(filters.householdId, householdId), inArray(filters.id, ids))); + if (found.length !== new Set(ids).size) throw new AccountError('invalid_filter_reference'); + } + async saveFilter(actor: Actor, householdId: string, value: Identity & { definition: FilterAst }, id?: string, version?: number) { + return this.db.transaction(async tx => { + await this.tasks.scope(tx, actor, householdId, true); + if (id) { + const [old] = await tx.select().from(filters).where(and(eq(filters.id, id), eq(filters.householdId, householdId))); + if (!old) throw new AccountError('filter_not_found', 404); + if (old.version !== version) throw new AccountError('planning_conflict', 409); + const [row] = await tx.update(filters).set({ ...value, version: old.version + 1 }).where(eq(filters.id, id)).returning(); + await tx.insert(filterHistory).values({ filterId: id, version: row!.version, definition: value.definition, actorId: actor.user.id }); + return filterDocumentSchema.parse(row); + } + const [row] = await tx.insert(filters).values({ ...value, householdId, createdBy: actor.user.id }).returning(); + await tx.insert(filterHistory).values({ filterId: row!.id, version: 1, definition: value.definition, actorId: actor.user.id }); + return filterDocumentSchema.parse(row); + }); + } + async saveView(actor: Actor, householdId: string, value: Identity & { definition: ViewDefinition }, id?: string, version?: number) { + return this.db.transaction(async tx => { + await this.tasks.scope(tx, actor, householdId, true); + await this.references(tx, householdId, value.definition.quickFilters); + if (id) { + const [old] = await tx.select().from(views).where(and(eq(views.id, id), eq(views.householdId, householdId))); + if (!old) throw new AccountError('view_not_found', 404); + if (old.version !== version) throw new AccountError('planning_conflict', 409); + const [row] = await tx.update(views).set({ ...value, version: old.version + 1 }).where(eq(views.id, id)).returning(); + return viewDocumentSchema.parse(row); + } + const [row] = await tx.insert(views).values({ ...value, householdId, createdBy: actor.user.id }).returning(); + return viewDocumentSchema.parse(row); + }); + } + async personal(actor: Actor, householdId: string, id: string, input: PersonalView) { + return this.db.transaction(async tx => { + await this.tasks.scope(tx, actor, householdId, true); + const [view] = await tx.select().from(views).where(and(eq(views.id, id), eq(views.householdId, householdId))); + if (!view) throw new AccountError('view_not_found', 404); + if (input.activeFilters.some(f => !view.definition.quickFilters.includes(f))) throw new AccountError('invalid_filter_reference'); + if (input.currentPlace) { + const [place] = await tx.select().from(entities).where(and(eq(entities.id, input.currentPlace), eq(entities.householdId, householdId), eq(entities.kind, 'place'))); + if (!place) throw new AccountError('invalid_task_reference'); + } + const where = and(eq(viewPersonal.viewId, id), eq(viewPersonal.userId, actor.user.id)); + const [old] = await tx.select().from(viewPersonal).where(where); + if ((old?.version ?? 0) !== input.version) throw new AccountError('planning_conflict', 409); + const value = { ...input, version: input.version + 1, favorite: input.favorite ? 1 : 0 }; + await tx.insert(viewPersonal).values({ ...value, viewId: id, userId: actor.user.id }).onConflictDoUpdate({ target: [viewPersonal.viewId, viewPersonal.userId], set: value }); + return personalViewSchema.parse({ ...value, favorite: input.favorite }); + }); + } + async history(actor: Actor, householdId: string, id: string) { + await this.tasks.scope(this.db, actor, householdId); + const [filter] = await this.db.select().from(filters).where(and(eq(filters.id, id), eq(filters.householdId, householdId))); + if (!filter) throw new AccountError('filter_not_found', 404); + return (await this.db.select().from(filterHistory).where(eq(filterHistory.filterId, id)).orderBy(asc(filterHistory.version))).map(r => ({ version: r.version, definition: r.definition, createdAt: r.createdAt.toISOString() })); + } + async remove(actor: Actor, householdId: string, kind: 'filter' | 'view', id: string, version: number) { + return this.db.transaction(async tx => { + await this.tasks.scope(tx, actor, householdId, true); + const table = kind === 'filter' ? filters : views; + const [old] = await tx.select().from(table).where(and(eq(table.id, id), eq(table.householdId, householdId))); + if (!old) throw new AccountError('planning_not_found', 404); + if (old.version !== version) throw new AccountError('planning_conflict', 409); + if (old.builtin) throw new AccountError('builtin_view_required'); + if (kind === 'filter') { + const linked = await tx.select().from(views).where(eq(views.householdId, householdId)); + // Remove deleted chips explicitly; never leave a saved view referring to a missing rule. + for (const view of linked.filter(v => v.definition.quickFilters.includes(id))) await tx.update(views).set({ version: view.version + 1, definition: { ...view.definition, quickFilters: view.definition.quickFilters.filter(f => f !== id) } }).where(eq(views.id, view.id)); + } + await tx.delete(table).where(eq(table.id, id)); + }); + } + async results(actor: Actor, householdId: string, options: { viewId?: string; preview?: FilterAst; currentPlace?: string | null; offset: number; limit: number }) { + return this.db.transaction(async tx => { + const household = await this.tasks.scope(tx, actor, householdId); + let definition = defaultView(false), currentPlace = options.currentPlace ?? null; + const expressions: FilterAst[] = []; + if (options.viewId) { + const [view] = await tx.select().from(views).where(and(eq(views.id, options.viewId), eq(views.householdId, householdId))); + if (!view) throw new AccountError('view_not_found', 404); + definition = view.definition; + const [personal] = await tx.select().from(viewPersonal).where(and(eq(viewPersonal.viewId, view.id), eq(viewPersonal.userId, actor.user.id))); + currentPlace = personal?.currentPlace ?? null; + const active = personal?.activeFilters.filter(id => definition.quickFilters.includes(id)) ?? []; + if (active.length) expressions.push(...(await tx.select().from(filters).where(and(eq(filters.householdId, householdId), inArray(filters.id, active)))).map(f => f.definition)); + } + expressions.unshift(options.preview ?? definition.base); + if (options.preview) definition.subtasks = true; + const ast: FilterAst = { type: 'group', operator: 'and', children: expressions }; + const snapshot = await this.tasks.graph(tx, householdId, household.timezone); + const candidates = snapshot.rows.filter(r => !r.trashedAt && !r.archivedAt && (definition.subtasks || !r.parentId)).map(r => snapshot.task(r.id)); + const found = await filterTasks(tx, candidates, expressions, { userId: actor.user.id, currentPlace, timezone: household.timezone }); + found.sort((a, b) => { + const tie = a.order - b.order || a.id.localeCompare(b.id); + switch (definition.sort) { + case 'deadline': return (a.deadlineDate ?? '9999').localeCompare(b.deadlineDate ?? '9999') || tie; + case 'priority': return Number(b.high) - Number(a.high) || tie; + case 'effort': return (['XS', 'S', 'M', 'L', 'XL'].indexOf(a.size ?? '') + 6) % 6 - (['XS', 'S', 'M', 'L', 'XL'].indexOf(b.size ?? '') + 6) % 6 || tie; + case 'created': return a.createdAt.localeCompare(b.createdAt) || tie; + default: return tie; + } + }); + return { items: found.slice(options.offset, options.offset + options.limit), count: found.length, nextOffset: found.length > options.offset + options.limit ? options.offset + options.limit : null, missingCurrentPlace: !currentPlace && JSON.stringify(ast).includes('"$place"') }; + }, { isolationLevel: 'repeatable read' }); + } +} diff --git a/apps/api/src/tasks/domain.test.ts b/apps/api/src/tasks/domain.test.ts index 9353755..abf9c03 100644 --- a/apps/api/src/tasks/domain.test.ts +++ b/apps/api/src/tasks/domain.test.ts @@ -1,5 +1,5 @@ import { expect, it } from 'vitest'; -import { availability, dateInstant, moveTaskToColumn, suggestSize, taskColumn } from './domain.js'; +import { promotedColumn, availability, dateInstant, moveTaskToColumn, suggestSize, taskColumn } from './domain.js'; it('keeps six visible columns and reopens to the immediate previous column', () => { let task = moveTaskToColumn({ status: 'todo', bucket: 'someday', precedingColumn: null }, 'within_year'); task = moveTaskToColumn(task, 'in_progress'); @@ -21,3 +21,15 @@ it('uses household local days including DST and optional explicit times', () => it('suggests size at inclusive configurable effort boundaries', () => { expect([60, 61, 240, 480, 1440, 1441].map(n => suggestSize(n, [60, 240, 480, 1440]))).toEqual(['XS', 'S', 'S', 'M', 'L', 'XL']); }); + +it('promotes future columns forward at calendar horizons and the exact local start', () => { + const now = Date.parse('2026-01-31T11:00:00Z'); + const promote = (startDate: string | null, column: 'someday' | 'within_year' | 'within_month' | 'todo' | 'in_progress' | 'done' = 'someday', startTime: string | null = null) => promotedColumn({ column, startDate, startTime }, 'Europe/Stockholm', now); + expect(['2027-02-01', '2027-01-31', '2026-03-01', '2026-02-28', '2026-01-31', '2026-01-30'].map(date => promote(date))).toEqual(['someday', 'within_year', 'within_year', 'within_month', 'todo', 'todo']); + expect(promote('2026-01-31', 'within_year', '12:01')).toBe('within_month'); + expect(promote('2026-01-31', 'within_month', '12:00')).toBe('todo'); + expect(promote('2028-01-01', 'within_month')).toBe('within_month'); + expect(promote(null)).toBe('someday'); + for (const column of ['todo', 'in_progress', 'done'] as const) expect(promote('2026-01-01', column)).toBe(column); + expect(promotedColumn({ column: 'someday', startDate: '2026-10-16', startTime: null }, 'Europe/Stockholm', Date.parse('2026-10-15T22:00:00Z'))).toBe('todo'); +}); diff --git a/apps/api/src/tasks/domain.ts b/apps/api/src/tasks/domain.ts index a47c2de..406baac 100644 --- a/apps/api/src/tasks/domain.ts +++ b/apps/api/src/tasks/domain.ts @@ -29,3 +29,15 @@ export function availability(task: Pick, timezone: string, now = Date.now()): TaskColumn { + const future: TaskColumn[] = ['someday', 'within_year', 'within_month', 'todo']; + const current = future.indexOf(task.column); + if (!task.startDate || current < 0 || current === 3) return task.column; + const today = Temporal.Instant.fromEpochMilliseconds(now).toZonedDateTimeISO(timezone).toPlainDate(); + // Calendar horizons clamp month ends, while the actual start respects an optional local time. + const target = dateInstant(task.startDate, task.startTime, timezone) <= now ? 3 + : task.startDate <= today.add({ months: 1 }).toString() ? 2 + : task.startDate <= today.add({ years: 1 }).toString() ? 1 : 0; + return future[Math.max(current, target)]!; +} diff --git a/apps/api/src/tasks/graph.test.ts b/apps/api/src/tasks/graph.test.ts new file mode 100644 index 0000000..9c6c9ed --- /dev/null +++ b/apps/api/src/tasks/graph.test.ts @@ -0,0 +1,11 @@ +import { expect, it } from 'vitest'; +import type { TaskFields } from '@tendly/shared'; +import { resolveGraph, type GraphNode } from './graph.js'; +it('resolves thousands of nesting levels without a recursive call-stack limit', () => { + const local: TaskFields = { parentId: null, inherit: [], placeExclusions: [], resourceExclusions: [], tagExclusions: [], blockers: [], related: [], title: 'Deep task', description: '', column: 'todo', epicId: null, high: true, size: null, estimateMinutes: null, startDate: null, startTime: null, deadlineDate: null, deadlineTime: null, assignees: [], places: [], resources: [], tags: [] }; + const nodes: GraphNode[] = Array.from({ length: 3000 }, (_, i) => ({ id: String(i), trashed: false, local: { ...local, parentId: i ? String(i - 1) : null, high: !i, inherit: i ? ['high'] : [] } })); + const graph = resolveGraph(nodes, 'UTC'); + graph.validateDependencies(); + expect(graph.details('2999')).toMatchObject({ high: true, available: true }); + expect(graph.details('0').unfinishedDescendants).toBe(2999); +}); diff --git a/apps/api/src/tasks/graph.ts b/apps/api/src/tasks/graph.ts new file mode 100644 index 0000000..2b5562a --- /dev/null +++ b/apps/api/src/tasks/graph.ts @@ -0,0 +1,83 @@ +import { resolveCollection, type TaskFields, type Task } from '@tendly/shared'; +import { availability, dateInstant } from './domain.js'; +import { AccountError } from '../accounts/errors.js'; +export type GraphNode = { id: string; local: TaskFields; trashed: boolean }; +const sets = ['places', 'resources', 'tags'] as const; +const exclusions = { places: 'placeExclusions', resources: 'resourceExclusions', tags: 'tagExclusions' } as const; +export const emptyInherited = { epicId: null, high: false, startDate: null, startTime: null, deadlineDate: null, deadlineTime: null, assignees: [], places: [], resources: [], tags: [] }; +export function resolveGraph(nodes: GraphNode[], timezone: string) { + const byId = new Map(nodes.map(node => [node.id, node])); + const children = new Map(); + const order: string[] = []; + for (const node of nodes) { + const parent = node.local.parentId; + if (!parent) order.push(node.id); + else { + if (!byId.has(parent)) throw new AccountError('invalid_task_reference'); + const siblings = children.get(parent) ?? []; siblings.push(node.id); children.set(parent, siblings); + } + } + // Iteration rather than recursive JS calls keeps deeply nested valid trees usable. + for (let at = 0; at < order.length; at++) for (const child of children.get(order[at]!) ?? []) order.push(child); + if (order.length !== nodes.length) throw new AccountError('task_cycle'); + const effective = new Map(); + const blockers = new Map>(); + const unfinished = new Map(); + for (const id of order) { + const local = byId.get(id)!.local; + const parent = local.parentId ? effective.get(local.parentId)! : emptyInherited; + const next = { ...local }; + for (const key of local.inherit) { + if (key === 'startDate') { next.startDate = parent.startDate; next.startTime = parent.startTime; } + else if (key === 'deadlineDate') { next.deadlineDate = parent.deadlineDate; next.deadlineTime = parent.deadlineTime; } + else if (key === 'epicId') next.epicId = parent.epicId; + else if (key === 'high') next.high = parent.high; + else next.assignees = parent.assignees; + } + for (const key of sets) next[key] = resolveCollection(parent[key], local[key], local[exclusions[key]]); + effective.set(id, next); + blockers.set(id, new Set([...(local.parentId ? blockers.get(local.parentId)! : []), ...local.blockers])); + } + for (const id of [...order].reverse()) unfinished.set(id, (children.get(id) ?? []).reduce((sum, child) => { + const node = byId.get(child)!; + return sum + (node.trashed ? 0 : (node.local.column === 'done' ? 0 : 1) + unfinished.get(child)!); + }, 0)); + function link(id: string) { const node = byId.get(id)!; return { id, title: node.local.title, column: node.local.column }; } + function details(id: string) { + const node = byId.get(id)!, value = effective.get(id)!; + const parent = value.parentId ? effective.get(value.parentId)! : emptyInherited; + const ancestors: Task['ancestors'] = []; + for (let p = value.parentId; p; p = byId.get(p)!.local.parentId) ancestors.push(link(p)); + const direct = (children.get(id) ?? []).filter(child => !byId.get(child)!.trashed).map(link); + const effectiveBlockers = [...blockers.get(id)!].map(blocker => { + const target = byId.get(blocker); + return { id: blocker, title: target?.local.title ?? null, complete: !!target && !target.trashed && target.local.column === 'done', inherited: !node.local.blockers.includes(blocker) }; + }); + const dates = availability(value, timezone); + return { + ...value, local: node.local, inheritedValues: parent, ancestors: ancestors.reverse(), children: direct, + relatedTasks: node.local.related.filter(peer => byId.has(peer)).map(link), effectiveBlockers, ...dates, available: dates.available && effectiveBlockers.every(b => b.complete), + progress: { done: direct.filter(c => c.column === 'done').length, total: direct.length }, + unfinishedDescendants: unfinished.get(id)!, + deadlineBeyondParent: !!value.parentId && !!value.deadlineDate && !!parent.deadlineDate && dateInstant(value.deadlineDate, value.deadlineTime, timezone, true) > dateInstant(parent.deadlineDate, parent.deadlineTime, timezone, true), + }; + } + function validateDependencies() { + // Kahn traversal validates the effective graph, including ancestor-derived edges. + // Availability intentionally does NOT traverse those blockers' own dependencies. + const remaining = new Map(); + const dependents = new Map(); + for (const id of order) { + const targets = [...blockers.get(id)!].filter(target => byId.has(target)); + remaining.set(id, targets.length); + for (const target of targets) { const list = dependents.get(target) ?? []; list.push(id); dependents.set(target, list); } + } + const ready = order.filter(id => remaining.get(id) === 0); + for (let at = 0; at < ready.length; at++) for (const dependent of dependents.get(ready[at]!) ?? []) { + const count = remaining.get(dependent)! - 1; remaining.set(dependent, count); + if (!count) ready.push(dependent); + } + if (ready.length !== order.length) throw new AccountError('dependency_cycle'); + } + return { details, validateDependencies }; +} diff --git a/apps/api/src/tasks/routes.ts b/apps/api/src/tasks/routes.ts index a5949c1..a829892 100644 --- a/apps/api/src/tasks/routes.ts +++ b/apps/api/src/tasks/routes.ts @@ -17,20 +17,24 @@ export async function registerTaskRoutes(server: FastifyInstance, accounts: Acco return current; }; app.get('/api/v1/households/:householdId/tasks', { - schema: { params: scope, querystring: z.object({ view: z.enum(['now', 'board']).default('board'), offset: z.coerce.number().int().min(0).default(0), limit: z.coerce.number().int().min(1).max(100).default(100) }), response: { 200: z.object({ items: z.array(taskSchema), nextOffset: z.number().nullable() }) } }, - }, async request => service.list(await actor(request), request.params.householdId, request.query.view, request.query.offset, request.query.limit)); + schema: { params: scope, querystring: z.object({ view: z.enum(['now', 'board']).default('board'), offset: z.coerce.number().int().min(0).default(0), search: z.string().max(200).default(''), includeSubtasks: z.enum(['true', 'false']).default('false'), parentId: z.uuid().optional(), limit: z.coerce.number().int().min(1).max(100).default(100) }), response: { 200: z.object({ items: z.array(taskSchema), nextOffset: z.number().nullable() }) } }, + }, async request => service.list(await actor(request), request.params.householdId, request.query.view, request.query.offset, request.query.limit, request.query.includeSubtasks === 'true', request.query.parentId, request.query.search)); app.get('/api/v1/households/:householdId/tasks/:id', { schema: { params: item, response: { 200: taskSchema } } }, async request => { - const household = await service.scope(service.db, await actor(request), request.params.householdId); - return service.get(service.db, household.id, request.params.id, household.timezone); + const current = await actor(request); + return service.db.transaction(async tx => { + const household = await service.scope(tx, current, request.params.householdId); + return service.get(tx, household.id, request.params.id, household.timezone); + }, { isolationLevel: 'repeatable read' }); }); app.post('/api/v1/households/:householdId/tasks', { schema: { params: scope, body: taskCreateSchema, response: { 200: taskSchema } } }, async request => service.create(await actor(request), request.params.householdId, request.body)); app.patch('/api/v1/households/:householdId/tasks/:id', { schema: { params: item, body: taskPatchSchema, response: { 200: taskSchema, 409: z.union([taskConflictSchema, errorSchema]) } } }, async (request, reply) => { - try { return await service.patch(await actor(request), request.params.householdId, request.params.id, request.body.baseVersion, request.body.changes, request.body.confirmUnavailable); } + try { return await service.patch(await actor(request), request.params.householdId, request.params.id, request.body.baseVersion, request.body.changes, request.body.confirmUnavailable, request.body.confirmDescendants); } catch (error) { if (error instanceof TaskConflict) return reply.code(409).send({ error: 'task_conflict' as const, fields: error.fields, current: error.current }); throw error; } }); + app.post('/api/v1/households/:householdId/tasks/:id/order', { schema: { params: item, body: z.object({ baseVersion: z.number().int().min(1), beforeId: z.uuid().nullable() }), response: { 200: taskSchema } } }, async r => service.reorder(await actor(r), r.params.householdId, r.params.id, r.body.baseVersion, r.body.beforeId)); app.get('/api/v1/households/:householdId/entities', { schema: { params: scope, response: { 200: z.array(entitySchema) } } }, async request => service.entityList(await actor(request), request.params.householdId)); app.post('/api/v1/households/:householdId/entities', { schema: { params: scope, body: entityCreateSchema, response: { 200: entitySchema } } }, async request => service.entityWrite(await actor(request), request.params.householdId, request.body)); app.patch('/api/v1/households/:householdId/entities/:id', { schema: { params: item, body: entityPatchSchema, response: { 200: entitySchema } } }, async request => service.entityWrite(await actor(request), request.params.householdId, request.body.changes, request.params.id, request.body.baseVersion)); diff --git a/apps/api/src/tasks/schema.ts b/apps/api/src/tasks/schema.ts index 8d78733..88b8eca 100644 --- a/apps/api/src/tasks/schema.ts +++ b/apps/api/src/tasks/schema.ts @@ -1,4 +1,4 @@ -import { pgTable, pgEnum, uuid, text, integer, boolean, timestamp, doublePrecision, jsonb, primaryKey, index } from 'drizzle-orm/pg-core'; +import { pgTable, pgEnum, uuid, text, integer, boolean, timestamp, doublePrecision, jsonb, primaryKey, index, type AnyPgColumn } from 'drizzle-orm/pg-core'; import { households, users } from '../accounts/schema.js'; export const kindEnum = pgEnum('entity_kind', ['epic', 'place', 'resource', 'tag']); export const statusEnum = pgEnum('task_status', ['todo', 'in_progress', 'done']); @@ -15,6 +15,8 @@ export const entities = pgTable('planning_entities', { export const tasks = pgTable('tasks', { id: uuid('id').primaryKey().defaultRandom(), householdId: uuid('household_id').notNull().references(() => households.id, { onDelete: 'cascade' }), + parentId: uuid('parent_id').references((): AnyPgColumn => tasks.id, { onDelete: 'restrict' }), + inherit: jsonb('inherit').$type<('epicId' | 'high' | 'startDate' | 'deadlineDate' | 'assignees')[]>().notNull().default([]), title: text('title').notNull(), description: text('description').notNull().default(''), status: statusEnum('status').notNull().default('todo'), bucket: bucketEnum('planning_bucket').notNull().default('someday'), precedingColumn: text('preceding_column'), @@ -29,8 +31,9 @@ export const tasks = pgTable('tasks', { updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(), createdBy: uuid('created_by').references(() => users.id, { onDelete: 'set null' }), completedAt: timestamp('completed_at', { withTimezone: true }), completedBy: uuid('completed_by').references(() => users.id, { onDelete: 'set null' }), + trashRootId: uuid('trash_root_id'), archivedAt: timestamp('archived_at', { withTimezone: true }), trashedAt: timestamp('trashed_at', { withTimezone: true }), -}, t => [index('task_household_order_idx').on(t.householdId, t.order), index('task_epic_idx').on(t.epicId)]); +}, t => [index('task_household_order_idx').on(t.householdId, t.order), index('task_epic_idx').on(t.epicId), index('task_parent_idx').on(t.parentId)]); export const taskEntities = pgTable('task_entities', { taskId: uuid('task_id').notNull().references(() => tasks.id, { onDelete: 'cascade' }), entityId: uuid('entity_id').notNull().references(() => entities.id, { onDelete: 'cascade' }), @@ -50,3 +53,17 @@ export const planningSettings = pgTable('planning_settings', { thresholds: jsonb('size_thresholds').$type<[number, number, number, number]>().notNull().default([60, 240, 480, 1440]), version: integer('version').notNull().default(1), }); + +export const taskEntityExclusions = pgTable('task_entity_exclusions', { + taskId: uuid('task_id').notNull().references(() => tasks.id, { onDelete: 'cascade' }), + entityId: uuid('entity_id').notNull().references(() => entities.id, { onDelete: 'cascade' }), +}, t => [primaryKey({ columns: [t.taskId, t.entityId] })]); +export const taskDependencies = pgTable('task_dependencies', { + blockedTaskId: uuid('blocked_task_id').notNull().references(() => tasks.id, { onDelete: 'cascade' }), + // Retain the identity after permanent deletion; a missing blocker is unresolved. + blockingTaskId: uuid('blocking_task_id').notNull(), +}, t => [primaryKey({ columns: [t.blockedTaskId, t.blockingTaskId] }), index('dependency_blocker_idx').on(t.blockingTaskId)]); +export const taskRelations = pgTable('task_relations', { + firstId: uuid('first_id').notNull().references(() => tasks.id, { onDelete: 'cascade' }), + secondId: uuid('second_id').notNull().references(() => tasks.id, { onDelete: 'cascade' }), +}, t => [primaryKey({ columns: [t.firstId, t.secondId] }), index('relation_second_idx').on(t.secondId)]); diff --git a/apps/api/src/tasks/service.ts b/apps/api/src/tasks/service.ts index b2a829a..3c1b24e 100644 --- a/apps/api/src/tasks/service.ts +++ b/apps/api/src/tasks/service.ts @@ -1,12 +1,16 @@ -import { and, asc, eq, gt, inArray, isNull, max } from 'drizzle-orm'; +import { occurrences, templates } from '../lifecycle/schema.js'; +import { files } from '../content/schema.js'; +import { inspectRichText } from '../content/rich-text.js'; +import { and, asc, eq, inArray, isNull, max, or, sql } from 'drizzle-orm'; import { z } from 'zod'; -import { taskFields, taskSchema, entitySchema, type Task, type TaskChanges, type TaskFields, type taskCreateSchema, type entityCreateSchema, type entityPatchSchema } from '@tendly/shared'; +import { taskFields, taskSchema, entitySchema, inheritedFields, type Task, type TaskChanges, type TaskFields, type taskCreateSchema, type entityCreateSchema, type entityPatchSchema } from '@tendly/shared'; import type { Database, QueryDatabase, Transaction } from '../accounts/database.js'; import { householdAccess, type Actor } from '../accounts/access.js'; import { households, memberships } from '../accounts/schema.js'; import { AccountError } from '../accounts/errors.js'; -import { entities, tasks, taskEntities, taskAssignees, taskActivities, planningSettings } from './schema.js'; -import { availability, moveTaskToColumn, suggestSize, taskColumn } from './domain.js'; +import { entities, tasks, taskEntities, taskAssignees, taskActivities, planningSettings, taskEntityExclusions, taskDependencies, taskRelations } from './schema.js'; +import { resolveGraph } from './graph.js'; +import { moveTaskToColumn, suggestSize, taskColumn } from './domain.js'; type Row = typeof tasks.$inferSelect; export class TaskConflict extends AccountError { @@ -26,58 +30,107 @@ export class TaskService { const [row] = await db.select().from(planningSettings).where(eq(planningSettings.householdId, householdId)); return row ? { version: row.version, thresholds: row.thresholds } : { version: 0, thresholds: [60, 240, 480, 1440] as [number, number, number, number] }; } + async graph(db: QueryDatabase, householdId: string, timezone: string) { + const rows = await db.select().from(tasks).where(eq(tasks.householdId, householdId)).orderBy(asc(tasks.order)); + const links = await db.select({ taskId: taskEntities.taskId, id: entities.id, kind: entities.kind }).from(taskEntities).innerJoin(tasks, eq(tasks.id, taskEntities.taskId)).innerJoin(entities, eq(entities.id, taskEntities.entityId)).where(eq(tasks.householdId, householdId)); + const exclusions = await db.select({ taskId: taskEntityExclusions.taskId, id: entities.id, kind: entities.kind }).from(taskEntityExclusions).innerJoin(tasks, eq(tasks.id, taskEntityExclusions.taskId)).innerJoin(entities, eq(entities.id, taskEntityExclusions.entityId)).where(eq(tasks.householdId, householdId)); + const assignments = await db.select({ taskId: taskAssignees.taskId, userId: taskAssignees.userId }).from(taskAssignees).innerJoin(tasks, eq(tasks.id, taskAssignees.taskId)).where(eq(tasks.householdId, householdId)); + const dependencies = await db.select({ blocked: taskDependencies.blockedTaskId, blocker: taskDependencies.blockingTaskId }).from(taskDependencies).innerJoin(tasks, eq(tasks.id, taskDependencies.blockedTaskId)).where(eq(tasks.householdId, householdId)); + const relations = await db.select({ first: taskRelations.firstId, second: taskRelations.secondId }).from(taskRelations).innerJoin(tasks, eq(tasks.id, taskRelations.firstId)).where(eq(tasks.householdId, householdId)); + const collect = (records: T[], owner: (record: T) => string) => { + const map = new Map(); + for (const record of records) { const key = owner(record); const list = map.get(key) ?? []; list.push(record); map.set(key, list); } + return map; + }; + const localLinks = collect(links, l => l.taskId), localExclusions = collect(exclusions, l => l.taskId); + const localAssignments = collect(assignments, a => a.taskId), localDependencies = collect(dependencies, d => d.blocked); + const related = new Map(); + for (const pair of relations) { related.set(pair.first, [...(related.get(pair.first) ?? []), pair.second]); related.set(pair.second, [...(related.get(pair.second) ?? []), pair.first]); } + const graph = resolveGraph(rows.map(row => ({ id: row.id, trashed: !!row.trashedAt, local: taskFields.parse({ + ...row, column: taskColumn(row), + assignees: (localAssignments.get(row.id) ?? []).map(a => a.userId).sort(), + ...Object.fromEntries(['place', 'resource', 'tag'].flatMap(kind => [ + [kind + 's', (localLinks.get(row.id) ?? []).filter(l => l.kind === kind).map(l => l.id).sort()], + [kind + 'Exclusions', (localExclusions.get(row.id) ?? []).filter(l => l.kind === kind).map(l => l.id).sort()], + ])), + blockers: (localDependencies.get(row.id) ?? []).map(d => d.blocker).sort(), related: (related.get(row.id) ?? []).sort(), + }) })), timezone); + const series = await db.select({ rootId: occurrences.rootId, templateId: occurrences.templateId }).from(occurrences).innerJoin(templates, eq(templates.id, occurrences.templateId)).where(eq(templates.householdId, householdId)); + const byId = new Map(rows.map(row => [row.id, row])); + return { rows, graph, task: (id: string) => { + const row = byId.get(id); + if (!row || row.trashedAt) throw new AccountError('task_not_found', 404); + const details = graph.details(id); + const recurrenceTemplateId = series.find(s => s.rootId === id || details.ancestors.some(a => a.id === s.rootId))?.templateId ?? null; + return taskSchema.parse({ ...row, ...details, recurrenceTemplateId, createdAt: row.createdAt.toISOString(), updatedAt: row.updatedAt.toISOString(), completedAt: row.completedAt?.toISOString() ?? null }); + } }; + } async hydrate(db: QueryDatabase, rows: Row[], timezone: string): Promise { if (!rows.length) return []; - const ids = rows.map(r => r.id); - const links = await db.select({ taskId: taskEntities.taskId, id: entities.id, kind: entities.kind }).from(taskEntities).innerJoin(entities, eq(entities.id, taskEntities.entityId)).where(inArray(taskEntities.taskId, ids)); - const assignees = await db.select().from(taskAssignees).where(inArray(taskAssignees.taskId, ids)); - return rows.map(row => { - const column = taskColumn(row); - return taskSchema.parse({ - ...row, column, ...availability({ ...row, column }, timezone), - createdAt: row.createdAt.toISOString(), updatedAt: row.updatedAt.toISOString(), completedAt: row.completedAt?.toISOString() ?? null, - assignees: assignees.filter(a => a.taskId === row.id).map(a => a.userId).sort(), - places: links.filter(l => l.taskId === row.id && l.kind === 'place').map(l => l.id).sort(), - resources: links.filter(l => l.taskId === row.id && l.kind === 'resource').map(l => l.id).sort(), - tags: links.filter(l => l.taskId === row.id && l.kind === 'tag').map(l => l.id).sort(), - }); - }); + const context = await this.graph(db, rows[0]!.householdId, timezone); + return rows.map(row => context.task(row.id)); } async get(db: QueryDatabase, householdId: string, id: string, timezone: string) { - const [row] = await db.select().from(tasks).where(and(eq(tasks.id, id), eq(tasks.householdId, householdId), isNull(tasks.trashedAt))); - if (!row) throw new AccountError('task_not_found', 404); - return (await this.hydrate(db, [row], timezone))[0]!; - } - async list(actor: Actor, householdId: string, view: 'now' | 'board', offset: number, limit: number) { - const household = await this.scope(this.db, actor, householdId); - const selected: Row[] = []; - let cursor = -1, matched = 0, more = true; - // Bound each scan; filter before pagination. There is no silent household task cap. - // Stage 5's filter compiler will extend this same effective-result boundary. - while (more && selected.length <= limit) { - const batch = await this.db.select().from(tasks).where(and(eq(tasks.householdId, householdId), isNull(tasks.trashedAt), isNull(tasks.archivedAt), gt(tasks.order, cursor))).orderBy(asc(tasks.order)).limit(256); - more = batch.length === 256; - for (const row of batch) { - cursor = row.order; - const column = taskColumn(row); - if (view === 'now' && (!['within_month', 'todo', 'in_progress'].includes(column) || !availability({ ...row, column }, household.timezone).available)) continue; - if (matched++ >= offset) selected.push(row); + return (await this.graph(db, householdId, timezone)).task(id); + } + async list(actor: Actor, householdId: string, view: 'now' | 'board', offset: number, limit: number, includeSubtasks = false, parentId?: string, search = '') { + // One snapshot prevents mixed parent/child values during concurrent edits. + return this.db.transaction(async tx => { + const household = await this.scope(tx, actor, householdId); + const context = await this.graph(tx, householdId, household.timezone); + const selected: Task[] = []; + let matched = 0; + for (const row of context.rows) { + if (row.trashedAt || row.archivedAt || !row.title.toLocaleLowerCase().includes(search.toLocaleLowerCase())) continue; + if (parentId !== undefined ? row.parentId !== parentId : view === 'board' && !includeSubtasks && row.parentId !== null) continue; + const task = context.task(row.id); + if (view === 'now' && (!['within_month', 'todo', 'in_progress'].includes(task.column) || !task.available)) continue; + if (matched++ >= offset) selected.push(task); if (selected.length > limit) break; } + return { items: selected.slice(0, limit), nextOffset: selected.length > limit ? offset + limit : null }; + }, { isolationLevel: 'repeatable read' }); + } + async validateContent(db: QueryDatabase, householdId: string, value: string) { + const content = inspectRichText(value); + if (content.mentions.some(id => !z.uuid().safeParse(id).success)) throw new AccountError('invalid_rich_text'); + if (content.mentions.length) { + const found = await db.select().from(memberships).where(and(eq(memberships.householdId, householdId), inArray(memberships.userId, content.mentions))); + if (found.length !== content.mentions.length) throw new AccountError('invalid_task_reference'); + } + if (content.images.length) { + const found = await db.select().from(files).where(and(eq(files.householdId, householdId), inArray(files.id, content.images))); + if (found.length !== content.images.length) throw new AccountError('invalid_task_reference'); } - return { items: await this.hydrate(this.db, selected.slice(0, limit), household.timezone), nextOffset: selected.length > limit ? offset + limit : null }; } - async validate(db: QueryDatabase, householdId: string, value: TaskFields, previous?: Task) { + async validate(db: QueryDatabase, householdId: string, value: TaskFields, previous?: Task, retainedTemplate = false) { + await this.validateContent(db, householdId, value.description); if ((!value.startDate && value.startTime) || (!value.deadlineDate && value.deadlineTime)) throw new AccountError('date_required'); const expected = [ ...(value.epicId ? [{ id: value.epicId, kind: 'epic' }] : []), + ...value.placeExclusions.map(id => ({ id, kind: 'place' })), ...value.resourceExclusions.map(id => ({ id, kind: 'resource' })), ...value.tagExclusions.map(id => ({ id, kind: 'tag' })), ...value.places.map(id => ({ id, kind: 'place' })), ...value.resources.map(id => ({ id, kind: 'resource' })), ...value.tags.map(id => ({ id, kind: 'tag' })), ]; const records = expected.length ? await db.select().from(entities).where(and(eq(entities.householdId, householdId), inArray(entities.id, expected.map(e => e.id)))) : []; for (const item of expected) { const record = records.find(e => e.id === item.id && e.kind === item.kind); if (!record) throw new AccountError('invalid_task_reference'); - if (record.archived && (item.kind === 'epic' ? previous?.epicId !== item.id : ![...(previous?.places ?? []), ...(previous?.resources ?? []), ...(previous?.tags ?? [])].includes(item.id))) throw new AccountError('entity_archived'); + if (record.archived && !retainedTemplate && (item.kind === 'epic' ? previous?.epicId !== item.id : ![...(previous?.places ?? []), ...(previous?.resources ?? []), ...(previous?.tags ?? [])].includes(item.id))) throw new AccountError('entity_archived'); + } + const references = [...new Set([...(value.parentId ? [value.parentId] : []), ...value.blockers, ...value.related])]; + if (references.length) { + const found = await db.select({ id: tasks.id }).from(tasks).where(and(eq(tasks.householdId, householdId), inArray(tasks.id, references), isNull(tasks.trashedAt))); + const known = new Set(found.map(t => t.id)); + // Previously deleted blockers remain removable and unresolved, never silently completed. + if (references.some(id => !known.has(id) && !(previous?.local.blockers.includes(id) && value.blockers.includes(id) && value.parentId !== id && !value.related.includes(id)))) throw new AccountError('invalid_task_reference'); + if (previous && value.related.includes(previous.id)) throw new AccountError('invalid_task_reference'); + } + if (previous && value.parentId && value.parentId !== previous.parentId) { + const descendants = await db.execute<{ id: string }>(sql`WITH RECURSIVE descendants AS ( + SELECT id FROM tasks WHERE id = ${previous.id} AND household_id = ${householdId} + UNION SELECT t.id FROM tasks t JOIN descendants d ON t.parent_id = d.id WHERE t.household_id = ${householdId} + ) SELECT id FROM descendants WHERE id = ${value.parentId}`); + if (descendants.rows.length) throw new AccountError('task_cycle'); } if (value.assignees.length) { const members = await db.select().from(memberships).where(and(eq(memberships.householdId, householdId), inArray(memberships.userId, value.assignees))); @@ -91,17 +144,35 @@ export class TaskService { await db.delete(taskAssignees).where(eq(taskAssignees.taskId, id)); if (value.assignees.length) await db.insert(taskAssignees).values([...new Set(value.assignees)].map(userId => ({ taskId: id, userId }))); } + async graphCollections(db: Transaction, id: string, value: TaskFields, actorId: string | null) { + await db.delete(taskEntityExclusions).where(eq(taskEntityExclusions.taskId, id)); + const excluded = [...new Set([...value.placeExclusions, ...value.resourceExclusions, ...value.tagExclusions])]; + if (excluded.length) await db.insert(taskEntityExclusions).values(excluded.map(entityId => ({ taskId: id, entityId }))); + await db.delete(taskDependencies).where(eq(taskDependencies.blockedTaskId, id)); + if (value.blockers.length) await db.insert(taskDependencies).values([...new Set(value.blockers)].map(blockingTaskId => ({ blockedTaskId: id, blockingTaskId }))); + const old = await db.select().from(taskRelations).where(or(eq(taskRelations.firstId, id), eq(taskRelations.secondId, id))); + const previous = old.map(pair => pair.firstId === id ? pair.secondId : pair.firstId); + const changed = new Set([...previous.filter(peer => !value.related.includes(peer)), ...value.related.filter(peer => !previous.includes(peer))]); + if (!changed.size) return; + await db.delete(taskRelations).where(or(eq(taskRelations.firstId, id), eq(taskRelations.secondId, id))); + if (value.related.length) await db.insert(taskRelations).values([...new Set(value.related)].map(peer => { const [firstId, secondId] = [id, peer].sort(); return { firstId: firstId!, secondId: secondId! }; })); + for (const peer of changed) { + const [row] = await db.select().from(tasks).where(eq(tasks.id, peer)); + if (!row) continue; + await db.update(tasks).set({ version: row.version + 1, fieldVersions: { ...row.fieldVersions, related: row.version + 1 }, updatedAt: new Date() }).where(eq(tasks.id, peer)); + await db.insert(taskActivities).values({ taskId: peer, actorId, version: row.version + 1, fields: ['related'] }); + } + } values(value: TaskFields) { - const { column: _column, places: _places, resources: _resources, tags: _tags, assignees: _assignees, ...plain } = value; - void _column; void _places; void _resources; void _tags; void _assignees; + const { blockers: _blockers, related: _related, placeExclusions: _pe, resourceExclusions: _re, tagExclusions: _te, column: _column, places: _places, resources: _resources, tags: _tags, assignees: _assignees, ...plain } = value; + void _blockers; void _related; void _pe; void _re; void _te; void _column; void _places; void _resources; void _tags; void _assignees; return plain; } async create(actor: Actor, householdId: string, input: z.infer) { return this.db.transaction(async tx => { const household = await this.scope(tx, actor, householdId, true); - const value = taskFields.parse({ description: '', column: 'someday', epicId: null, high: false, size: null, estimateMinutes: null, startDate: null, startTime: null, deadlineDate: null, deadlineTime: null, assignees: [], places: [], resources: [], tags: [], ...input }); + const value = taskFields.parse({ parentId: null, inherit: input.parentId ? inheritedFields.filter(field => input[field] === undefined) : [], placeExclusions: [], resourceExclusions: [], tagExclusions: [], blockers: [], related: [], description: '', column: 'someday', epicId: null, high: false, size: null, estimateMinutes: null, startDate: null, startTime: null, deadlineDate: null, deadlineTime: null, assignees: [], places: [], resources: [], tags: [], ...input }); await this.validate(tx, householdId, value); - if (value.column === 'in_progress' && !availability(value, household.timezone).available && !input.confirmUnavailable) throw new AccountError('confirm_unavailable', 409); if (!value.size && value.estimateMinutes) value.size = suggestSize(value.estimateMinutes, (await this.settings(tx, householdId)).thresholds); const [last] = await tx.select({ value: max(tasks.order) }).from(tasks).where(eq(tasks.householdId, householdId)); const workflow = moveTaskToColumn({ status: 'todo', bucket: 'someday', precedingColumn: null }, value.column); @@ -110,17 +181,32 @@ export class TaskService { completedAt: value.column === 'done' ? new Date() : null, completedBy: value.column === 'done' ? actor.user.id : null, }).returning(); await this.collections(tx, row!.id, value); + await this.graphCollections(tx, row!.id, value, actor.user.id); + for (const [index, title] of (input.subtasks ?? []).entries()) { + const child = taskFields.parse({ ...value, title, description: '', column: 'someday', parentId: row!.id, inherit: [...inheritedFields], epicId: null, high: false, size: null, estimateMinutes: null, startDate: null, startTime: null, deadlineDate: null, deadlineTime: null, assignees: [], places: [], resources: [], tags: [], placeExclusions: [], resourceExclusions: [], tagExclusions: [], blockers: [], related: [] }); + const [inserted] = await tx.insert(tasks).values({ ...this.values(child), householdId, order: (last?.value ?? 0) + (index + 2) * 1024, createdBy: actor.user.id }).returning(); + await tx.insert(taskActivities).values({ taskId: inserted!.id, actorId: actor.user.id, version: 1, fields: ['created'] }); + } + const created = await this.graph(tx, householdId, household.timezone); + created.graph.validateDependencies(); + if (value.column === 'done' && input.subtasks?.length && !input.confirmDescendants) throw new AccountError('confirm_descendants', 409); + if (value.column === 'in_progress' && !created.task(row!.id).available && !input.confirmUnavailable) throw new AccountError('confirm_unavailable', 409); await tx.insert(taskActivities).values({ taskId: row!.id, actorId: actor.user.id, version: 1, fields: ['created'] }); - return this.get(tx, householdId, row!.id, household.timezone); + return created.task(row!.id); }); } - async patch(actor: Actor, householdId: string, id: string, baseVersion: number, changes: TaskChanges, confirmUnavailable = false) { + async patch(actor: Actor, householdId: string, id: string, baseVersion: number, changes: TaskChanges, confirmUnavailable = false, confirmDescendants = false) { return this.db.transaction(async tx => { + // The household row serializes all graph writers, including reparenting and edge edits. + // Validate after tentative writes so the transaction rolls back any effective cycle. const household = await this.scope(tx, actor, householdId, true); const [row] = await tx.select().from(tasks).where(and(eq(tasks.id, id), eq(tasks.householdId, householdId), isNull(tasks.trashedAt))).for('update'); if (!row) throw new AccountError('task_not_found', 404); const current = (await this.hydrate(tx, [row], household.timezone))[0]!; const checked = new Set(Object.keys(changes)); + if (['inherit', 'parentId'].some(key => checked.has(key))) inheritedFields.forEach(key => checked.add(key)); + if (inheritedFields.some(key => checked.has(key))) { checked.add('inherit'); checked.add('parentId'); } + for (const [add, exclude] of [['places', 'placeExclusions'], ['resources', 'resourceExclusions'], ['tags', 'tagExclusions']]) if (checked.has(add!) || checked.has(exclude!)) { checked.add(add!); checked.add(exclude!); checked.add('parentId'); } // Date and optional time form one logical field, even when edited separately. for (const pair of [['startDate', 'startTime'], ['deadlineDate', 'deadlineTime']]) { if (pair.some(key => checked.has(key))) pair.forEach(key => checked.add(key)); @@ -128,19 +214,22 @@ export class TaskService { const conflicts = [...checked].filter(key => (row.fieldVersions[key] ?? 1) > baseVersion); if (baseVersion > row.version || conflicts.length) throw new TaskConflict(current, conflicts.length ? conflicts : Object.keys(changes)); const workflow = moveTaskToColumn(row, changes.column ?? current.column); - const next = taskFields.parse({ ...current, ...changes, column: taskColumn(workflow) }); + const next = taskFields.parse({ ...current.local, ...changes, column: taskColumn(workflow) }); + if (changes.inherit === undefined && current.local.inherit.includes('startDate') && (changes.startDate !== undefined || changes.startTime !== undefined)) { next.startDate = changes.startDate === undefined ? current.startDate : changes.startDate; next.startTime = changes.startTime === undefined ? current.startTime : changes.startTime; } + if (changes.inherit === undefined && current.local.inherit.includes('deadlineDate') && (changes.deadlineDate !== undefined || changes.deadlineTime !== undefined)) { next.deadlineDate = changes.deadlineDate === undefined ? current.deadlineDate : changes.deadlineDate; next.deadlineTime = changes.deadlineTime === undefined ? current.deadlineTime : changes.deadlineTime; } + if (changes.inherit === undefined) next.inherit = next.inherit.filter(key => changes[key] === undefined && !(key === 'startDate' && changes.startTime !== undefined) && !(key === 'deadlineDate' && changes.deadlineTime !== undefined)); if (!next.startDate) next.startTime = null; if (!next.deadlineDate) next.deadlineTime = null; const changed = new Set(Object.keys(changes)); - if (next.startTime !== current.startTime) changed.add('startTime'); - if (next.deadlineTime !== current.deadlineTime) changed.add('deadlineTime'); + if (JSON.stringify(next.inherit) !== JSON.stringify(current.local.inherit)) changed.add('inherit'); + if (next.startTime !== current.local.startTime) changed.add('startTime'); + if (next.deadlineTime !== current.local.deadlineTime) changed.add('deadlineTime'); // An exact duration only suggests an empty size; explicit sizes always survive. if (!next.size && next.estimateMinutes && changes.estimateMinutes !== undefined && changes.size === undefined && (row.fieldVersions.size ?? 1) <= baseVersion) { next.size = suggestSize(next.estimateMinutes, (await this.settings(tx, householdId)).thresholds); changed.add('size'); } await this.validate(tx, householdId, next, current); - if (next.column === 'in_progress' && current.column !== 'in_progress' && !availability(next, household.timezone).available && !confirmUnavailable) throw new AccountError('confirm_unavailable', 409); const version = row.version + 1; const fieldVersions = { ...row.fieldVersions, ...Object.fromEntries([...changed].map(key => [key, version])) }; // Completion metadata changes with the visible column, never with unrelated edits. @@ -150,7 +239,36 @@ export class TaskService { }; await tx.update(tasks).set({ ...this.values(next), ...workflow, ...completion, version, fieldVersions, updatedAt: new Date() }).where(eq(tasks.id, id)); await this.collections(tx, id, next); + await this.graphCollections(tx, id, next, actor.user.id); + const updated = await this.graph(tx, householdId, household.timezone); + updated.graph.validateDependencies(); + const resolved = updated.task(id); + if (next.column === 'in_progress' && current.column !== 'in_progress' && !resolved.available && !confirmUnavailable) throw new AccountError('confirm_unavailable', 409); + if (next.column === 'done' && current.column !== 'done' && resolved.unfinishedDescendants && !confirmDescendants) throw new AccountError('confirm_descendants', 409); await tx.insert(taskActivities).values({ taskId: id, actorId: actor.user.id, version, fields: [...changed] }); + return resolved; + }); + } + async reorder(actor: Actor, householdId: string, id: string, baseVersion: number, beforeId: string | null) { + return this.db.transaction(async tx => { + const household = await this.scope(tx, actor, householdId, true); + const rows = await tx.select().from(tasks).where(and(eq(tasks.householdId, householdId), isNull(tasks.trashedAt))).orderBy(asc(tasks.order), asc(tasks.id)); + const current = rows.find(r => r.id === id); + if (!current) throw new AccountError('task_not_found', 404); + if ((current.fieldVersions.order ?? 1) > baseVersion || baseVersion > current.version) throw new AccountError('planning_conflict', 409); + if (beforeId === id) return this.get(tx, householdId, id, household.timezone); + const others = rows.filter(r => r.id !== id); + const index = beforeId ? others.findIndex(r => r.id === beforeId) : others.length; + if (index < 0) throw new AccountError('invalid_task_reference'); + const next = others[index]?.order, previous = others[index - 1]?.order; + const order = previous === undefined ? (next ?? 1024) - 1024 : next === undefined ? previous + 1024 : (previous + next) / 2; + // Rebalance only when floating-point gaps are exhausted. Relative order is unchanged. + if (order === previous || order === next) { + others.splice(index, 0, current); + for (const [i, row] of others.entries()) await tx.update(tasks).set({ order: (i + 1) * 1024 }).where(eq(tasks.id, row.id)); + } else await tx.update(tasks).set({ order }).where(eq(tasks.id, id)); + await tx.update(tasks).set({ version: current.version + 1, fieldVersions: { ...current.fieldVersions, order: current.version + 1 }, updatedAt: new Date() }).where(eq(tasks.id, id)); + await tx.insert(taskActivities).values({ taskId: id, actorId: actor.user.id, version: current.version + 1, fields: ['order'] }); return this.get(tx, householdId, id, household.timezone); }); } @@ -181,13 +299,25 @@ export class TaskService { if (!entity) throw new AccountError('entity_not_found', 404); if (entity.version !== baseVersion) throw new AccountError('entity_conflict', 409); const linked = await tx.select({ taskId: taskEntities.taskId }).from(taskEntities).where(eq(taskEntities.entityId, id)); - const affected = await tx.select().from(tasks).where(and(eq(tasks.householdId, householdId), entity.kind === 'epic' ? eq(tasks.epicId, id) : inArray(tasks.id, linked.map(l => l.taskId)))); + const excluded = await tx.select({ taskId: taskEntityExclusions.taskId }).from(taskEntityExclusions).where(eq(taskEntityExclusions.entityId, id)); + const affected = await tx.select().from(tasks).where(and(eq(tasks.householdId, householdId), entity.kind === 'epic' ? eq(tasks.epicId, id) : inArray(tasks.id, [...linked, ...excluded].map(l => l.taskId)))); const field = entity.kind === 'epic' ? 'epicId' : ({ place: 'places', resource: 'resources', tag: 'tags' } as const)[entity.kind]; for (const task of affected) { - await tx.update(tasks).set({ version: task.version + 1, fieldVersions: { ...task.fieldVersions, [field]: task.version + 1 }, updatedAt: new Date() }).where(eq(tasks.id, task.id)); + await tx.update(tasks).set({ version: task.version + 1, fieldVersions: { ...task.fieldVersions, [field]: task.version + 1, ...(entity.kind !== 'epic' ? { [entity.kind + 'Exclusions']: task.version + 1 } : {}) }, updatedAt: new Date() }).where(eq(tasks.id, task.id)); await tx.insert(taskActivities).values({ taskId: task.id, actorId: actor.user.id, version: task.version + 1, fields: [field] }); } await tx.delete(entities).where(eq(entities.id, id)); + // JSON template references need the same deletion semantics as task FKs. + // Otherwise deleting a tag/epic would break every future occurrence. + const saved = await tx.select().from(templates).where(eq(templates.householdId, householdId)); + for (const template of saved) { + const nodes = template.nodes.map(node => ({ ...node, value: { ...node.value, + epicId: node.value.epicId === id ? null : node.value.epicId, + places: node.value.places.filter(value => value !== id), resources: node.value.resources.filter(value => value !== id), tags: node.value.tags.filter(value => value !== id), + placeExclusions: node.value.placeExclusions.filter(value => value !== id), resourceExclusions: node.value.resourceExclusions.filter(value => value !== id), tagExclusions: node.value.tagExclusions.filter(value => value !== id), + } })); + if (JSON.stringify(nodes) !== JSON.stringify(template.nodes)) await tx.update(templates).set({ nodes, version: template.version + 1 }).where(eq(templates.id, template.id)); + } }); } async reorderEntity(actor: Actor, householdId: string, id: string, direction: 'up' | 'down', baseVersion: number) { diff --git a/apps/api/src/tasks/tasks.integration.test.ts b/apps/api/src/tasks/tasks.integration.test.ts index 5ef95c1..d628237 100644 --- a/apps/api/src/tasks/tasks.integration.test.ts +++ b/apps/api/src/tasks/tasks.integration.test.ts @@ -1,3 +1,6 @@ +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { rm } from 'node:fs/promises'; import { beforeAll, afterAll, expect, it } from 'vitest'; import { randomUUID } from 'node:crypto'; import pg from 'pg'; @@ -13,6 +16,7 @@ import { buildApp } from '../app.js'; let planning: TaskService; const origin = 'https://accounts.example.test'; const databaseName = `tendly_test_${randomUUID().replaceAll('-', '')}`; +const filesDirectory = join(tmpdir(), databaseName); let root: pg.Client; let pool: pg.Pool; let db: ReturnType>; @@ -46,9 +50,10 @@ beforeAll(async () => { await db.insert(schema.households).values([{ id: householdA, name: 'A', timezone: 'Europe/Stockholm' }, { id: householdB, name: 'B', timezone: 'UTC' }]); await db.insert(schema.memberships).values([{ householdId: householdA, userId: userA, role: 'admin' }, { householdId: householdB, userId: userB, role: 'member' }]); sessionA = await service.session(db, userA); sessionB = await service.session(db, userB); - app = await buildApp({ checkDatabase: async () => {}, accounts: { service, mail: new MailService(db, 'ab'.repeat(32), origin, async () => {}) } }); + app = await buildApp({ filesPath: filesDirectory, checkDatabase: async () => {}, accounts: { service, mail: new MailService(db, 'ab'.repeat(32), origin, async () => {}) } }); }, 30000); afterAll(async () => { + await rm(filesDirectory, { recursive: true, force: true }); await app?.close(); await pool?.end(); if (root) { await root.query(`DROP DATABASE IF EXISTS "${databaseName}"`); await root.end(); } }); @@ -114,3 +119,236 @@ it('releases a removed member’s assignments without allowing stale editors to await expect(planning.patch(actor, householdA, task.id, task.version, { assignees: [userB] })).rejects.toThrow('task_conflict'); expect((await planning.patch(actor, householdA, task.id, task.version, { title: 'Still editable' })).title).toBe('Still editable'); }); +it('resolves deep item inheritance, explicit none/false, dates and independent Now children', async () => { + const actor = (await service.findSession(sessionA))!; + const car = await planning.entityWrite(actor, householdA, { kind: 'resource', name: 'Car' }); + const ladder = await planning.entityWrite(actor, householdA, { kind: 'resource', name: 'Ladder' }); + const trailer = await planning.entityWrite(actor, householdA, { kind: 'resource', name: 'Trailer' }); + let parent = await planning.create(actor, householdA, { title: 'Parent', resources: [car.id, ladder.id], high: true, startDate: '2099-01-01', startTime: '09:00', deadlineDate: '2099-01-30', assignees: [userA] }); + const child = await planning.create(actor, householdA, { title: 'Child', parentId: parent.id, column: 'todo', resourceExclusions: [car.id], startDate: null, high: false, deadlineDate: '2099-02-05' }); + expect(child).toMatchObject({ resources: [ladder.id], high: false, startDate: null, available: true, deadlineBeyondParent: true, assignees: [userA] }); + let deep = child; + for (let i = 0; i < 12; i++) deep = await planning.create(actor, householdA, { title: `Level ${i}`, parentId: deep.id }); + parent = await planning.patch(actor, householdA, parent.id, parent.version, { resources: [car.id, ladder.id, trailer.id] }); + expect((await planning.get(db, householdA, deep.id, 'Europe/Stockholm')).resources.sort()).toEqual([ladder.id, trailer.id].sort()); + parent = await planning.patch(actor, householdA, parent.id, parent.version, { resources: [car.id, trailer.id] }); + expect((await planning.get(db, householdA, deep.id, 'Europe/Stockholm')).resources).toEqual([trailer.id]); + const now = await planning.list(actor, householdA, 'now', 0, 100); + expect(now.items.some(t => t.id === child.id)).toBe(true); + expect(now.items.some(t => t.id === parent.id)).toBe(false); + const board = await planning.list(actor, householdA, 'board', 0, 100); + expect(board.items.some(t => t.id === child.id)).toBe(false); + expect((await planning.list(actor, householdA, 'board', 0, 100, true)).items.some(t => t.id === child.id)).toBe(true); + const inherited = await planning.patch(actor, householdA, child.id, child.version, { inherit: ['high', 'startDate', 'deadlineDate', 'assignees'] }); + expect(inherited).toMatchObject({ high: true, available: false, deadlineDate: parent.deadlineDate, deadlineBeyondParent: false }); + const none = await planning.patch(actor, householdA, child.id, inherited.version, { deadlineDate: null, assignees: [] }); + expect(none).toMatchObject({ deadlineDate: null, assignees: [] }); + const timed = await planning.patch(actor, householdA, child.id, none.version, { startTime: '10:00' }); + expect(timed).toMatchObject({ startDate: '2099-01-01', startTime: '10:00' }); + expect(timed.local.inherit).not.toContain('startDate'); +}); +it('rejects cross-household graph edges, ancestry cycles and concurrent dependency cycles', async () => { + const actor = (await service.findSession(sessionA))!; + const other = await planning.create((await service.findSession(sessionB))!, householdB, { title: 'Private' }); + const a = await planning.create(actor, householdA, { title: 'Graph A' }); + for (const changes of [{ parentId: other.id }, { blockers: [other.id] }, { related: [other.id] }]) await expect(planning.patch(actor, householdA, a.id, a.version, changes)).rejects.toThrow('invalid_task_reference'); + const b = await planning.create(actor, householdA, { title: 'Graph B' }); + const race = await Promise.allSettled([planning.patch(actor, householdA, a.id, a.version, { blockers: [b.id] }), planning.patch(actor, householdA, b.id, b.version, { blockers: [a.id] })]); + expect(race.filter(result => result.status === 'fulfilled')).toHaveLength(1); + const p = await planning.create(actor, householdA, { title: 'Graph parent' }); + const c = await planning.create(actor, householdA, { title: 'Graph child', parentId: p.id }); + await expect(planning.patch(actor, householdA, p.id, p.version, { parentId: c.id })).rejects.toThrow('task_cycle'); + await expect(planning.patch(actor, householdA, p.id, p.version, { blockers: [c.id] })).rejects.toThrow('dependency_cycle'); + const independent = await planning.create(actor, householdA, { title: 'Independent', blockers: [c.id] }); + await expect(planning.patch(actor, householdA, p.id, p.version, { parentId: independent.id })).rejects.toThrow('dependency_cycle'); + const x = await planning.create(actor, householdA, { title: 'Tree X' }); + const y = await planning.create(actor, householdA, { title: 'Tree Y' }); + const treeRace = await Promise.allSettled([planning.patch(actor, householdA, x.id, x.version, { parentId: y.id }), planning.patch(actor, householdA, y.id, y.version, { parentId: x.id })]); + expect(treeRace.filter(result => result.status === 'fulfilled')).toHaveLength(1); +}); +it('counts direct progress but warns for all descendants; availability checks only effective direct blockers', async () => { + const actor = (await service.findSession(sessionA))!; + const prerequisite = await planning.create(actor, householdA, { title: 'Prerequisite' }); + const permit = await planning.create(actor, householdA, { title: 'Permit', column: 'done', blockers: [prerequisite.id] }); + const parent = await planning.create(actor, householdA, { title: 'Work', blockers: [permit.id] }); + const child = await planning.create(actor, householdA, { title: 'Child done', parentId: parent.id, column: 'done' }); + const grandchild = await planning.create(actor, householdA, { title: 'Work to do', parentId: child.id, column: 'todo' }); + expect(grandchild.available).toBe(true); // Permit is done even though its own blocker isn't. + expect(await planning.get(db, householdA, parent.id, 'UTC')).toMatchObject({ progress: { done: 1, total: 1 }, unfinishedDescendants: 1 }); + await expect(planning.patch(actor, householdA, parent.id, parent.version, { column: 'done' })).rejects.toThrow('confirm_descendants'); + const completed = await planning.patch(actor, householdA, parent.id, parent.version, { column: 'done' }, false, true); + expect(completed.column).toBe('done'); + expect((await planning.get(db, householdA, grandchild.id, 'UTC')).column).toBe('todo'); + let started = await planning.patch(actor, householdA, grandchild.id, grandchild.version, { column: 'in_progress' }); + const reopened = await planning.patch(actor, householdA, permit.id, permit.version, { column: 'todo' }); + expect(reopened.column).toBe('todo'); + expect(await planning.get(db, householdA, started.id, 'UTC')).toMatchObject({ column: 'in_progress', available: false }); + started = await planning.patch(actor, householdA, started.id, started.version, { column: 'todo' }); + await expect(planning.patch(actor, householdA, started.id, started.version, { column: 'in_progress' })).rejects.toThrow('confirm_unavailable'); + expect((await planning.patch(actor, householdA, started.id, started.version, { column: 'in_progress' }, true)).available).toBe(false); +}); +it('keeps relations bidirectional and nonblocking, protects peer edits, and preserves deleted blockers', async () => { + const actor = (await service.findSession(sessionA))!; + const a = await planning.create(actor, householdA, { title: 'Related A', column: 'todo' }); + const b = await planning.create(actor, householdA, { title: 'Related B' }); + const linked = await planning.patch(actor, householdA, a.id, a.version, { related: [b.id] }); + expect(linked.available).toBe(true); + expect((await planning.get(db, householdA, b.id, 'UTC')).related).toEqual([a.id]); + await expect(planning.patch(actor, householdA, b.id, b.version, { related: [] })).rejects.toThrow('task_conflict'); + const blocker = await planning.create(actor, householdA, { title: 'Will be removed', column: 'done' }); + const blocked = await planning.create(actor, householdA, { title: 'Survives deletion', column: 'todo', blockers: [blocker.id] }); + await pool.query('DELETE FROM tasks WHERE id = $1', [blocker.id]); + expect(await planning.get(db, householdA, blocked.id, 'UTC')).toMatchObject({ available: false, effectiveBlockers: [{ id: blocker.id, title: null, complete: false, inherited: false }] }); + const renamed = await planning.patch(actor, householdA, blocked.id, blocked.version, { title: 'Still editable' }); + expect(renamed.available).toBe(false); + expect((await planning.patch(actor, householdA, blocked.id, renamed.version, { blockers: [] })).available).toBe(true); +}); + +it('evaluates shared nested filters on effective values, isolates personal toggles and guards saved revisions', async () => { + const { PlanningService } = await import('../planning/service.js'); + const { defaultView } = await import('@tendly/shared'); + const saved = new PlanningService(db), actor = (await service.findSession(sessionA))!; + const home = await planning.entityWrite(actor, householdA, { name: 'Filter home', kind: 'place' }); + const car = await planning.entityWrite(actor, householdA, { name: 'Filter car', kind: 'resource' }); + const trailer = await planning.entityWrite(actor, householdA, { name: 'Filter trailer', kind: 'resource' }); + const parent = await planning.create(actor, householdA, { title: 'Filter parent', resources: [car.id, trailer.id], places: [home.id] }); + const child = await planning.create(actor, householdA, { title: 'Filter child', parentId: parent.id, resourceExclusions: [trailer.id], column: 'todo' }); + const filter = await saved.saveFilter(actor, householdA, { name: 'Feasible at home', icon: 'car', color: 'blue', definition: { type: 'group', operator: 'and', children: [ + { type: 'predicate', field: 'resources', operator: 'feasible', value: [car.id] }, + { type: 'predicate', field: 'places', operator: 'compatible', value: ['$place'] }, + ] } }); + const view = await saved.saveView(actor, householdA, { name: 'Focused view', icon: 'house', color: 'blue', definition: { ...defaultView(true), quickFilters: [filter.id] } }); + await saved.personal(actor, householdA, view.id, { version: 0, activeFilters: [filter.id], favorite: true, currentPlace: home.id }); + const found = await saved.results(actor, householdA, { viewId: view.id, offset: 0, limit: 100 }); + expect(found.items.map(t => t.id)).toContain(child.id); + expect(found.items.map(t => t.id)).not.toContain(parent.id); + await saved.saveFilter(actor, householdA, { ...filter, definition: { type: 'predicate', field: 'title', operator: 'eq', value: "' OR TRUE --" } }, filter.id, filter.version); + expect((await saved.results(actor, householdA, { viewId: view.id, offset: 0, limit: 100 })).count).toBe(0); + await expect(saved.saveFilter(actor, householdA, filter, filter.id, filter.version)).rejects.toThrow('planning_conflict'); + const history = await saved.history(actor, householdA, filter.id); + expect(history.map(h => h.version)).toEqual([1, 2]); + await saved.saveFilter(actor, householdA, { ...filter, definition: history[0]!.definition }, filter.id, 2); + expect((await saved.results(actor, householdA, { viewId: view.id, offset: 0, limit: 100 })).items.map(t => t.id)).toContain(child.id); + const other = (await service.findSession(sessionB))!; + await expect(saved.results(other, householdB, { viewId: view.id, offset: 0, limit: 10 })).rejects.toThrow('view_not_found'); + await expect(saved.personal(other, householdB, view.id, { version: 0, favorite: false, activeFilters: [], currentPlace: null })).rejects.toThrow('view_not_found'); + await db.insert(schema.memberships).values({ householdId: householdA, userId: userB, role: 'member' }); + try { + const personal = (await saved.library(other, householdA)).personal[view.id]!; + expect(personal.activeFilters).toEqual([]); + expect(personal.favorite).toBe(false); + await expect(saved.personal(actor, householdA, view.id, { ...personal, currentPlace: home.id })).rejects.toThrow('planning_conflict'); + } finally { await db.delete(schema.memberships).where((await import('drizzle-orm')).and((await import('drizzle-orm')).eq(schema.memberships.householdId, householdA), (await import('drizzle-orm')).eq(schema.memberships.userId, userB))); } + const reordered = await planning.reorder(actor, householdA, child.id, child.version, parent.id); + expect(reordered.order).toBeLessThan(parent.order); + await expect(planning.reorder(actor, householdA, child.id, child.version, null)).rejects.toThrow('planning_conflict'); +}); + +it('materializes recurrence once, preserves instance edits and safely restores/deletes task trees', async () => { + const { TemplateService } = await import('../lifecycle/templates.js'); + const { LifecycleService } = await import('../lifecycle/service.js'); + const { maintainHousehold } = await import('../lifecycle/worker.js'); + const { eq } = await import('drizzle-orm'); + const actor = (await service.findSession(sessionA))!, actorB = (await service.findSession(sessionB))!; + const templates = new TemplateService(db), lifecycle = new LifecycleService(db); + const epic = await planning.entityWrite(actor, householdA, { kind: 'epic', name: 'Seasonal work' }); + const root = await planning.create(actor, householdA, { title: 'Winterize', epicId: epic.id, startDate: '2030-10-01', deadlineDate: '2030-10-15' }); + const a = await planning.create(actor, householdA, { title: 'Turn off pump', parentId: root.id }); + await planning.create(actor, householdA, { title: 'Drain pipes', parentId: root.id, blockers: [a.id] }); + const template = await templates.capture(actor, householdA, root.id, 'Winterization', { anchor: '2030-10-01', interval: 1, unit: 'years', leadDays: 14, enabled: true }); + await planning.entityWrite(actor, householdA, { archived: true }, epic.id, epic.version); + await maintainHousehold(db, householdA, new Date('2030-09-16T12:00Z')); + expect(await db.select().from(schema.occurrences).where(eq(schema.occurrences.templateId, template.id))).toHaveLength(0); + await Promise.all([maintainHousehold(db, householdA, new Date('2030-09-17T12:00Z')), maintainHousehold(db, householdA, new Date('2030-09-17T12:00Z'))]); + const occurrences = await db.select().from(schema.occurrences).where(eq(schema.occurrences.templateId, template.id)); + expect(occurrences).toHaveLength(1); + const instance = await planning.get(db, householdA, occurrences[0]!.rootId, 'Europe/Stockholm'); + const pump = instance.children.find(c => c.title === 'Turn off pump')!, drain = instance.children.find(c => c.title === 'Drain pipes')!; + expect((await planning.get(db, householdA, drain.id, 'Europe/Stockholm')).blockers).toEqual([pump.id]); + expect(instance.epicId).toBe(epic.id); + await planning.entityWrite(actor, householdA, { archived: false }, epic.id, epic.version + 1); + await templates.save(actor, householdA, { ...template, name: 'Updated series', nodes: template.nodes.map(n => ({ ...n, value: { ...n.value, title: n.value.title + ' future' } })) }, template.id, template.version); + expect((await planning.get(db, householdA, instance.id, 'Europe/Stockholm')).title).toBe('Winterize'); + await expect(templates.createInstance(actorB, householdB, template.id, '2030-10-01')).rejects.toThrow('template_not_found'); + const currentRoot = await planning.get(db, householdA, root.id, 'Europe/Stockholm'); + const completed = await planning.patch(actor, householdA, root.id, currentRoot.version, { column: 'done' }, false, true); + await db.update(schema.tasks).set({ completedAt: new Date('2020-01-01') }).where(eq(schema.tasks.id, root.id)); + await maintainHousehold(db, householdA, new Date('2030-09-17T12:00Z')); + expect((await db.select().from(schema.tasks).where(eq(schema.tasks.id, root.id)))[0]!.archivedAt).toBeNull(); + await lifecycle.change(actor, householdA, root.id, completed.version, 'trash', true); + expect((await lifecycle.list(actor, householdA, 'trash')).filter(t => [root.id, a.id].includes(t.id))).toHaveLength(2); + const trashed = (await lifecycle.list(actor, householdA, 'trash')).find(t => t.id === root.id)!; + await lifecycle.change(actor, householdA, root.id, trashed.version, 'restore', false); + expect((await planning.get(db, householdA, root.id, 'Europe/Stockholm')).children).toHaveLength(2); + const blocker = await planning.create(actor, householdA, { title: 'Disposable blocker', column: 'done' }); + const dependent = await planning.create(actor, householdA, { title: 'Keep dependent', blockers: [blocker.id] }); + await expect(lifecycle.change(actor, householdA, blocker.id, blocker.version, 'delete', false)).rejects.toThrow('confirm_dependent_deletion'); + await lifecycle.change(actor, householdA, blocker.id, blocker.version, 'delete', true); + expect((await planning.get(db, householdA, dependent.id, 'Europe/Stockholm')).available).toBe(false); + await planning.entityDelete(actor, householdA, epic.id, epic.version + 2); + expect((await templates.createInstance(actor, householdA, template.id, '2031-10-01')).epicId).toBeNull(); +}); + +it('keeps rich content and downloads household-scoped, protects comment authors and searches comment text', async () => { + const { ContentService } = await import('../content/service.js'); + const content = new ContentService(db, filesDirectory), actor = (await service.findSession(sessionA))!, other = (await service.findSession(sessionB))!; + const task = await planning.create(actor, householdA, { title: 'Photo and notes' }); + const body = JSON.stringify({ type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Remember the brass fitting', marks: [{ type: 'bold' }] }] }] }); + await content.comment(actor, householdA, task.id, body); + const saved = (await content.list(actor, householdA, task.id)).comments[0]!; + await expect(content.comment(other, householdB, task.id, body)).rejects.toThrow('task_not_found'); + await db.insert(schema.memberships).values({ householdId: householdA, userId: userB, role: 'member' }); + await expect(content.comment(other, householdA, task.id, 'Changed', saved.id, saved.version)).rejects.toThrow('comment_author_required'); + await expect(content.removeComment(other, householdA, saved.id, saved.version)).rejects.toThrow('comment_author_required'); + await content.comment(actor, householdA, task.id, body, saved.id, saved.version); + await expect(content.comment(actor, householdA, task.id, 'Stale', saved.id, saved.version)).rejects.toThrow('planning_conflict'); + const unsafe = JSON.stringify({ type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'click', marks: [{ type: 'link', attrs: { href: 'javascript:alert(1)' } }] }] }] }); + await expect(planning.patch(actor, householdA, task.id, task.version, { description: unsafe })).rejects.toThrow('invalid_rich_text'); + const file = await content.upload(actor, householdA, task.id, { name: 'sample.png', base64: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=' }); + expect(file.mime).toBe('image/png'); + const response = await app.inject({ url: `/api/v1/households/${householdA}/files/${file.id}`, headers: headers(sessionA) }); + expect(response.statusCode).toBe(200); + expect(response.headers['cache-control']).toBe('private, no-store'); + expect((await app.inject({ url: `/api/v1/households/${householdB}/files/${file.id}`, headers: headers(sessionB) })).statusCode).toBe(404); + expect((await app.inject({ url: `/api/v1/households/${householdA}/files/${file.id}` })).statusCode).toBe(401); + const search = await app.inject({ method: 'POST', url: `/api/v1/households/${householdA}/search`, headers: headers(sessionA), payload: { query: 'brass fitting', definition: null, currentPlace: null } }); + expect(search.statusCode).toBe(200); + expect(search.json().tasks.map((result: { task: { id: string } }) => result.task.id)).toContain(task.id); + const imageDescription = JSON.stringify({ type: 'doc', content: [{ type: 'image', attrs: { src: `/api/v1/households/${householdA}/files/${file.id}`, alt: 'Inspection', title: null, width: null, height: null } }] }); + const withImage = await planning.patch(actor, householdA, task.id, task.version, { description: imageDescription }); + await expect(content.removeFile(actor, householdA, file.id)).rejects.toThrow('file_in_use'); + const { TemplateService } = await import('../lifecycle/templates.js'); + const { LifecycleService } = await import('../lifecycle/service.js'); + const templates = new TemplateService(db), template = await templates.capture(actor, householdA, task.id, 'Keep illustration', null); + await new LifecycleService(db).change(actor, householdA, task.id, withImage.version, 'delete', true); + const copy = await templates.createInstance(actor, householdA, template.id, '2030-10-01'); + expect(copy.description).toBe(imageDescription); + expect((await content.download(actor, householdA, file.id)).bytes.length).toBeGreaterThan(0); + +}); + +it('automatically promotes effective starts once, preserving blockers, revisions and household isolation', async () => { + const { maintainHousehold } = await import('../lifecycle/worker.js'); + const { eq } = await import('drizzle-orm'); + const actor = (await service.findSession(sessionA))!, otherActor = (await service.findSession(sessionB))!; + const parent = await planning.create(actor, householdA, { title: 'Scheduled parent', startDate: '2032-10-16' }); + const blocker = await planning.create(actor, householdA, { title: 'Still unfinished' }); + const child = await planning.create(actor, householdA, { title: 'Inherited schedule', parentId: parent.id, blockers: [blocker.id] }); + const archived = await planning.create(actor, householdA, { title: 'Archived schedule', startDate: '2032-10-16' }); + await db.update(schema.tasks).set({ archivedAt: new Date() }).where(eq(schema.tasks.id, archived.id)); + const other = await planning.create(otherActor, householdB, { title: 'Other household schedule', startDate: '2032-10-16' }); + const get = (id: string) => planning.get(db, householdA, id, 'Europe/Stockholm'); + await maintainHousehold(db, householdA, new Date('2031-10-16T10:00Z')); + expect((await get(child.id)).column).toBe('within_year'); + await maintainHousehold(db, householdA, new Date('2032-09-16T10:00Z')); + expect((await get(child.id)).column).toBe('within_month'); + await Promise.all([maintainHousehold(db, householdA, new Date('2032-10-15T22:00Z')), maintainHousehold(db, householdA, new Date('2032-10-15T22:00Z'))]); + const promoted = await get(child.id); + expect(promoted.column).toBe('todo'); + expect(promoted.available).toBe(false); + expect(promoted.blockers).toContain(blocker.id); + expect(promoted.version).toBe(child.version + 3); + expect((await get(archived.id)).column).toBe('someday'); + expect((await planning.get(db, householdB, other.id, 'UTC')).column).toBe('someday'); + await expect(planning.patch(actor, householdA, child.id, child.version, { column: 'someday' })).rejects.toThrow('task_conflict'); +}); diff --git a/apps/web/index.html b/apps/web/index.html index e4567b9..2537ff1 100644 --- a/apps/web/index.html +++ b/apps/web/index.html @@ -1,2 +1,2 @@ -Tendly
+Tendly
diff --git a/apps/web/package.json b/apps/web/package.json index 9dd30de..25a4fc9 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -1,7 +1,7 @@ { "name": "@tendly/web", "private": true, - "version": "0.0.0", + "version": "1.0.0", "license": "AGPL-3.0-or-later", "type": "module", "scripts": { @@ -11,9 +11,17 @@ }, "dependencies": { "@radix-ui/react-dialog": "1.3.1", + "@radix-ui/react-popover": "^1.3.1", "@simplewebauthn/browser": "14.0.0", "@tanstack/react-query": "5.104.2", "@tendly/shared": "workspace:*", + "@tiptap/extension-image": "3.32.0", + "@tiptap/extension-mention": "3.32.0", + "@tiptap/extension-task-item": "3.32.0", + "@tiptap/extension-task-list": "3.32.0", + "@tiptap/pm": "3.32.0", + "@tiptap/react": "3.32.0", + "@tiptap/starter-kit": "3.32.0", "i18next": "26.4.4", "leaflet": "1.9.4", "lucide-react": "1.56.0", diff --git a/apps/web/public/icon-180.png b/apps/web/public/icon-180.png new file mode 100644 index 0000000..02e0947 Binary files /dev/null and b/apps/web/public/icon-180.png differ diff --git a/apps/web/public/icon-192.png b/apps/web/public/icon-192.png new file mode 100644 index 0000000..aa6fff5 Binary files /dev/null and b/apps/web/public/icon-192.png differ diff --git a/apps/web/public/icon-512.png b/apps/web/public/icon-512.png new file mode 100644 index 0000000..7be411d Binary files /dev/null and b/apps/web/public/icon-512.png differ diff --git a/apps/web/public/icon.svg b/apps/web/public/icon.svg new file mode 100644 index 0000000..1b0d513 --- /dev/null +++ b/apps/web/public/icon.svg @@ -0,0 +1 @@ + diff --git a/apps/web/public/manifest.webmanifest b/apps/web/public/manifest.webmanifest new file mode 100644 index 0000000..67140e2 --- /dev/null +++ b/apps/web/public/manifest.webmanifest @@ -0,0 +1,25 @@ +{ + "id": "/", + "name": "Tendly", + "short_name": "Tendly", + "description": "A shared place for everything that makes a home.", + "start_url": "/", + "scope": "/", + "display": "standalone", + "background_color": "#f7f8fa", + "theme_color": "#087bff", + "icons": [ + { + "src": "/icon-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "any maskable" + }, + { + "src": "/icon-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "any maskable" + } + ] +} diff --git a/apps/web/public/offline.html b/apps/web/public/offline.html new file mode 100644 index 0000000..acf2ea9 --- /dev/null +++ b/apps/web/public/offline.html @@ -0,0 +1 @@ +Tendly · Offline

Tendly

You are offline. Connect to your Tendly server to see and update household tasks.

diff --git a/apps/web/public/sw.js b/apps/web/public/sw.js new file mode 100644 index 0000000..b7d3af4 --- /dev/null +++ b/apps/web/public/sw.js @@ -0,0 +1,14 @@ +/* global self, caches, fetch, URL */ +const CACHE = 'tendly-static-v1'; +self.addEventListener('install', event => { event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(['/offline.html', '/icon.svg']))); }); +self.addEventListener('activate', event => { event.waitUntil(caches.keys().then(keys => Promise.all(keys.filter(key => key.startsWith('tendly-static-') && key !== CACHE).map(key => caches.delete(key)))).then(() => self.clients.claim())); }); +self.addEventListener('fetch', event => { + const url = new URL(event.request.url); + // Never cache sessions, task data, files or mutations. Offline editing is deliberately unsupported. + if (event.request.method !== 'GET' || url.origin !== self.location.origin || url.pathname.startsWith('/api/')) return; + if (event.request.mode === 'navigate') { event.respondWith(fetch(event.request).catch(() => caches.match('/offline.html'))); return; } + if (url.pathname.startsWith('/assets/')) event.respondWith(caches.open(CACHE).then(async cache => { + const cached = await cache.match(event.request); if (cached) return cached; + const response = await fetch(event.request); if (response.ok) await cache.put(event.request, response.clone()); return response; + })); +}); diff --git a/apps/web/src/accounts/Invitations.tsx b/apps/web/src/accounts/Invitations.tsx index f1fbce8..e1f3e9b 100644 --- a/apps/web/src/accounts/Invitations.tsx +++ b/apps/web/src/accounts/Invitations.tsx @@ -1,12 +1,12 @@ import { useEffect, useRef, useState, type FormEvent } from 'react'; import { useTranslation } from 'react-i18next'; -import { Copy, Mail } from 'lucide-react'; +import { Copy, Mail, Ticket } from 'lucide-react'; import { api, result } from './api.js'; export function InvitationCodeEntry({ onUse }: { onUse: (code: string) => void }) { const { t } = useTranslation(); - return
- {t('haveInvitationCode')} + return
+

{ event.preventDefault(); onUse(String(new FormData(event.currentTarget).get('invitationCode')).trim()); @@ -14,7 +14,7 @@ export function InvitationCodeEntry({ onUse }: { onUse: (code: string) => void }
-
; + ; } type Run = (action: () => Promise, message?: string) => Promise; export function InvitePanel({ householdId, run, busy }: { householdId: string; run: Run; busy: boolean }) { diff --git a/apps/web/src/accounts/Settings.tsx b/apps/web/src/accounts/Settings.tsx index 007bebd..824efe3 100644 --- a/apps/web/src/accounts/Settings.tsx +++ b/apps/web/src/accounts/Settings.tsx @@ -1,7 +1,8 @@ +import { Section } from '../components/Section.js'; import { useState, type FormEvent } from 'react'; import { useTranslation } from 'react-i18next'; import { useQuery, useQueryClient } from '@tanstack/react-query'; -import { Fingerprint, House, LogOut, Mail, ShieldCheck, UserRound, UsersRound } from 'lucide-react'; +import { Settings2, Trash2, Fingerprint, House, LogOut, Mail, ShieldCheck, UserRound, UsersRound } from 'lucide-react'; import type { Account } from '@tendly/shared'; import { InvitationCodeEntry, InvitePanel } from './Invitations.js'; import { api, result } from './api.js'; @@ -11,6 +12,7 @@ type Run = (action: () => Promise, message?: string) => Promise; export function Settings({ account, refresh, link, clearLink, useInvitation, embedded = false, activeHouseholdId }: { account: Account; refresh: () => Promise; link: EntryLink; clearLink: () => void; useInvitation: (code: string) => void; embedded?: boolean; activeHouseholdId?: string }) { const { t, i18n } = useTranslation(); const queries = useQueryClient(); + const version = useQuery({ queryKey: ['version'], queryFn: () => result(api.GET('/api/v1/version')) }); const [page, setPage] = useState('account'); const [householdId, setHouseholdId] = useState(activeHouseholdId ?? account.households[0]?.id ?? ''); const household = account.households.find((item) => item.id === householdId) ?? account.households[0]; @@ -24,9 +26,9 @@ export function Settings({ account, refresh, link, clearLink, useInvitation, emb finally { setBusy(false); } }; return
-
{!embedded &&
Tendly
}
+
{embedded &&

{t('settings')}

}{!embedded &&
Tendly
}
+
Tendly {version.data?.version}
; } function AccountPanel({ account, run, busy }: { account: Account; run: Run; busy: boolean }) { @@ -58,7 +60,10 @@ function AccountPanel({ account, run, busy }: { account: Account; run: Run; busy void run(() => result(api.PATCH('/api/v1/account', { body: { name: String(data.get('name')), language: data.get('language') as 'en' | 'sv', theme: data.get('theme') as 'system' | 'light' | 'dark' } }))); } return <> -

{t('profile')}

{account.email}

+

+ {account.avatar && {account.name}} + + {account.avatar && }

{account.email}

@@ -69,7 +74,7 @@ function AccountPanel({ account, run, busy }: { account: Account; run: Run; busy

{t('passkeys')}

{t('passkeysText')}

{passkeys.isError &&

{t('network_error')}

} -
    {passkeys.data?.map((key) =>
  • {key.name}{new Date(key.createdAt).toLocaleDateString(i18n.language)}
  • )}
+
    {passkeys.data?.map((key) =>
  • {key.name}{new Date(key.createdAt).toLocaleDateString(i18n.language)}
  • )}
{ event.preventDefault(); const data = new FormData(event.currentTarget); void run(() => enroll({ flow: 'add' }, String(data.get('keyName')))); }}>

{t('sessions')}

@@ -83,11 +88,12 @@ function MembersPanel({ household, run, busy }: { household: Account['households const members = useQuery({ queryKey: ['members', household.id], queryFn: () => result(api.GET('/api/v1/households/{id}/members', { params: { path: { id: household.id } } })) }); return <>

{household.name}

{household.timezone}

+ {household.role === 'admin' &&
{ e.preventDefault(); const data = new FormData(e.currentTarget); void run(() => result(api.PUT('/api/v1/households/{id}', { params: { path: { id: household.id } }, body: { name: String(data.get('name')), timezone: String(data.get('timezone')), previousName: household.name, previousTimezone: household.timezone } }))); }}>

{t('timezoneChangeHint')}

} {members.isError &&

{t('network_error')}

}
    {members.data?.map((member) =>
  • {member.name}{member.email}
    {household.role === 'admin' ?
    -
    •••
    +
    •••
    : {t(member.role)}}
  • )}
@@ -98,9 +104,9 @@ function SmtpPanel({ run, busy }: { run: Run; busy: boolean }) { const { t } = useTranslation(); const smtp = useQuery({ queryKey: ['smtp'], queryFn: () => result(api.GET('/api/v1/settings/smtp')) }); if (smtp.isPending) return

{t('loading')}

; - if (smtp.isError) return

{t(errorKey(smtp.error))}

; + if (smtp.isError) return

{t(errorKey(smtp.error))}

; const config = smtp.data; - return

{t('smtp')}

{t('smtpText')}

{ + return

{t('smtpText')}

{ event.preventDefault(); const data = new FormData(event.currentTarget); const password = String(data.get('password')); void run(() => result(api.PUT('/api/v1/settings/smtp', { body: { host: String(data.get('host')), port: Number(data.get('port')), security: data.get('security') as 'tls' | 'starttls', username: String(data.get('username')), sender: String(data.get('sender')), ...(password ? { password } : {}) } }))); }}>
diff --git a/apps/web/src/components/Section.tsx b/apps/web/src/components/Section.tsx new file mode 100644 index 0000000..5e4a030 --- /dev/null +++ b/apps/web/src/components/Section.tsx @@ -0,0 +1,8 @@ +import { type ReactNode, useId } from 'react'; +import type { LucideIcon } from 'lucide-react'; + +/** Visible groups share a heading and landmark instead of hiding fields in disclosures. */ +export function Section({ title, icon: Icon, children, className = '' }: { title: string; icon: LucideIcon; children: ReactNode; className?: string }) { + const id = useId(); + return

{children}
; +} diff --git a/apps/web/src/components/ui/dialog.tsx b/apps/web/src/components/ui/dialog.tsx index cae9c7b..f47171d 100644 --- a/apps/web/src/components/ui/dialog.tsx +++ b/apps/web/src/components/ui/dialog.tsx @@ -4,15 +4,15 @@ import { X } from 'lucide-react'; import { useTranslation } from 'react-i18next'; // shadcn/ui's Radix composition: focus trapping, Escape and focus restoration live // in the primitive; Tendly supplies its responsive sheet treatment. -export function Dialog({ open, onOpenChange, title, children, sheet = false }: { - open: boolean; onOpenChange: (open: boolean) => void; title: string; children: ReactNode; sheet?: boolean; +export function Dialog({ open, onOpenChange, title, children, sheet = false, className = '' }: { + open: boolean; onOpenChange: (open: boolean) => void; title: string; children: ReactNode; sheet?: boolean; className?: string; }) { const { t } = useTranslation(); const returnFocus = useRef(document.activeElement); return - { + { event.preventDefault(); const target = returnFocus.current; if (target instanceof HTMLElement && target.isConnected) target.focus(); diff --git a/apps/web/src/content/ContentPanel.tsx b/apps/web/src/content/ContentPanel.tsx new file mode 100644 index 0000000..41aa7b9 --- /dev/null +++ b/apps/web/src/content/ContentPanel.tsx @@ -0,0 +1,42 @@ +import { Paperclip, Camera, MessageSquare, History, Trash2 } from 'lucide-react'; +import { lazy, Suspense, useState } from 'react'; +import { useQuery, useQueryClient } from '@tanstack/react-query'; +import { useTranslation } from 'react-i18next'; +import { api, result } from '../accounts/api.js'; +import type { Member } from '../tasks/TaskFields.js'; +const RichEditor = lazy(() => import('./RichEditor.js')); +export async function uploadFiles(householdId: string, taskId: string, files: File[], commentId: string | null = null) { + const urls: string[] = []; + for (const file of files) { + if (file.size > 16 * 1024 * 1024) throw new Error('file_too_large'); + const base64 = await new Promise((resolve, reject) => { const reader = new FileReader(); reader.onerror = reject; reader.onload = () => resolve(String(reader.result).split(',')[1]!); reader.readAsDataURL(file); }); + const saved = await result(api.POST('/api/v1/households/{householdId}/tasks/{taskId}/files', { params: { path: { householdId, taskId } }, body: { name: file.name, base64, commentId } })); + if (saved.mime.startsWith('image/')) urls.push(`/api/v1/households/${householdId}/files/${saved.id}`); + } + return urls; +} +export function ContentPanel({ householdId, taskId, actorId, members }: { householdId: string; taskId: string; actorId: string; members: Member[] }) { + const { t } = useTranslation(), queries = useQueryClient(); + const [tab, setTab] = useState<'comments' | 'activity'>('comments'), [body, setBody] = useState(''), [editing, setEditing] = useState<{ id: string; version: number } | null>(null), [error, setError] = useState(''), [busy, setBusy] = useState(false); + const content = useQuery({ queryKey: ['planning', householdId, 'content', taskId], queryFn: () => result(api.GET('/api/v1/households/{householdId}/tasks/{taskId}/content', { params: { path: { householdId, taskId } } })) }); + const refresh = () => queries.invalidateQueries({ queryKey: ['planning', householdId, 'content', taskId] }); + async function upload(files: File[], commentId: string | null = null) { setBusy(true); setError(''); try { const urls = await uploadFiles(householdId, taskId, files, commentId); await refresh(); return urls; } catch (e) { setError((e as Error).message); return []; } finally { setBusy(false); } } + async function saveComment() { + setBusy(true); setError(''); + try { + if (editing) await result(api.PUT('/api/v1/households/{householdId}/tasks/{taskId}/comments/{id}', { params: { path: { householdId, taskId, id: editing.id } }, body: { body, baseVersion: editing.version } })); + else await result(api.POST('/api/v1/households/{householdId}/tasks/{taskId}/comments', { params: { path: { householdId, taskId } }, body: { body } })); + setBody(''); setEditing(null); await refresh(); + } catch (e) { setError((e as Error).message); } finally { setBusy(false); } + } + return
{ if (e.dataTransfer.types.includes('Files')) e.preventDefault(); }} onDrop={e => { if (!e.defaultPrevented && e.dataTransfer.files.length) { e.preventDefault(); void upload(Array.from(e.dataTransfer.files)); } }}> +

{t('attachmentHint')}

+
{content.data?.files.map(file =>
{file.mime.startsWith('image/') && {file.name}}
{file.name}
)}
+ {error &&

{t(error)}

}{content.isError && } +
{(['comments', 'activity'] as const).map(key => )}
+ {tab === 'activity' ?
    {content.data?.activity.map(event =>
  1. {event.actor ?? 'Tendly'} · {event.fields.map(f => t('field_' + f, { defaultValue: t(f) })).join(', ')}
  2. )}
: {t('loading')}

}> +
{content.data?.comments.map(comment =>
{comment.author}
{content.data?.files.filter(file => file.commentId === comment.id).map(file => {file.mime.startsWith('image/') && {file.name}}{file.name})}
{comment.authorId === actorId &&
}
)}
+
upload(files, editing?.id ?? null)} />
{editing && }
+
} +
; +} diff --git a/apps/web/src/content/RichEditor.tsx b/apps/web/src/content/RichEditor.tsx new file mode 100644 index 0000000..84573ad --- /dev/null +++ b/apps/web/src/content/RichEditor.tsx @@ -0,0 +1,73 @@ +import { Bold, Italic, Heading2, List, ListOrdered, ListChecks, Quote, Code, Link, type LucideIcon } from 'lucide-react'; +import { useEffect, useRef } from 'react'; +import { useEditor, EditorContent } from '@tiptap/react'; +import StarterKit from '@tiptap/starter-kit'; +import Image from '@tiptap/extension-image'; +import TaskList from '@tiptap/extension-task-list'; +import TaskItem from '@tiptap/extension-task-item'; +import Mention from '@tiptap/extension-mention'; +import { readRichText } from '@tendly/shared'; +import { useTranslation } from 'react-i18next'; +import type { Member } from '../tasks/TaskFields.js'; +export default function RichEditor({ value, onChange, members = [], label, upload, disabled = false }: { value: string; disabled?: boolean; onChange?: ((value: string) => void) | undefined; members?: Member[]; label: string; upload?: ((files: File[]) => Promise) | undefined }) { + const { t } = useTranslation(), callback = useRef(onChange), uploadRef = useRef(upload), membersRef = useRef(members); + callback.current = onChange; uploadRef.current = upload; membersRef.current = members; + const editor = useEditor({ + // Create after React commits: a lazy sheet can delay effects long enough for + // Tiptap to dispose an instance created during render (notably in WebKit). + immediatelyRender: false, + extensions: [StarterKit.configure({ link: { openOnClick: !onChange, protocols: ['https', 'http', 'mailto'], HTMLAttributes: { rel: 'noopener noreferrer nofollow', target: '_blank' } } }), Image, TaskList, TaskItem.configure({ nested: true }), Mention.configure({ + suggestion: { + items: ({ query }) => membersRef.current.filter(m => m.name.toLocaleLowerCase().includes(query.toLocaleLowerCase())).slice(0, 8), + render: () => { + let popup: HTMLDivElement | null = null; + return { + onStart: props => { + popup = document.createElement('div'); popup.className = 'mention-menu'; popup.setAttribute('role', 'listbox'); document.body.append(popup); + const render = () => { + popup!.replaceChildren(); + for (const member of props.items) { const button = document.createElement('button'); button.type = 'button'; button.textContent = member.name; button.setAttribute('role', 'option'); button.addEventListener('mousedown', e => { e.preventDefault(); props.command({ id: member.id, label: member.name }); }); popup!.append(button); } + const rect = props.clientRect?.(); if (rect) { popup!.style.left = Math.min(rect.left, window.innerWidth - 220) + 'px'; popup!.style.top = Math.min(rect.bottom + 4, window.innerHeight - 220) + 'px'; } + }; render(); + }, + onUpdate: props => { if (!popup) return; popup.replaceChildren(); for (const member of props.items) { const button = document.createElement('button'); button.type = 'button'; button.textContent = member.name; button.setAttribute('role', 'option'); button.addEventListener('mousedown', e => { e.preventDefault(); props.command({ id: member.id, label: member.name }); }); popup.append(button); } }, + onKeyDown: ({ event }) => { if (event.key === 'Escape') { popup?.remove(); return true; } if (event.key === 'Enter' && popup?.firstElementChild) { popup.firstElementChild.dispatchEvent(new MouseEvent('mousedown', { bubbles: true })); return true; } return false; }, + onExit: () => { popup?.remove(); popup = null; }, + }; + }, + }, + })], + content: readRichText(value), editable: !!onChange && !disabled, + onUpdate: ({ editor }) => callback.current?.(JSON.stringify(editor.getJSON())), + editorProps: { attributes: { role: 'textbox', 'aria-label': label, 'aria-multiline': 'true' }, handlePaste: (_view, event) => { + const files = Array.from(event.clipboardData?.files ?? []); + if (!files.length || !uploadRef.current) return false; + void uploadRef.current(files).then(urls => { if (!editor || editor.isDestroyed) return; for (const src of urls) editor.chain().focus().setImage({ src }).run(); }); return true; + }, handleDrop: (_view, event) => { + const files = Array.from(event.dataTransfer?.files ?? []); + if (!files.length || !uploadRef.current) return false; + void uploadRef.current(files).then(urls => { if (!editor || editor.isDestroyed) return; for (const src of urls) editor.chain().focus().setImage({ src }).run(); }); return true; + } }, + }); + useEffect(() => { if (editor && !editor.isDestroyed && JSON.stringify(editor.getJSON()) !== value) editor.commands.setContent(readRichText(value), { emitUpdate: false }); }, [value, editor]); + useEffect(() => { // Changing editability is UI state, not a document edit; do not restart autosave. + if (editor && !editor.isDestroyed) editor.setEditable(!!onChange && !disabled, false); }, [editor, onChange, disabled]); + if (!editor || editor.isDestroyed) return null; + const formatIcons: Record = { bold: Bold, italic: Italic, heading: Heading2, bulletList: List, numberedList: ListOrdered, checklist: ListChecks, quote: Quote, codeBlock: Code, link: Link }; + const action = (name: string, run: () => void, active = false) => { const Icon = formatIcons[name]!; return ; }; + return
+ {onChange &&
+ {action('bold', () => editor.chain().focus().toggleBold().run(), editor.isActive('bold'))} + {action('italic', () => editor.chain().focus().toggleItalic().run(), editor.isActive('italic'))} + {action('heading', () => editor.chain().focus().toggleHeading({ level: 2 }).run(), editor.isActive('heading'))} + {action('bulletList', () => editor.chain().focus().toggleBulletList().run(), editor.isActive('bulletList'))} + {action('numberedList', () => editor.chain().focus().toggleOrderedList().run(), editor.isActive('orderedList'))} + {action('checklist', () => editor.chain().focus().toggleTaskList().run(), editor.isActive('taskList'))} + {action('quote', () => editor.chain().focus().toggleBlockquote().run(), editor.isActive('blockquote'))} + {action('codeBlock', () => editor.chain().focus().toggleCodeBlock().run(), editor.isActive('codeBlock'))} + {action('link', () => { const href = window.prompt(t('linkAddress'), String(editor.getAttributes('link').href ?? 'https://')); if (href === '') editor.chain().focus().unsetLink().run(); else if (href && /^(https?:\/\/|mailto:)/i.test(href)) editor.chain().focus().setLink({ href }).run(); })} + {!!members.length && } +
} + +
; +} diff --git a/apps/web/src/content/Search.tsx b/apps/web/src/content/Search.tsx new file mode 100644 index 0000000..980ad01 --- /dev/null +++ b/apps/web/src/content/Search.tsx @@ -0,0 +1,18 @@ +import { Section } from '../components/Section.js'; +import { ListFilter } from 'lucide-react'; +import { useEffect, useState } from 'react'; +import { useInfiniteQuery } from '@tanstack/react-query'; +import { useTranslation } from 'react-i18next'; +import { allFilter, filterAstSchema, type Task, type Entity, type FilterAst } from '@tendly/shared'; +import { api, result } from '../accounts/api.js'; +import { Dialog } from '../components/ui/dialog.js'; +import { FilterBuilder } from '../planning/FilterBuilder.js'; +import type { Member } from '../tasks/TaskFields.js'; +export function Search({ householdId, entities, members, onOpen, onClose, onEntities }: { householdId: string; entities: Entity[]; members: Member[]; onOpen: (id: string) => void; onClose: () => void; onEntities: () => void }) { + const { t } = useTranslation(), [query, setQuery] = useState(''), [definition, setDefinition] = useState(allFilter), [currentPlace, setCurrentPlace] = useState(null), [draft, setDraft] = useState({ query, definition }); + useEffect(() => { const timer = setTimeout(() => setDraft({ query, definition }), 300); return () => clearTimeout(timer); }, [query, definition]); + const search = useInfiniteQuery<{ tasks: { task: Task; archived: boolean }[]; entities: Entity[]; count: number; nextOffset: number | null }>({ queryKey: ['planning', householdId, 'search', draft, currentPlace], enabled: filterAstSchema.safeParse(draft.definition).success, initialPageParam: 0, getNextPageParam: last => last.nextOffset ?? undefined, queryFn: ({ pageParam }) => result(api.POST('/api/v1/households/{householdId}/search', { params: { path: { householdId } }, body: { ...draft, currentPlace, offset: Number(pageParam) } })) }); + return { if (!open) onClose(); }} title={t('search')}> setQuery(e.target.value)} />
+ {search.isError &&

{t('network_error')}

}

{t('resultCount', { count: search.data?.pages[0]?.count ?? 0 })}

{search.data?.pages.flatMap(p => p.tasks).map(({ task, archived }) => )}{search.data?.pages[0]?.entities.map(entity => )}
{search.hasNextPage && } +
; +} diff --git a/apps/web/src/content/useHouseholdSync.ts b/apps/web/src/content/useHouseholdSync.ts new file mode 100644 index 0000000..3eb23d3 --- /dev/null +++ b/apps/web/src/content/useHouseholdSync.ts @@ -0,0 +1,20 @@ +import { useEffect, useState } from 'react'; +import { useQueryClient } from '@tanstack/react-query'; +export function useHouseholdSync(householdId: string) { + const queries = useQueryClient(), [connected, setConnected] = useState(false); + useEffect(() => { + if (!householdId) return; + let stopped = false, socket: WebSocket | undefined, timer: ReturnType | undefined, attempts = 0; + function connect() { + const url = new URL(`/api/v1/households/${householdId}/events`, location.href); url.protocol = location.protocol === 'https:' ? 'wss:' : 'ws:'; + socket = new WebSocket(url); + socket.onopen = () => { attempts = 0; setConnected(true); void queries.invalidateQueries({ queryKey: ['planning', householdId] }); }; + socket.onmessage = () => { void queries.invalidateQueries({ queryKey: ['planning', householdId] }); }; + socket.onclose = () => { setConnected(false); if (!stopped) timer = setTimeout(connect, Math.min(30000, 1000 * 2 ** attempts++)); }; + socket.onerror = () => socket?.close(); + } + connect(); + return () => { stopped = true; clearTimeout(timer); socket?.close(); }; + }, [householdId, queries]); + return connected; +} diff --git a/apps/web/src/layout.css b/apps/web/src/layout.css new file mode 100644 index 0000000..d2e1fab --- /dev/null +++ b/apps/web/src/layout.css @@ -0,0 +1,222 @@ +/* Shared geometry. Page frames own outer spacing; children never re-center themselves. */ +:root { + --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; + --space-6: 24px; --space-8: 32px; + --page-gutter: 24px; --page-width: 1120px; --panel-padding: 24px; + --section-gap: 24px; --field-gap: 16px; --control-height: 44px; +} +.workspace-main { padding: 0 var(--page-gutter) var(--space-8); } +.workspace-utilities { + display: flex; align-items: center; gap: var(--space-2); min-height: 64px; + margin: 0; padding: var(--space-2) 0; + width: 100%; max-width: var(--page-width); +} +.workspace-utilities .utility-search { margin-left: auto; } +.workspace-utilities>.quiet { padding-inline: 0; } +.page-layout { width: 100%; max-width: var(--page-width); padding-top: var(--space-6); } +.page-layout[hidden] { display: none; } +.page-heading,.settings-heading { + display: flex; align-items: center; justify-content: space-between; + gap: var(--space-4); margin: 0 0 var(--section-gap); padding: 0; +} +.page-heading h1,.settings-heading h1 { font-size: 1.5rem; line-height: 1.3; margin: 0; } +.page-heading p { margin: var(--space-2) 0 0; } +.page-layout .library-page,.page-layout .more-links { max-width: none; } +.page-layout .app-shell { width: 100%; } +.settings-heading { min-height: var(--control-height); } +.settings-heading>button { flex-shrink: 0; } +.settings-layout,.workspace-main .settings-layout { + display: grid; grid-template-columns: 224px minmax(0,1fr); align-items: start; + gap: var(--space-8); width: 100%; max-width: none; margin: 0; padding: 0; +} +.settings-layout>aside { min-width: 0; } +.settings-layout>aside>p { margin: 0 0 var(--space-3); } +.settings-layout>aside nav { display: grid; margin: 0; gap: var(--space-1); padding: 0; } +.settings-layout>aside nav button { + justify-content: flex-start; text-align: left; gap: var(--space-3); + padding: var(--space-3); min-height: var(--control-height); line-height: 1.4; + overflow-wrap: normal; hyphens: none; +} +button>svg,h2>svg { flex-shrink: 0; } +.settings-footer { margin: var(--space-6) 0 0; padding: var(--space-4) 0; border-top: 1px solid var(--line); } +.settings-message>button { margin-top: var(--space-2); } +.panel { padding: var(--panel-padding); margin: 0 0 var(--section-gap); } +.panel>:last-child { margin-bottom: 0; } +.panel>h2,.section-heading h2 { margin: 0; font-size: 1.05rem; } +.panel>h2+* { margin-top: var(--space-3); } +.panel>p { margin: var(--space-3) 0; } +.section-heading { min-height: var(--control-height); gap: var(--space-4); margin-bottom: var(--space-3); } +form { margin-top: var(--space-4); } +label { gap: var(--space-2); margin-bottom: var(--field-gap); line-height: 1.4; } +.form-grid,.field-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 0 var(--space-4); } +input,select { min-height: var(--control-height); padding: var(--space-2) var(--space-3); } +textarea { padding: var(--space-3); } +button { padding: var(--space-2) var(--space-3); min-height: var(--control-height); } +.button-row { gap: var(--space-2); align-items: center; } +.check-label { margin: 0; gap: var(--space-2); } +.check-label input { min-height: 18px; } +fieldset>legend { font-weight: 600; margin-bottom: var(--space-3); } +fieldset+fieldset { margin-top: var(--space-6); } +.item-list,.entity-list { margin: var(--space-4) 0; } +.item-list>li,.entity-list>li { padding-block: var(--space-3); gap: var(--space-3); } +.entity-main { padding: var(--space-2) 0; } +.library-tabs { gap: var(--space-2); margin-bottom: var(--space-6); } +.planning-documents { gap: var(--space-3); margin: var(--space-3) 0 var(--space-8); } +.planning-documents article { padding: var(--space-4); gap: var(--space-4); background: var(--surface); } +.planning-documents .button-row { margin: 0; } +.more-links { gap: var(--space-3); } +.more-links>button { padding: var(--space-4); } +.dialog-content { padding: var(--panel-padding); } +.dialog-heading { margin-bottom: var(--space-4); min-height: var(--control-height); } +.dialog-heading h2 { line-height: 1.4; } +.dialog-content .button-row { margin-top: var(--space-4); } +.dialog-content .planning-documents .button-row { margin-top: 0; } +.filter-group { padding: var(--space-3); margin: var(--space-2) 0; } +.filter-rule { gap: var(--space-2); margin: var(--space-2) 0; } +.filter-child { gap: var(--space-2); } +.search-results { gap: var(--space-2); } +.search-results button { justify-content: stretch; justify-items: start; padding: var(--space-3); } +.icon-picker+button { margin-bottom: var(--space-4); } +.filter-preview { margin-top: var(--space-6); padding-top: var(--space-6); } +.auth-layout { padding: var(--space-6); } +.auth-layout>.brand { margin: 0 0 var(--space-6); } +.auth-card { padding: var(--panel-padding); } +.auth-card h1 { margin: var(--space-4) 0 var(--space-3); } +.auth-card .text-button { justify-content: flex-start; text-align: left; } +.auth-layout .locale-picker { margin: var(--space-4) auto; } +/* Compact task chrome is a deliberate density variant of the same spacing scale. */ +.task-workspace { padding: 0 var(--space-4) var(--space-8); } +.board-toolbar { margin: 0 calc(-1 * var(--space-4)) var(--space-3); padding: var(--space-2) var(--space-4); gap: var(--space-3); } +.board-toolbar .current-place { margin: 0; } +.board-toolbar .current-place select { min-height: 36px; padding: var(--space-1) var(--space-2); } +.task-detail-sheet>.dialog-heading { margin: 0; padding-inline: var(--panel-padding); } +.task-detail-sheet>.save-status { padding-inline: var(--panel-padding); } +.task-detail-sheet>.alert { margin-inline: var(--panel-padding); } +.task-detail-content { padding: var(--space-4) var(--panel-padding) var(--space-8); } +.task-detail-properties { padding: var(--panel-padding); } +.task-detail-properties .form-grid { grid-template-columns: 1fr; } +.task-detail-properties label { margin-bottom: var(--field-gap); } +.task-detail-content>fieldset+fieldset { margin-top: 0; } +.task-detail-content .content-panel { margin-top: var(--section-gap); padding-top: var(--space-4); } +.task-detail-content .task-structure { margin-top: var(--space-4); } +.task-detail-content .task-structure>section { margin-block: var(--space-4); } +.task-detail-content .subtask-capture { margin: var(--space-3) 0 var(--space-4); } +.rich-toolbar select { min-height: 32px; padding: var(--space-1); } +@media(min-width:1100px) { .planning-editor .filter-preview { margin-top: 0; padding: 0 0 0 var(--space-6); } } +@media(max-width:720px) { + :root { --page-gutter: 16px; --panel-padding: 16px; --section-gap: 24px; } + .workspace-main,.task-workspace { padding: 0 var(--page-gutter) calc(96px + env(safe-area-inset-bottom)); } + .workspace-utilities { min-height: 56px; } + .page-layout { padding-top: var(--space-4); } + .page-heading,.settings-heading { gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; } + .page-heading h1,.settings-heading h1 { font-size: 1.3rem; } + .settings-layout,.workspace-main .settings-layout { grid-template-columns: 1fr; gap: var(--space-4); } + .settings-layout>aside nav,.workspace-main .settings-layout aside nav { display: flex; overflow-x: auto; gap: var(--space-1); padding-bottom: var(--space-1); } + .settings-layout>aside nav button { white-space: nowrap; flex-shrink: 0; padding: var(--space-2) var(--space-3); } + .form-grid,.field-grid { grid-template-columns: 1fr; } + .settings-footer { margin-top: var(--space-4); } + .member-actions { flex-wrap: wrap; max-width: 100%; } + .planning-documents article { gap: var(--space-3); } + .planning-documents article>.button-row { flex-basis: 100%; } + .planning-documents .button-row button { flex: 0 1 auto; } + .dialog-content { padding: var(--panel-padding); padding-top: max(16px,env(safe-area-inset-top)); padding-bottom: max(24px,env(safe-area-inset-bottom)); } + .dialog-content.task-detail-sheet { padding: 0; } + .task-detail-properties { padding-bottom: max(24px,env(safe-area-inset-bottom)); } + .board-toolbar { margin: 0 calc(-1 * var(--page-gutter)) var(--space-3); padding: var(--space-2) var(--page-gutter); } + .board-toolbar .current-place select,.rich-toolbar select { min-height: 44px; } + .auth-layout { padding: var(--space-4); } +} +/* Brand, household context and menu icons share the expanded sidebar's inset. */ +.workspace-nav .brand { padding-inline: var(--space-3); } +.workspace-nav .nav-household { padding-inline: var(--space-3); } +.workspace-nav nav button { padding-inline: var(--space-3); } +.nav-collapsed .workspace-nav .brand,.nav-collapsed .workspace-nav nav button { padding-inline: 0; } + +/* Visible, labeled groups make planning controls discoverable without disclosures. */ +.icon-label,.property-section>h3 { display: flex; align-items: center; gap: var(--space-2); } +.icon-label>svg,.property-section>h3>svg { flex-shrink: 0; } +.property-section { border-top: 1px solid var(--line); padding-top: var(--space-4); margin-top: var(--space-6); min-width: 0; } +.property-section>h3 { margin: 0 0 var(--space-3); font-size: .9rem; font-weight: 650; line-height: 1.4; } +.property-section h4 { margin: var(--space-4) 0 var(--space-2); font-size: .85rem; } +.property-section>.small { margin-block: var(--space-2); } +.size-selector { margin: 0 0 var(--space-3); } +.size-selector>legend { font-size: .85rem; margin-bottom: var(--space-2); } +.size-options { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: var(--space-1); } +.size-options button { padding-inline: var(--space-1); } +.size-options button[aria-pressed=true],.priority-toggle[aria-pressed=true] { background: var(--tint); border-color: var(--accent); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); } +.priority-toggle { width: 100%; justify-content: flex-start; margin-bottom: var(--space-2); } +.date-row { display: grid; grid-template-columns: minmax(0,1.35fr) minmax(0,1fr); align-items: end; gap: var(--space-2); } +.date-row input { min-width: 0; width: 100%; padding-inline: var(--space-2); } +.date-row label { min-width: 0; font-size: .75rem; } +.date-hint { font-size: .75rem; line-height: 1.5; } +.task-detail-layout { grid-template-columns: minmax(0,1fr) 320px; } +.task-detail-properties .date-row label { margin-bottom: var(--space-3); } +button.danger { color: #b42332; border-color: #b4233260; } +[data-theme=dark] button.danger { color: #ff9da6; border-color: #ff9da660; } +button.danger:hover { background: light-dark(#fff0f1,#4a252b); } +.task-actions { border-top: 1px solid var(--line); padding-top: var(--space-4); margin-top: var(--space-6); } +.task-actions>.button-row { display: grid; } +.task-actions>.button-row>button { justify-content: flex-start; } +.code-entry>h3 { margin-top: 0; font-size: 1rem; } +.upload-button { flex-direction: row; gap: var(--space-2); margin-bottom: 0; } +.check-label input { padding: 0; margin: 0; flex-shrink: 0; } +@media(max-width:720px) { + .task-detail-layout { grid-template-columns: 1fr; } + .date-row { grid-template-columns: minmax(0,1.35fr) minmax(0,1fr); } +} + +.assignee-field { margin-block: var(--space-4); } +.assignee-avatars { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); } +.member-avatar { width: 40px; height: 40px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--tint); color: var(--ink); font-size: .85rem; font-weight: 650; overflow: hidden; } +.member-avatar img { width: 100%; height: 100%; object-fit: cover; } +.assignee-avatars .avatar-trigger { width: 44px; height: 44px; padding: 1px; border-radius: 50%; } +.assignee-avatars .assignee-add { width: 44px; height: 44px; padding: 0; border-radius: 50%; border-style: dashed; } +.assignee-popover { z-index: 50; width: min(360px,calc(100vw - 32px)); max-height: min(520px,var(--radix-popover-content-available-height)); overflow-y: auto; padding: var(--space-4); background: var(--surface); color: var(--ink); border: 1px solid var(--control-line); border-radius: 16px; box-shadow: 0 12px 40px #0003; } +.assignee-picker-heading { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); } +.assignee-picker-heading h3 { margin: 0; font-size: 1rem; } +.assignee-picker-group { margin-top: var(--space-4); } +.assignee-picker-group h4 { margin: 0 0 var(--space-2); font-size: .8rem; color: var(--muted); } +.assignee-choice { width: 100%; justify-content: flex-start; text-align: left; padding: var(--space-2); gap: var(--space-3); } +.assignee-choice>span:nth-child(2) { flex: 1; min-width: 0; overflow-wrap: anywhere; } +.assignee-choice>svg { flex-shrink: 0; } + +/* Property tiles separate groups without adding headings to self-evident controls. */ +.task-property-tile { + min-width: 0; margin: 0 0 var(--space-3); padding: var(--space-3); + border: 1px solid var(--line); border-radius: 12px; background: var(--surface); +} +.task-property-tile .form-grid { gap: var(--space-2); } +.task-property-tile .form-grid label { margin: 0; } +.task-basics .size-selector { margin: var(--space-3) 0; } +.task-basics .priority-toggle { margin-bottom: 0; } +.task-property-tile .choice-list { margin: 0; } +.task-property-tile .task-compact-choices { display: flex; flex-wrap: wrap; gap: 0 var(--space-3); } +.task-property-tile .task-compact-choices .check-label { + min-height: 32px; max-width: 100%; margin: 0; gap: var(--space-2); + overflow-wrap: anywhere; cursor: pointer; +} +.task-property-tile .task-inherited-choices { display: grid; gap: var(--space-2); } +.task-property-tile .task-inherited-choices label { min-width: 0; margin: 0; overflow-wrap: anywhere; } +.task-property-tile .task-inherited-choices select { max-width: 100%; } +.task-property-tile .date-hint { margin-bottom: 0; } +@media (pointer: coarse), (max-width: 720px) { + .task-property-tile .task-compact-choices .check-label { min-height: 44px; } +} + +.entity-chips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); } +.entity-chip, .entity-chip-add { min-height: 32px; padding: 4px 8px; border-radius: 8px; gap: 6px; } +.entity-chip { max-width: 100%; background: oklch(var(--epic-lightness) var(--epic-chroma) var(--epic-hue)); color: oklch(var(--epic-ink) .02 var(--epic-hue)); border-color: transparent; text-align: left; } +.entity-chip span { min-width: 0; overflow-wrap: anywhere; } +.entity-chip svg { flex-shrink: 0; } +.entity-chip-add { width: 32px; padding: 0; border-style: dashed; } +.entity-picker-options { display: grid; gap: var(--space-2); margin-top: var(--space-3); } +.entity-picker-option { min-width: 0; } +.entity-picker-toggle { width: 100%; justify-content: flex-start; text-align: left; gap: var(--space-2); padding: var(--space-2); } +.entity-picker-toggle span { flex: 1; min-width: 0; overflow-wrap: anywhere; } +.entity-picker-toggle svg { flex-shrink: 0; } +.entity-picker-toggle[aria-pressed="true"] { background: var(--tint); } +.entity-picker-option select { width: 100%; margin-top: 4px; } +@media (pointer: coarse), (max-width: 720px) { + .entity-chip, .entity-chip-add { min-height: 44px; } + .entity-chip-add { width: 44px; } +} diff --git a/apps/web/src/lifecycle/LifecycleLibrary.tsx b/apps/web/src/lifecycle/LifecycleLibrary.tsx new file mode 100644 index 0000000..4f8d207 --- /dev/null +++ b/apps/web/src/lifecycle/LifecycleLibrary.tsx @@ -0,0 +1,22 @@ +import { Archive, Trash2, RotateCcw, Settings2 } from 'lucide-react'; +import { useState } from 'react'; +import { useQuery, useQueryClient } from '@tanstack/react-query'; +import { useTranslation } from 'react-i18next'; +import { api, result } from '../accounts/api.js'; +export function LifecycleLibrary({ householdId, admin, onOpen }: { householdId: string; admin: boolean; onOpen: (id: string) => void }) { + const { t } = useTranslation(), queries = useQueryClient(), [kind, setKind] = useState<'archive' | 'trash'>('archive'), [error, setError] = useState(''); + const list = useQuery({ queryKey: ['planning', householdId, 'lifecycle', kind], queryFn: () => result(api.GET('/api/v1/households/{householdId}/lifecycle', { params: { path: { householdId }, query: { kind } } })) }); + const settings = useQuery({ queryKey: ['planning', householdId, 'lifecycle-settings'], queryFn: () => result(api.GET('/api/v1/households/{householdId}/lifecycle-settings', { params: { path: { householdId } } })) }); + async function change(id: string, version: number, action: 'restore' | 'unarchive' | 'delete', confirmed = false) { + if (action === 'delete' && !confirmed && !window.confirm(t('permanentDeleteConfirm'))) return; + try { await result(api.POST('/api/v1/households/{householdId}/tasks/{id}/lifecycle', { params: { path: { householdId, id } }, body: { baseVersion: version, action, confirmed } })); await queries.invalidateQueries({ queryKey: ['planning', householdId] }); } + catch (e) { if ((e as Error).message === 'confirm_dependent_deletion' && window.confirm(t('confirm_dependent_deletion'))) await change(id, version, action, true); else setError((e as Error).message); } + } + return

{(['archive', 'trash'] as const).map(k => )}
{error &&

{t(error)}

}{list.isError && }
{list.data?.map(task =>
{task.title}{new Date((kind === 'archive' ? task.archivedAt : task.trashedAt)!).toLocaleDateString()}
{kind === 'archive' && }{admin && kind === 'trash' && }
)}
+ {admin && settings.data && { await result(api.PUT('/api/v1/households/{householdId}/lifecycle-settings', { params: { path: { householdId } }, body: value })); await settings.refetch(); }} />} +
; +} +function HousekeepingSettings({ initial, save }: { initial: { version: number; archiveDays: number | null; trashDays: number }; save: (value: typeof initial) => Promise }) { + const { t } = useTranslation(), [value, setValue] = useState(initial), [error, setError] = useState(''), [busy, setBusy] = useState(false); + return { e.preventDefault(); setBusy(true); void save(value).catch(e => setError((e as Error).message)).finally(() => setBusy(false)); }}>

{t('archiveDisableHint')}

{error &&

{t(error)}

}
; +} diff --git a/apps/web/src/lifecycle/TaskActions.tsx b/apps/web/src/lifecycle/TaskActions.tsx new file mode 100644 index 0000000..bb5c763 --- /dev/null +++ b/apps/web/src/lifecycle/TaskActions.tsx @@ -0,0 +1,26 @@ +import { Archive, CopyPlus, Trash2 } from 'lucide-react'; +import { useState } from 'react'; +import { useQueryClient } from '@tanstack/react-query'; +import { useTranslation } from 'react-i18next'; +import type { Task, Recurrence } from '@tendly/shared'; +import { api, result } from '../accounts/api.js'; +import { Dialog } from '../components/ui/dialog.js'; +import { RecurrenceFields } from './TemplateLibrary.js'; +export function TaskActions({ task, householdId, timezone, flush, onClose, onSeries, onLifecycle }: { task: Task; householdId: string; timezone: string; flush: () => Promise; onClose: () => void; onSeries: (id: string) => void; onLifecycle: (undo: { id: string; version: number; action: 'restore' | 'unarchive' }) => void }) { + const { t } = useTranslation(), queries = useQueryClient(); + const [capture, setCapture] = useState(false), [name, setName] = useState(task.title), [recurrence, setRecurrence] = useState(null), [error, setError] = useState(''), [busy, setBusy] = useState(false), [notice, setNotice] = useState(''); + async function lifecycle(action: 'archive' | 'trash', confirmed = false) { + const current = await flush(); + if (!current) return; + if (!confirmed && !window.confirm(t(action === 'trash' ? 'trashSubtreeConfirm' : 'archiveConfirm'))) return; + setBusy(true); setError(''); + try { + + await result(api.POST('/api/v1/households/{householdId}/tasks/{id}/lifecycle', { params: { path: { householdId, id: task.id } }, body: { baseVersion: current.version, action, confirmed } })); + await queries.invalidateQueries({ queryKey: ['planning', householdId] }); onLifecycle({ id: task.id, version: current.version + 1, action: action === 'trash' ? 'restore' : 'unarchive' }); onClose(); + } catch (e) { if ((e as Error).message === 'confirm_dependent_deletion' && window.confirm(t('confirm_dependent_deletion'))) await lifecycle(action, true); else setError((e as Error).message); } finally { setBusy(false); } + } + return
{task.recurrenceTemplateId &&

{t('editingOccurrence')}

}
{error &&

{t(error)}

}{notice &&

{t(notice)}

} + {capture && { if (!open && !busy) setCapture(false); }}>
{ e.preventDefault(); setBusy(true); void result(api.POST('/api/v1/households/{householdId}/templates', { params: { path: { householdId } }, body: { taskId: task.id, name, recurrence } })).then(async () => { await queries.invalidateQueries({ queryKey: ['planning', householdId] }); setCapture(false); setNotice('templateSaved'); }).catch(e => setError((e as Error).message)).finally(() => setBusy(false)); }}>

{t('templateCaptureHint')}

{error &&

{t(error)}

}
} +
; +} diff --git a/apps/web/src/lifecycle/TemplateLibrary.tsx b/apps/web/src/lifecycle/TemplateLibrary.tsx new file mode 100644 index 0000000..e2b9e55 --- /dev/null +++ b/apps/web/src/lifecycle/TemplateLibrary.tsx @@ -0,0 +1,47 @@ +import { Repeat2, Trash2, CopyPlus } from 'lucide-react'; +import { useEffect, useRef, useState } from 'react'; +import { useQuery, useQueryClient } from '@tanstack/react-query'; +import { useTranslation } from 'react-i18next'; +import { type Template, type Entity, type Recurrence, type Task } from '@tendly/shared'; +import { api, result } from '../accounts/api.js'; +import { Dialog } from '../components/ui/dialog.js'; +import { TaskFields, emptyTask, type Member } from '../tasks/TaskFields.js'; +function householdToday(timezone: string) { return new Intl.DateTimeFormat('en-CA', { timeZone: timezone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date()); } +export function RecurrenceFields({ value, onChange, timezone }: { timezone: string; value: Recurrence | null; onChange: (value: Recurrence | null) => void }) { + const { t } = useTranslation(); + return
{value && <>
}
; +} +export function TemplateLibrary({ householdId, entities, members, timezone, onOpen, initialId }: { householdId: string; entities: Entity[]; members: Member[]; timezone: string; onOpen: (task: Task) => void; initialId: string | null }) { + const { t } = useTranslation(), queries = useQueryClient(); + const list = useQuery({ queryKey: ['planning', householdId, 'templates'], queryFn: () => result(api.GET('/api/v1/households/{householdId}/templates', { params: { path: { householdId } } })) }); + const [editing, setEditing] = useState