b59904fdae
Data model - Properties, rooms (+optional floors), assets (typed custom fields + Zod runtime validator + move history), documents (polymorphic scope) - Projects -> work packages -> tasks -> subtasks - Decision events (scoped to project/property/asset/work_package) - Checklist templates + instances, maintenance schedules (time + usage) with auto-materialized checklists on event recording - Wiki (global + per-project) with revisions + tsvector FTS - Property accounts (utility/meter numbers by kind) - Notifications table + per-user channel prefs Infra - RBAC guards (requireCompany / requireAdmin) - Storage abstraction: LocalDiskStorage (HMAC signed URLs) + S3Storage behind the same interface, switchable via STORAGE_BACKEND - CSV export for assets / maintenance / decisions - QR labels: /api/qr SVG endpoint + printable /assets/[id]/label - Notifications: in-app + SMTP (own server via nodemailer) + Matrix (Client-Server API, per-company room) with opt-in per user - Company switcher + auto-select first company on login UI - Topbar: bell with unread count, theme toggle, name, Sign Out (flat) - Sidebar: main nav + dedicated Admin section (Asset types, Users, Company) - Nested-route tabs on property / project / asset detail pages - Admin UIs for users (invite, role, reset pw, deactivate) and company settings (default currency, Matrix room id) - Custom asset type creation + field-def editor with immutable key/type guard and auto-deprecate when removing a field still referenced Graph - graphify-out/ committed: GRAPH_REPORT.md, graph.html, graph.json
33 lines
2.4 KiB
SQL
33 lines
2.4 KiB
SQL
CREATE TABLE "property_floors" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
"property_id" uuid NOT NULL,
|
|
"label" varchar(32) NOT NULL,
|
|
"name" varchar(255),
|
|
"order" integer DEFAULT 0 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 "property_rooms" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
"property_id" uuid NOT NULL,
|
|
"floor_id" uuid,
|
|
"name" varchar(255) NOT NULL,
|
|
"notes" text,
|
|
"order" integer DEFAULT 0 NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"deleted_at" timestamp with time zone
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "assets" ADD COLUMN "current_room_id" uuid;--> statement-breakpoint
|
|
ALTER TABLE "property_floors" ADD CONSTRAINT "property_floors_property_id_properties_id_fk" FOREIGN KEY ("property_id") REFERENCES "public"."properties"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "property_rooms" ADD CONSTRAINT "property_rooms_property_id_properties_id_fk" FOREIGN KEY ("property_id") REFERENCES "public"."properties"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "property_rooms" ADD CONSTRAINT "property_rooms_floor_id_property_floors_id_fk" FOREIGN KEY ("floor_id") REFERENCES "public"."property_floors"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
CREATE INDEX "floors_by_property" ON "property_floors" USING btree ("property_id","order");--> statement-breakpoint
|
|
CREATE UNIQUE INDEX "floors_property_label_uq" ON "property_floors" USING btree ("property_id","label");--> statement-breakpoint
|
|
CREATE INDEX "rooms_by_property" ON "property_rooms" USING btree ("property_id","order");--> statement-breakpoint
|
|
CREATE INDEX "rooms_by_floor" ON "property_rooms" USING btree ("floor_id");--> statement-breakpoint
|
|
CREATE UNIQUE INDEX "rooms_floor_name_uq" ON "property_rooms" USING btree ("property_id","floor_id","name");--> statement-breakpoint
|
|
ALTER TABLE "assets" ADD CONSTRAINT "assets_current_room_id_property_rooms_id_fk" FOREIGN KEY ("current_room_id") REFERENCES "public"."property_rooms"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
CREATE INDEX "assets_by_room" ON "assets" USING btree ("current_room_id"); |