@fayz-ai/db 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ -- 020_fayz_projects.sql — tenant ↔ fayz project association
2
+ -- ----------------------------------------------------------------------------
3
+ -- Almost every tenant owns one or more "fayz projects": deployed sites/apps on
4
+ -- the fayz platform, each addressed by a platform projectId. A tenant's client
5
+ -- site (exposed on the web by fayz) is one such project; an e-commerce client's
6
+ -- site is a project with the storefront module active — i.e. a sales channel.
7
+ --
8
+ -- This table lives in the CLIENT pool (e.g. cluster-ecommerce) and gives the
9
+ -- admin SDK apps a mature link: admin app ↔ tenant ↔ fayz project. It drives the
10
+ -- "Seu site" widget in the sidebar (open preview / open editor), the Loja Online
11
+ -- sales channel (= the storefront project), and Marketing landing-page links.
12
+ --
13
+ -- No platform integration yet: rows are maintained by the admin (manual CRUD),
14
+ -- and the preview/editor URLs are stored explicitly (there is no URL convention
15
+ -- in code and the platform domains are still undecided). A future platform sync
16
+ -- can populate fayz_project_id + URLs automatically.
17
+ --
18
+ -- Additive + idempotent (CREATE TABLE IF NOT EXISTS).
19
+
20
+ CREATE TABLE IF NOT EXISTS public.fayz_projects (
21
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
22
+ tenant_id uuid NOT NULL,
23
+ -- The fayz platform project id (addresses /public/projects/{id}/…). Text
24
+ -- because the platform issues its own ids; nullable until provisioned.
25
+ fayz_project_id text,
26
+ -- App manifest id of the deployed app (e.g. 'artorious-shop'), when known.
27
+ app_id text,
28
+ name text NOT NULL,
29
+ -- site | storefront | landing_page | other
30
+ kind text NOT NULL DEFAULT 'site',
31
+ -- The tenant's default site (the one the "Seu site" widget shows). Partial
32
+ -- unique index below keeps at most one default per tenant.
33
+ is_default boolean NOT NULL DEFAULT false,
34
+ -- Whether the storefront module is active on this site. A storefront-enabled
35
+ -- site is an e-commerce sales channel (the Loja Online channel).
36
+ storefront_enabled boolean NOT NULL DEFAULT false,
37
+ -- Explicit public URLs. preview_url = the live/preview site; editor_url = the
38
+ -- fayz editor (/fayz/editor). Stored, not derived (no convention in code yet).
39
+ preview_url text,
40
+ editor_url text,
41
+ slug text,
42
+ metadata jsonb NOT NULL DEFAULT '{}',
43
+ created_at timestamptz NOT NULL DEFAULT now(),
44
+ updated_at timestamptz NOT NULL DEFAULT now()
45
+ );
46
+
47
+ CREATE INDEX IF NOT EXISTS fayz_projects_tenant_idx ON public.fayz_projects (tenant_id);
48
+ -- At most one default project per tenant.
49
+ CREATE UNIQUE INDEX IF NOT EXISTS fayz_projects_one_default_per_tenant
50
+ ON public.fayz_projects (tenant_id) WHERE is_default;
51
+
52
+ DROP TRIGGER IF EXISTS fayz_projects_updated_at ON public.fayz_projects;
53
+ CREATE TRIGGER fayz_projects_updated_at BEFORE UPDATE ON public.fayz_projects
54
+ FOR EACH ROW EXECUTE FUNCTION public.handle_updated_at();
55
+
56
+ ALTER TABLE public.fayz_projects ENABLE ROW LEVEL SECURITY;
57
+
58
+ DROP POLICY IF EXISTS "fayz_projects_member_all" ON public.fayz_projects;
59
+ CREATE POLICY "fayz_projects_member_all" ON public.fayz_projects FOR ALL TO authenticated
60
+ USING (tenant_id IN (SELECT public.user_tenant_ids()))
61
+ WITH CHECK (tenant_id IN (SELECT public.user_tenant_ids()));
62
+
63
+ GRANT SELECT, INSERT, UPDATE, DELETE ON public.fayz_projects TO authenticated, service_role;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "fayz": {
4
4
  "status": "beta"
5
5
  },
6
- "version": "0.8.3",
6
+ "version": "0.8.4",
7
7
  "description": "Fayz SDK database layer — Drizzle schema primitives, spine references, and migration helpers shared across plugins.",
8
8
  "type": "module",
9
9
  "main": "./dist/index.cjs",