/**
 * Cell PG schema.
 *
 * The universal content primitive: a single `cell` table whose `data` JSONB
 * is interpreted by view shape. Parent→child membership and named
 * relationships live in two sibling tables — `cell_item` (ordered
 * children, fractional-indexing keyed) and `cell_field` (named edges).
 * `refs text[]` carries `blake3:` fact hashes auto-extracted from `data`
 * by application code on every write.
 *
 * Soft delete via `deleted_at`. Most indexes are partial on
 * `deleted_at IS NULL` so active-cell queries skip tombstones.
 *
 * `path` is the global namespace axis — a partial unique index enforces
 * uniqueness across all active rows (PostgreSQL UNIQUE constraints don't
 * support WHERE clauses, so it's expressed as a partial unique index). It
 * additionally filters on `deleted_at IS NULL` so a soft-deleted cell
 * doesn't block reuse of its path. Path writes are admin-only at the
 * action layer; user-namespaced paths are a future extension.
 *
 * **Ownership columns** (`created_by`, `updated_by`) are nullable FKs to
 * `actor`: NULL = system origin (well-known cells, daemon/agent cells).
 * The non-admin authz path treats NULL `created_by` as admin-only via an
 * explicit equality check (`auth/cell_authorize.ts`).
 *
 * **Timestamp naming** (`created_at`, `updated_at`) aligns with fuz_app's
 * `_at`-everywhere convention used by `account`, `actor`, `audit_log`,
 * `role_grant`, etc.
 *
 * **Single-migration shape**: `cell_v0` creates the canonical
 * cell + cell_grant + cell_field + cell_item layout in one shot from the
 * live exported constants.
 *
 * @module
 */
import type { Migration, MigrationNamespace } from './migrate.js';
/**
 * `cell_visibility` enum — access-control axis for a cell. Lives as a
 * top-level column (not inside `data`) because visibility is access
 * control, not content metadata. `cell_grant` is the other ACL surface;
 * keeping visibility as a peer column (not a JSON field) co-locates
 * access-control state and lets the planner reason about it directly.
 *
 * Ships with two states (`'private'`, `'public'`); a third (unlisted /
 * public-link) folds in via `ALTER TYPE` when public-link sharing lands.
 *
 * Wrapped in a `DO` block so the migration can replay idempotently —
 * `CREATE TYPE` has no `IF NOT EXISTS` variant in PostgreSQL.
 */
export declare const CELL_VISIBILITY_TYPE = "\nDO $$ BEGIN\n\tCREATE TYPE cell_visibility AS ENUM ('private', 'public');\nEXCEPTION WHEN duplicate_object THEN NULL;\nEND $$";
/**
 * `cell` table — universal content primitive: identity + content only.
 * Parent→child membership lives in `cell_item`; named relations live in
 * `cell_field`. Includes the `created_by` / `updated_by` ownership columns.
 *
 * `visibility` is the access-control axis — `private` (default) is
 * restricted to admin / owner / `cell_grant`-admitted callers; `public`
 * admits everyone, including unauthenticated visitors. Lives as a
 * top-level column so the auth predicate reads off the row directly
 * rather than reaching into `data`.
 *
 * `path` is the global namespace axis (no tenant/hub scoping) — globally
 * unique on active rows via `idx_cell_path_unique`.
 */
export declare const CELL_SCHEMA = "\nCREATE TABLE IF NOT EXISTS cell (\n\tid UUID PRIMARY KEY DEFAULT gen_random_uuid(),\n\tdata JSONB NOT NULL,\n\tvisibility cell_visibility NOT NULL DEFAULT 'private',\n\tpath TEXT,\n\trefs TEXT[],\n\tcreated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n\tupdated_at TIMESTAMPTZ,\n\tdeleted_at TIMESTAMPTZ,\n\tcreated_by UUID REFERENCES actor(id) ON DELETE SET NULL,\n\tupdated_by UUID REFERENCES actor(id) ON DELETE SET NULL\n)";
/**
 * Cell indexes — all active-only, partial on `deleted_at IS NULL`.
 *
 * - `idx_cell_active`: active-cell list/scan ordered by creation.
 * - `idx_cell_path_unique`: global `path` uniqueness + read-side path
 *   lookup. Partial on path + active so reused paths after soft delete are
 *   allowed.
 * - `idx_cell_data`: shape-driven queries (`data ? 'kind'`, `data @> ...`).
 * - `idx_cell_refs`: cells-by-fact discovery (cross-cell reference graph).
 * - `idx_cell_created_by`: "cells this actor created" queries.
 *
 * Parent↔child membership and named relations live in sibling tables;
 * see `CELL_ITEM_INDEXES` / `CELL_FIELD_INDEXES` below.
 */
export declare const CELL_INDEXES: Array<string>;
/**
 * `cell_grant` table — resource-side ACL for cells. Each row admits a
 * principal (actor or `(role, scope_id)`) at a `level` (`viewer` or
 * `editor`). Owner is implicit (`cell.created_by`); the table never carries
 * owner rows.
 *
 * The single-principal arm is actor-grain (`actor_id` FK); the other arm is
 * role-shaped (`(role, scope_id)`). The CHECK enforces exactly one arm.
 */
export declare const CELL_GRANT_SCHEMA = "\nCREATE TABLE IF NOT EXISTS cell_grant (\n\tid UUID PRIMARY KEY DEFAULT gen_random_uuid(),\n\tcell_id UUID NOT NULL REFERENCES cell(id) ON DELETE CASCADE,\n\tlevel TEXT NOT NULL CHECK (level IN ('viewer', 'editor')),\n\tactor_id UUID REFERENCES actor(id) ON DELETE CASCADE,\n\trole TEXT,\n\tscope_id UUID,\n\tgranted_by UUID REFERENCES actor(id) ON DELETE SET NULL,\n\tcreated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n\tCHECK (\n\t\t(actor_id IS NOT NULL AND role IS NULL AND scope_id IS NULL) OR\n\t\t(actor_id IS NULL AND role IS NOT NULL)\n\t)\n)";
/**
 * `cell_grant` indexes.
 *
 * - `idx_cell_grant_cell`: forward lookup ("who has access to this cell?").
 * - `idx_cell_grant_actor`: reverse lookup ("which cells does this actor have access to?").
 * - `idx_cell_grant_role_scope`: reverse lookup for role-shaped principals.
 * - `idx_cell_grant_unique_actor`: prevents duplicate actor-shaped grants for the same cell.
 *   Re-granting updates `level` via UPSERT on this index.
 * - `idx_cell_grant_unique_role_scope`: same, for role-shaped grants.
 *   `NULLS NOT DISTINCT` so two rows with the same `(cell_id, role)` and
 *   `scope_id IS NULL` collide — without it, default NULL-distinct
 *   semantics would let duplicate null-scope role grants slip past the
 *   re-share UPSERT path. Requires PostgreSQL 15+ (pglite tracks PG 16).
 */
export declare const CELL_GRANT_INDEXES: Array<string>;
/**
 * `cell_field` table — named relation (`(source_id, name) → target_id`).
 * One target per name per source — JSON-object keys are unique. Multiplicity
 * is expressed by composition (`foo.tags = collection_cell` whose `items[]`
 * are the tags), not by allowing duplicate `(source_id, name)` rows.
 */
export declare const CELL_FIELD_SCHEMA = "\nCREATE TABLE IF NOT EXISTS cell_field (\n\tsource_id UUID NOT NULL REFERENCES cell(id) ON DELETE CASCADE,\n\tname TEXT NOT NULL,\n\ttarget_id UUID NOT NULL REFERENCES cell(id) ON DELETE CASCADE,\n\tcreated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n\tPRIMARY KEY (source_id, name)\n)";
/**
 * `cell_field` indexes.
 *
 * - PK on `(source_id, name)` covers forward lookup ("what does this cell
 *   point to via field X?") and the per-source fields list.
 * - `idx_cell_field_target` covers reverse lookup ("which cells link to
 *   this target?").
 *
 * Soft-delete is filtered by JOIN at the read boundary; no partial indexes
 * here on `deleted_at` (would force index churn on cell soft-delete
 * toggles, and the join filter is sufficient).
 */
export declare const CELL_FIELD_INDEXES: Array<string>;
/**
 * `cell_item` table — ordered child membership keyed by an opaque
 * fractional-indexing string. `(parent_id, position)` PK enforces one cell
 * per slot; the same `child_id` may appear at multiple positions (the
 * primitive is JSON-array-shaped — ordered multiset, not set). Domain
 * dedup rules ride on top in helpers.
 */
export declare const CELL_ITEM_SCHEMA = "\nCREATE TABLE IF NOT EXISTS cell_item (\n\tparent_id UUID NOT NULL REFERENCES cell(id) ON DELETE CASCADE,\n\tposition TEXT NOT NULL,\n\tchild_id UUID NOT NULL REFERENCES cell(id) ON DELETE CASCADE,\n\tcreated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n\tPRIMARY KEY (parent_id, position)\n)";
/**
 * `cell_item` indexes.
 *
 * - PK on `(parent_id, position)` covers ordered scans for the per-parent
 *   items list (`SELECT ... ORDER BY position`).
 * - `idx_cell_item_child` covers reverse lookup ("which parents contain
 *   this child?").
 */
export declare const CELL_ITEM_INDEXES: Array<string>;
/** Tables created by `CELL_MIGRATION_NS`, in drop order (children first). */
export declare const CELL_DROP_TABLES: readonly ["cell_field", "cell_item", "cell_grant", "cell"];
/** Cell migrations. */
export declare const CELL_MIGRATIONS: Array<Migration>;
/** Namespace identifier for cell migrations. */
export declare const CELL_MIGRATION_NAMESPACE = "fuz_cell";
/** Migration namespace consumed by `run_migrations`. */
export declare const CELL_MIGRATION_NS: MigrationNamespace;
//# sourceMappingURL=cell_ddl.d.ts.map