/* <begin connected objects> */
/*
This file is auto generated by pgrx.

The ordering of items is not stable, it is driven by a dependency graph.
*/
/* </end connected objects> */

/* <begin connected objects> */
-- src/lib.rs:909
CREATE SCHEMA IF NOT EXISTS graph; /* graph::graph */
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/discovery.rs:84
-- graph::sql_facade::discovery::preview_discover
CREATE  FUNCTION graph."preview_discover"(
	"schema_name" TEXT DEFAULT 'public', /* & str */
	"graph_name" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"item_type" TEXT,  /* String */
	"item_name" TEXT,  /* String */
	"details" TEXT  /* String */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'preview_discover_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2659
-- graph::sql_facade::admin::build_status
CREATE  FUNCTION graph."build_status"(
	"build_id" TEXT /* & str */
) RETURNS TABLE (
	"build_id" TEXT,  /* String */
	"status" TEXT,  /* String */
	"nodes_loaded" bigint,  /* Option < i64 > */
	"edges_loaded" bigint,  /* Option < i64 > */
	"build_time_ms" double precision,  /* Option < f64 > */
	"memory_used_mb" double precision,  /* Option < f64 > */
	"progress_phase" TEXT,  /* String */
	"progress_message" TEXT,  /* Option < String > */
	"started_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"finished_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"error" TEXT  /* Option < String > */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'build_status_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3456
-- graph::sql_facade::admin::add_filter_column_to_graph
CREATE  FUNCTION graph."add_filter_column_to_graph"(
	"graph_name" TEXT, /* & str */
	"table_name" oid, /* pgrx :: pg_sys :: Oid */
	"column_name" TEXT, /* & str */
	"column_type" TEXT DEFAULT 'numeric', /* & str */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS void

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'add_filter_column_to_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/gql.rs:10
-- graph::sql_facade::gql::gql_explain
CREATE  FUNCTION graph."gql_explain"(
	"query" TEXT /* & str */
) RETURNS TEXT /* String */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'gql_explain_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3623
-- graph::sql_facade::admin::gt
CREATE  FUNCTION graph."gt"(
	"column_name" TEXT, /* & str */
	"value" bigint /* i64 */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'gt_i64_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:121
-- graph::sql_facade::admin::_max_sync_log_id_for_query_state
CREATE  FUNCTION graph."_max_sync_log_id_for_query_state"() RETURNS bigint /* i64 */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'max_sync_log_id_for_query_state_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3652
-- graph::sql_facade::admin::lt
CREATE  FUNCTION graph."lt"(
	"column_name" TEXT, /* & str */
	"value" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'lt_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:6223
-- graph::sql_facade::admin::maintenance_graph
CREATE  FUNCTION graph."maintenance_graph"(
	"graph_name" TEXT, /* & str */
	"concurrently" bool DEFAULT false, /* bool */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"job_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"status" TEXT,  /* String */
	"sync_rows_applied" bigint,  /* Option < i64 > */
	"nodes_after" bigint,  /* Option < i64 > */
	"edges_after" bigint,  /* Option < i64 > */
	"vacuum_time_ms" double precision,  /* Option < f64 > */
	"error" TEXT  /* Option < String > */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'maintenance_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3540
-- graph::sql_facade::admin::neq
CREATE  FUNCTION graph."neq"(
	"column_name" TEXT, /* & str */
	"value" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'neq_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3125
-- graph::sql_facade::admin::registered_tables
CREATE  FUNCTION graph."registered_tables"() RETURNS TABLE (
	"table_name" TEXT,  /* String */
	"id_columns" TEXT[],  /* Vec < String > */
	"columns" TEXT[],  /* Vec < String > */
	"tenant_column" TEXT  /* Option < String > */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'registered_tables_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/traversal.rs:557
-- graph::sql_facade::traversal::shortest_path
CREATE  FUNCTION graph."shortest_path"(
	"source_table" oid, /* pgrx :: pg_sys :: Oid */
	"source_id" TEXT, /* & str */
	"target_table" oid, /* pgrx :: pg_sys :: Oid */
	"target_id" TEXT, /* & str */
	"max_depth" INT, /* i32 */
	"hydrate" bool, /* bool */
	"edge_types" TEXT[] /* Vec < String > */
) RETURNS TABLE (
	"step" INT,  /* i32 */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT,  /* String */
	"edge_label" TEXT,  /* Option < String > */
	"node" jsonb,  /* Option < pgrx :: JsonB > */
	"node_table_name" TEXT  /* String */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'shortest_path_typed_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:1739
-- graph::sql_facade::admin::projection_repair
CREATE  FUNCTION graph."projection_repair"() RETURNS TABLE (
	"action" TEXT,  /* String */
	"generation_id" bigint,  /* Option < i64 > */
	"rebuilt" bool,  /* bool */
	"chunks_rewritten" INT,  /* i32 */
	"reason" TEXT  /* Option < String > */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'projection_repair_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/runtime.rs:37
-- graph::sql_facade::runtime::reset
CREATE  FUNCTION graph."reset"() RETURNS void
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'reset_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:509
-- graph::sql_facade::admin::set_current_graph
CREATE  FUNCTION graph."set_current_graph"(
	"graph_name" TEXT, /* & str */
	"tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"owner_role" oid,  /* pgrx :: pg_sys :: Oid */
	"created_by" oid,  /* pgrx :: pg_sys :: Oid */
	"tenant" TEXT,  /* Option < String > */
	"namespace" TEXT,  /* Option < String > */
	"graph_kind" TEXT,  /* String */
	"residency" TEXT,  /* String */
	"materialization" TEXT,  /* String */
	"projection_mode" TEXT,  /* String */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'set_current_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/discovery.rs:140
-- graph::sql_facade::discovery::create_row_predicate_subgraph
CREATE  FUNCTION graph."create_row_predicate_subgraph"(
	"graph_name" TEXT, /* & str */
	"row_predicate" jsonb, /* pgrx :: JsonB */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS void

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'create_row_predicate_subgraph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:1928
-- graph::sql_facade::admin::memory_profile
CREATE  FUNCTION graph."memory_profile"(
	"concurrent_backends" INT DEFAULT 1 /* i32 */
) RETURNS TABLE (
	"active_backend_private_mb" double precision,  /* f64 */
	"active_backend_shared_mb" double precision,  /* f64 */
	"active_backend_total_mb" double precision,  /* f64 */
	"estimated_instance_private_mb" double precision,  /* f64 */
	"estimated_instance_shared_mb" double precision,  /* f64 */
	"estimated_instance_total_mb" double precision,  /* f64 */
	"memory_limit_mb" INT,  /* i32 */
	"assumed_concurrent_backends" INT  /* i32 */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'memory_profile_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3699
-- graph::sql_facade::admin::node_ref_string
CREATE  FUNCTION graph."node_ref_string"(
	"table_name" oid, /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT /* & str */
) RETURNS TEXT /* String */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'node_ref_string_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:79
-- graph::sql_facade::admin::_pending_sync_rows_for_current_role
CREATE  FUNCTION graph."_pending_sync_rows_for_current_role"() RETURNS bigint /* i64 */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'pending_sync_rows_for_current_role_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:5902
-- graph::sql_facade::admin::alter_job
CREATE  FUNCTION graph."alter_job"(
	"job_id" TEXT, /* & str */
	"enabled" bool DEFAULT NULL, /* Option < bool > */
	"schedule_interval_secs" bigint DEFAULT NULL, /* Option < i64 > */
	"max_runtime_secs" bigint DEFAULT NULL, /* Option < i64 > */
	"max_retries" INT DEFAULT NULL /* Option < i32 > */
) RETURNS TABLE (
	"job_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"policy_kind" TEXT,  /* String */
	"enabled" bool,  /* bool */
	"schedule_interval_secs" bigint,  /* i64 */
	"max_runtime_secs" bigint,  /* Option < i64 > */
	"max_retries" INT,  /* i32 */
	"next_run_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"last_status" TEXT  /* Option < String > */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'alter_job_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/workflow.rs:96
-- graph::sql_facade::workflow::expand
CREATE  FUNCTION graph."expand"(
	"seed_table" oid, /* pgrx :: pg_sys :: Oid */
	"seed_id" TEXT, /* & str */
	"max_depth" INT DEFAULT current_setting('graph.default_max_depth')::int, /* i32 */
	"edge_types" TEXT[] DEFAULT NULL, /* :: std :: option :: Option < Vec < String > > */
	"direction" TEXT DEFAULT 'any', /* & str */
	"target_table" oid DEFAULT NULL, /* Option < pgrx :: pg_sys :: Oid > */
	"target_tables" oid[] DEFAULT NULL, /* :: std :: option :: Option < Vec < pgrx :: pg_sys :: Oid > > */
	"where_node" jsonb DEFAULT NULL, /* Option < pgrx :: JsonB > */
	"tenant" TEXT DEFAULT NULL, /* Option < String > */
	"max_rows" INT DEFAULT 50, /* i32 */
	"row_offset" INT DEFAULT 0, /* i32 */
	"include_start" bool DEFAULT false /* bool */
) RETURNS TABLE (
	"root_table" oid,  /* pgrx :: pg_sys :: Oid */
	"root_id" TEXT,  /* String */
	"root_table_name" TEXT,  /* String */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_table_name" TEXT,  /* String */
	"node_id" TEXT,  /* String */
	"depth" INT,  /* i32 */
	"rank" INT,  /* i32 */
	"path" jsonb,  /* pgrx :: JsonB */
	"edge_path" jsonb,  /* pgrx :: JsonB */
	"readable_path" TEXT,  /* String */
	"node" jsonb,  /* Option < pgrx :: JsonB > */
	"truncated" bool  /* bool */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'expand_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:477
-- graph::sql_facade::admin::current_graph
CREATE  FUNCTION graph."current_graph"() RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"owner_role" oid,  /* pgrx :: pg_sys :: Oid */
	"created_by" oid,  /* pgrx :: pg_sys :: Oid */
	"tenant" TEXT,  /* Option < String > */
	"namespace" TEXT,  /* Option < String > */
	"graph_kind" TEXT,  /* String */
	"residency" TEXT,  /* String */
	"materialization" TEXT,  /* String */
	"projection_mode" TEXT,  /* String */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'current_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:51
-- graph::sql_facade::admin::_graph_id_for_current_role_with_privilege
CREATE  FUNCTION graph."_graph_id_for_current_role_with_privilege"(
	"graph_name" TEXT, /* & str */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL, /* Option < & str > */
	"privilege" TEXT DEFAULT 'read' /* & str */
) RETURNS TEXT /* String */
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'graph_id_for_current_role_with_privilege_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/workflow.rs:673
-- graph::sql_facade::workflow::neighborhood
CREATE  FUNCTION graph."neighborhood"(
	"property_key" TEXT, /* & str */
	"property_value" TEXT, /* & str */
	"source_table" oid DEFAULT NULL, /* Option < pgrx :: pg_sys :: Oid > */
	"search_mode" TEXT DEFAULT 'contains', /* & str */
	"search_max_rows" INT DEFAULT 1, /* i32 */
	"max_depth" INT DEFAULT 4, /* i32 */
	"edge_types" TEXT[] DEFAULT NULL, /* :: std :: option :: Option < Vec < String > > */
	"direction" TEXT DEFAULT 'any', /* & str */
	"tenant" TEXT DEFAULT NULL, /* Option < String > */
	"sample_k" INT DEFAULT 5, /* i32 */
	"node_limit" INT DEFAULT 10000 /* i32 */
) RETURNS TABLE (
	"depth" INT,  /* i32 */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_table_name" TEXT,  /* String */
	"node_count" bigint,  /* i64 */
	"sample_nodes" jsonb,  /* pgrx :: JsonB */
	"truncated" bool  /* bool */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'neighborhood_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3591
-- graph::sql_facade::admin::is_null
CREATE  FUNCTION graph."is_null"(
	"column_name" TEXT /* & str */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'is_null_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:356
-- graph::sql_facade::admin::alter_graph
CREATE  FUNCTION graph."alter_graph"(
	"graph_name" TEXT, /* & str */
	"tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"namespace" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_kind" TEXT DEFAULT NULL, /* Option < & str > */
	"residency" TEXT DEFAULT NULL, /* Option < & str > */
	"materialization" TEXT DEFAULT NULL, /* Option < & str > */
	"projection_mode" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"owner_role" oid,  /* pgrx :: pg_sys :: Oid */
	"created_by" oid,  /* pgrx :: pg_sys :: Oid */
	"tenant" TEXT,  /* Option < String > */
	"namespace" TEXT,  /* Option < String > */
	"graph_kind" TEXT,  /* String */
	"residency" TEXT,  /* String */
	"materialization" TEXT,  /* String */
	"projection_mode" TEXT,  /* String */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'alter_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:1450
-- graph::sql_facade::admin::resource_status
CREATE  FUNCTION graph."resource_status"() RETURNS TABLE (
	"operation" TEXT,  /* String */
	"memory_budget_bytes" bigint,  /* i64 */
	"memory_peak_bytes" bigint,  /* i64 */
	"memory_peak_phase" TEXT,  /* Option < String > */
	"disk_peak_bytes" bigint,  /* i64 */
	"rows" bigint,  /* i64 */
	"work_units" bigint  /* i64 */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'resource_status_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3534
-- graph::sql_facade::admin::not_equals
CREATE  FUNCTION graph."not_equals"(
	"column_name" TEXT, /* & str */
	"value" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'not_equals_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:14
-- graph::sql_facade::admin::_selected_graph_id_for_current_role
CREATE  FUNCTION graph."_selected_graph_id_for_current_role"() RETURNS TEXT /* String */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'selected_graph_id_for_current_role_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/workflow.rs:239
-- graph::sql_facade::workflow::find_related
CREATE  FUNCTION graph."find_related"(
	"property_key" TEXT, /* & str */
	"property_value" TEXT, /* & str */
	"source_table" oid DEFAULT NULL, /* Option < pgrx :: pg_sys :: Oid > */
	"search_mode" TEXT DEFAULT COALESCE(NULLIF(current_setting('graph.default_search_mode'), ''), 'contains'), /* & str */
	"case_sensitive" bool DEFAULT current_setting('graph.default_case_sensitive')::boolean, /* bool */
	"search_max_rows" INT DEFAULT 1, /* i32 */
	"search_row_offset" INT DEFAULT 0, /* i32 */
	"max_depth" INT DEFAULT current_setting('graph.default_max_depth')::int, /* i32 */
	"edge_types" TEXT[] DEFAULT NULL, /* :: std :: option :: Option < Vec < String > > */
	"direction" TEXT DEFAULT 'any', /* & str */
	"target_table" oid DEFAULT NULL, /* Option < pgrx :: pg_sys :: Oid > */
	"target_tables" oid[] DEFAULT NULL, /* :: std :: option :: Option < Vec < pgrx :: pg_sys :: Oid > > */
	"where_node" jsonb DEFAULT NULL, /* Option < pgrx :: JsonB > */
	"tenant" TEXT DEFAULT NULL, /* Option < String > */
	"max_rows" INT DEFAULT 20, /* i32 */
	"row_offset" INT DEFAULT 0, /* i32 */
	"include_counts" bool DEFAULT false, /* bool */
	"candidate_limit" INT DEFAULT 10000, /* i32 */
	"include_start" bool DEFAULT false /* bool */
) RETURNS TABLE (
	"root_table" oid,  /* pgrx :: pg_sys :: Oid */
	"root_id" TEXT,  /* String */
	"root_table_name" TEXT,  /* String */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_table_name" TEXT,  /* String */
	"node_id" TEXT,  /* String */
	"depth" INT,  /* i32 */
	"score" real,  /* f32 */
	"rank" INT,  /* i32 */
	"path" jsonb,  /* pgrx :: JsonB */
	"edge_path" jsonb,  /* pgrx :: JsonB */
	"readable_path" TEXT,  /* String */
	"node" jsonb,  /* Option < pgrx :: JsonB > */
	"candidate_count" bigint,  /* Option < i64 > */
	"filtered_count" bigint,  /* Option < i64 > */
	"truncated" bool  /* bool */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'find_related_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2995
-- graph::sql_facade::admin::add_edge
CREATE  FUNCTION graph."add_edge"(
	"from_table" oid, /* pgrx :: pg_sys :: Oid */
	"from_column" TEXT, /* & str */
	"to_table" oid, /* pgrx :: pg_sys :: Oid */
	"to_column" TEXT, /* & str */
	"label" TEXT, /* & str */
	"bidirectional" bool DEFAULT true, /* bool */
	"weight_column" TEXT DEFAULT NULL, /* Option < String > */
	"label_column" TEXT DEFAULT NULL /* Option < String > */
) RETURNS void
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'add_edge_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:720
-- graph::sql_facade::admin::set_graph_quota
CREATE  FUNCTION graph."set_graph_quota"(
	"scope_type" TEXT, /* & str */
	"dimension" TEXT, /* & str */
	"limit_value" bigint, /* i64 */
	"scope_key" TEXT DEFAULT NULL, /* Option < & str > */
	"enforcement" TEXT DEFAULT 'hard' /* & str */
) RETURNS TABLE (
	"scope_type" TEXT,  /* String */
	"scope_key" TEXT,  /* String */
	"dimension" TEXT,  /* String */
	"limit_value" bigint,  /* i64 */
	"enforcement" TEXT,  /* String */
	"updated_by" oid,  /* pgrx :: pg_sys :: Oid */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'set_graph_quota_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/cypher.rs:58
-- graph::sql_facade::cypher::cypher_compatibility
CREATE  FUNCTION graph."cypher_compatibility"() RETURNS TABLE (
	"feature" TEXT,  /* & '_ str */
	"status" TEXT,  /* & '_ str */
	"notes" TEXT  /* & '_ str */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'cypher_compatibility_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:580
-- graph::sql_facade::admin::revoke_graph
CREATE  FUNCTION graph."revoke_graph"(
	"graph_name" TEXT, /* & str */
	"grantee" TEXT, /* & str */
	"privilege" TEXT, /* & str */
	"tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"grantee" oid,  /* pgrx :: pg_sys :: Oid */
	"privilege" TEXT,  /* String */
	"grantor" oid,  /* pgrx :: pg_sys :: Oid */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'revoke_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3057
-- graph::sql_facade::admin::add_edge_to_graph
CREATE  FUNCTION graph."add_edge_to_graph"(
	"graph_name" TEXT, /* & str */
	"from_table" oid, /* pgrx :: pg_sys :: Oid */
	"from_column" TEXT, /* & str */
	"to_table" oid, /* pgrx :: pg_sys :: Oid */
	"to_column" TEXT, /* & str */
	"label" TEXT, /* & str */
	"bidirectional" bool DEFAULT true, /* bool */
	"weight_column" TEXT DEFAULT NULL, /* Option < String > */
	"label_column" TEXT DEFAULT NULL, /* Option < String > */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS void
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'add_edge_to_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2887
-- graph::sql_facade::admin::add_table
CREATE  FUNCTION graph."add_table"(
	"table_name" oid, /* pgrx :: pg_sys :: Oid */
	"id_column" TEXT, /* & str */
	"columns" TEXT[] DEFAULT NULL, /* :: std :: option :: Option < Vec < String > > */
	"tenant_column" TEXT DEFAULT NULL /* Option < String > */
) RETURNS void
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'add_table_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:5671
-- graph::sql_facade::admin::job_runs
CREATE  FUNCTION graph."job_runs"(
	"job_id" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_name" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL, /* Option < & str > */
	"max_rows" INT DEFAULT 50 /* i32 */
) RETURNS TABLE (
	"run_id" TEXT,  /* String */
	"job_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"status" TEXT,  /* String */
	"rows_applied" bigint,  /* Option < i64 > */
	"retry_count" INT,  /* i32 */
	"execution_mode" TEXT,  /* String */
	"sqlstate" TEXT,  /* Option < String > */
	"error" TEXT,  /* Option < String > */
	"started_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"finished_at" timestamp with time zone  /* Option < TimestampWithTimeZone > */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'job_runs_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:6152
-- graph::sql_facade::admin::maintenance
CREATE  FUNCTION graph."maintenance"(
	"concurrently" bool DEFAULT false /* bool */
) RETURNS TABLE (
	"job_id" TEXT,  /* String */
	"status" TEXT,  /* String */
	"sync_rows_applied" bigint,  /* Option < i64 > */
	"nodes_after" bigint,  /* Option < i64 > */
	"edges_after" bigint,  /* Option < i64 > */
	"vacuum_time_ms" double precision,  /* Option < f64 > */
	"error" TEXT  /* Option < String > */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'maintenance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:109
-- graph::sql_facade::admin::_max_sync_log_id_for_current_role
CREATE  FUNCTION graph."_max_sync_log_id_for_current_role"() RETURNS bigint /* i64 */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'max_sync_log_id_for_current_role_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2528
-- graph::sql_facade::admin::build
CREATE  FUNCTION graph."build"(
	"concurrently" bool /* bool */
) RETURNS TABLE (
	"build_id" TEXT,  /* String */
	"status" TEXT,  /* String */
	"nodes_loaded" bigint,  /* Option < i64 > */
	"edges_loaded" bigint,  /* Option < i64 > */
	"build_time_ms" double precision,  /* Option < f64 > */
	"memory_used_mb" double precision,  /* Option < f64 > */
	"sync_mode" TEXT,  /* String */
	"projection_mode" TEXT  /* String */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'build_with_concurrently_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/traversal.rs:332
-- graph::sql_facade::traversal::traverse
CREATE  FUNCTION graph."traverse"(
	"start_tables" oid[], /* Vec < pgrx :: pg_sys :: Oid > */
	"start_ids" TEXT[], /* Vec < String > */
	"max_depth" INT DEFAULT COALESCE(NULLIF(current_setting('graph.default_max_depth', true), '')::int, 5), /* i32 */
	"edge_types" TEXT[] DEFAULT NULL, /* :: std :: option :: Option < Vec < String > > */
	"direction" TEXT DEFAULT 'any', /* & str */
	"node_tables" oid[] DEFAULT NULL, /* :: std :: option :: Option < Vec < pgrx :: pg_sys :: Oid > > */
	"filter" jsonb DEFAULT NULL, /* Option < pgrx :: JsonB > */
	"tenant" TEXT DEFAULT NULL, /* Option < String > */
	"strategy" TEXT DEFAULT 'bfs', /* & str */
	"uniqueness" TEXT DEFAULT 'node_global', /* & str */
	"include_start" bool DEFAULT true, /* bool */
	"hydrate" bool DEFAULT true, /* bool */
	"max_rows" INT DEFAULT 1000, /* i32 */
	"row_offset" INT DEFAULT 0, /* i32 */
	"max_nodes" INT DEFAULT COALESCE(NULLIF(current_setting('graph.max_nodes', true), '')::int, 100000), /* i32 */
	"max_frontier" INT DEFAULT COALESCE(NULLIF(current_setting('graph.max_frontier', true), '')::int, 100000) /* i32 */
) RETURNS TABLE (
	"root_table" oid,  /* pgrx :: pg_sys :: Oid */
	"root_id" TEXT,  /* String */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT,  /* String */
	"depth" INT,  /* i32 */
	"path" jsonb,  /* pgrx :: JsonB */
	"edge_path" jsonb,  /* pgrx :: JsonB */
	"node" jsonb,  /* Option < pgrx :: JsonB > */
	"root_table_name" TEXT,  /* String */
	"node_table_name" TEXT,  /* String */
	"capped" bool  /* bool */
)
  COST 1000
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'traverse_many_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2798
-- graph::sql_facade::admin::build_status_for_graph
CREATE  FUNCTION graph."build_status_for_graph"(
	"graph_name" TEXT, /* & str */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL, /* Option < & str > */
	"max_rows" INT DEFAULT 50 /* i32 */
) RETURNS TABLE (
	"build_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"status" TEXT,  /* String */
	"nodes_loaded" bigint,  /* Option < i64 > */
	"edges_loaded" bigint,  /* Option < i64 > */
	"build_time_ms" double precision,  /* Option < f64 > */
	"memory_used_mb" double precision,  /* Option < f64 > */
	"sync_mode" TEXT,  /* String */
	"projection_mode" TEXT,  /* String */
	"progress_phase" TEXT,  /* String */
	"progress_message" TEXT,  /* Option < String > */
	"started_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"finished_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"error" TEXT  /* Option < String > */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'build_status_for_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2286
-- graph::sql_facade::admin::build_async_graph
CREATE  FUNCTION graph."build_async_graph"(
	"graph_name" TEXT, /* & str */
	"projection_mode" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"build_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"status" TEXT,  /* String */
	"nodes_loaded" bigint,  /* Option < i64 > */
	"edges_loaded" bigint,  /* Option < i64 > */
	"build_time_ms" double precision,  /* Option < f64 > */
	"memory_used_mb" double precision,  /* Option < f64 > */
	"sync_mode" TEXT,  /* String */
	"projection_mode" TEXT  /* String */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'build_async_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:6430
-- graph::sql_facade::admin::maintenance_status_for_graph
CREATE  FUNCTION graph."maintenance_status_for_graph"(
	"graph_name" TEXT, /* & str */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL, /* Option < & str > */
	"max_rows" INT DEFAULT 50 /* i32 */
) RETURNS TABLE (
	"job_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"status" TEXT,  /* String */
	"sync_rows_applied" bigint,  /* Option < i64 > */
	"nodes_after" bigint,  /* Option < i64 > */
	"edges_after" bigint,  /* Option < i64 > */
	"vacuum_time_ms" double precision,  /* Option < f64 > */
	"progress_phase" TEXT,  /* String */
	"progress_message" TEXT,  /* Option < String > */
	"started_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"finished_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"error" TEXT  /* Option < String > */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'maintenance_status_for_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3707
-- graph::sql_facade::admin::format_path
CREATE  FUNCTION graph."format_path"(
	"path" jsonb, /* pgrx :: JsonB */
	"edge_path" jsonb, /* pgrx :: JsonB */
	"separator" TEXT DEFAULT ' | ' /* & str */
) RETURNS TEXT /* String */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'format_path_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:1307
-- graph::sql_facade::admin::status
CREATE  FUNCTION graph."status"() RETURNS TABLE (
	"node_count" INT,  /* i32 */
	"edge_count" INT,  /* i32 */
	"memory_used_mb" double precision,  /* f64 */
	"memory_limit_mb" INT,  /* i32 */
	"sync_mode" TEXT,  /* String */
	"sync_status" TEXT,  /* String */
	"last_build" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"last_vacuum" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"edge_types" TEXT[],  /* Vec < String > */
	"edge_buffer_used" INT,  /* i32 */
	"has_unidirectional_edges" bool,  /* bool */
	"schema_status" TEXT,  /* String */
	"sync_lag" bigint,  /* i64 */
	"pending_edge_deltas" INT,  /* i32 */
	"needs_vacuum" bool,  /* bool */
	"needs_rebuild" bool,  /* bool */
	"applied_sync_id" bigint,  /* i64 */
	"pending_sync_rows" bigint,  /* i64 */
	"invalid_reason" TEXT,  /* Option < String > */
	"disabled_trigger_count" INT,  /* i32 */
	"read_only" bool,  /* bool */
	"read_only_reason" TEXT,  /* Option < String > */
	"projection_mode" TEXT,  /* String */
	"overlay_tombstone_count" INT,  /* i32 */
	"overlay_memory_bytes" bigint,  /* i64 */
	"compaction_recommended" bool,  /* bool */
	"tx_delta_dirty" bool,  /* bool */
	"tx_delta_added_nodes" INT,  /* i32 */
	"tx_delta_deleted_nodes" INT,  /* i32 */
	"tx_delta_added_edges" INT,  /* i32 */
	"tx_delta_deleted_edges" INT,  /* i32 */
	"tx_delta_memory_bytes" bigint  /* i64 */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'status_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3523
-- graph::sql_facade::admin::eq
CREATE  FUNCTION graph."eq"(
	"column_name" TEXT, /* & str */
	"value" TEXT /* & str */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'eq_text_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:5724
-- graph::sql_facade::admin::job_stats
CREATE  FUNCTION graph."job_stats"(
	"graph_name" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"policy_kind" TEXT,  /* String */
	"job_count" bigint,  /* i64 */
	"run_count" bigint,  /* i64 */
	"completed_runs" bigint,  /* i64 */
	"failed_runs" bigint,  /* i64 */
	"last_run_at" timestamp with time zone  /* Option < TimestampWithTimeZone > */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'job_stats_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/traversal.rs:1479
-- graph::sql_facade::traversal::path_count_estimate
CREATE  FUNCTION graph."path_count_estimate"(
	"traversal" jsonb /* pgrx :: JsonB */
) RETURNS TABLE (
	"estimated_paths" bigint,  /* i64 */
	"exact" bool,  /* bool */
	"capped" bool  /* bool */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'path_count_estimate_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:5260
-- graph::sql_facade::admin::add_sync_policy
CREATE  FUNCTION graph."add_sync_policy"(
	"graph_name" TEXT, /* & str */
	"schedule_interval_secs" bigint DEFAULT 60, /* i64 */
	"max_sync_lag_rows" bigint DEFAULT NULL, /* Option < i64 > */
	"enabled" bool DEFAULT true, /* bool */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"policy_id" TEXT,  /* String */
	"job_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"enabled" bool,  /* bool */
	"schedule_interval_secs" bigint,  /* i64 */
	"max_sync_lag_rows" bigint,  /* Option < i64 > */
	"next_run_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"last_status" TEXT  /* Option < String > */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'add_sync_policy_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3504
-- graph::sql_facade::admin::equals
CREATE  FUNCTION graph."equals"(
	"column_name" TEXT, /* & str */
	"value" TEXT /* & str */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'equals_text_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/discovery.rs:45
-- graph::sql_facade::discovery::auto_discover_tables
CREATE  FUNCTION graph."auto_discover_tables"(
	"tables" oid[], /* Vec < pgrx :: pg_sys :: Oid > */
	"tenant_column" TEXT DEFAULT NULL, /* Option < String > */
	"graph_name" TEXT DEFAULT NULL, /* Option < & str > */
	"build" bool DEFAULT true, /* bool */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"item_type" TEXT,  /* String */
	"item_name" TEXT,  /* String */
	"details" TEXT  /* String */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'auto_discover_tables_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3640
-- graph::sql_facade::admin::gte
CREATE  FUNCTION graph."gte"(
	"column_name" TEXT, /* & str */
	"value" bigint /* i64 */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'gte_i64_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:6624
-- graph::sql_facade::admin::enable_sync
CREATE  FUNCTION graph."enable_sync"() RETURNS void
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'enable_sync_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:196
-- graph::sql_facade::admin::_record_sync_watermark_for_current_role
CREATE  FUNCTION graph."_record_sync_watermark_for_current_role"() RETURNS bool /* bool */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'record_sync_watermark_for_current_role_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:1701
-- graph::sql_facade::admin::projection_gc
CREATE  FUNCTION graph."projection_gc"() RETURNS TABLE (
	"valid_generations_scanned" INT,  /* i32 */
	"retained_generations" bigint[],  /* Vec < i64 > */
	"active_generations" bigint[],  /* Vec < i64 > */
	"obsolete_candidates" INT,  /* i32 */
	"protected_candidates" INT,  /* i32 */
	"deleted_files" INT,  /* i32 */
	"deleted_bytes" bigint  /* i64 */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'projection_gc_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:1499
-- graph::sql_facade::admin::projection_status
CREATE  FUNCTION graph."projection_status"() RETURNS TABLE (
	"manifest_generation" bigint,  /* Option < i64 > */
	"manifest_watermark" bigint,  /* Option < i64 > */
	"pending_durable_rows" bigint,  /* i64 */
	"base_artifact_bytes" bigint,  /* i64 */
	"manifest_bytes" bigint,  /* i64 */
	"artifact_bytes" bigint,  /* i64 */
	"segment_count" INT,  /* i32 */
	"segment_bytes" bigint,  /* i64 */
	"segment_fanout" INT,  /* i32 */
	"read_amplification" INT,  /* i32 */
	"l0_segment_count" INT,  /* i32 */
	"l1_segment_count" INT,  /* i32 */
	"l2_segment_count" INT,  /* i32 */
	"edge_segment_count" INT,  /* i32 */
	"node_segment_count" INT,  /* i32 */
	"dirty_chunk_count" INT,  /* i32 */
	"dirty_chunk_bytes" bigint,  /* i64 */
	"tombstone_ratio" double precision,  /* f64 */
	"compaction_backlog" INT,  /* i32 */
	"obsolete_file_count" INT,  /* i32 */
	"obsolete_bytes" bigint,  /* i64 */
	"active_generation_count" INT,  /* i32 */
	"artifact_validation_state" TEXT,  /* String */
	"last_ingestion_unix_micros" bigint,  /* Option < i64 > */
	"last_compaction_unix_micros" bigint,  /* Option < i64 > */
	"last_gc_unix_micros" bigint,  /* Option < i64 > */
	"last_repair_unix_micros" bigint,  /* Option < i64 > */
	"ingest_recommended" bool,  /* bool */
	"compaction_recommended" bool,  /* bool */
	"gc_recommended" bool,  /* bool */
	"repair_recommended" bool  /* bool */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'projection_status_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:553
-- graph::sql_facade::admin::grant_graph
CREATE  FUNCTION graph."grant_graph"(
	"graph_name" TEXT, /* & str */
	"grantee" TEXT, /* & str */
	"privilege" TEXT, /* & str */
	"tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"grantee" oid,  /* pgrx :: pg_sys :: Oid */
	"privilege" TEXT,  /* String */
	"grantor" oid,  /* pgrx :: pg_sys :: Oid */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'grant_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:5617
-- graph::sql_facade::admin::jobs
CREATE  FUNCTION graph."jobs"(
	"graph_name" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL, /* Option < & str > */
	"max_rows" INT DEFAULT 50 /* i32 */
) RETURNS TABLE (
	"job_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"policy_kind" TEXT,  /* String */
	"enabled" bool,  /* bool */
	"schedule_interval_secs" bigint,  /* i64 */
	"max_runtime_secs" bigint,  /* Option < i64 > */
	"max_retries" INT,  /* i32 */
	"next_run_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"last_run_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"last_status" TEXT,  /* Option < String > */
	"last_error" TEXT,  /* Option < String > */
	"last_sqlstate" TEXT  /* Option < String > */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'jobs_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3383
-- graph::sql_facade::admin::rename_edge
CREATE  FUNCTION graph."rename_edge"(
	"graph_name" TEXT, /* & str */
	"old_label" TEXT, /* & str */
	"new_label" TEXT, /* & str */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS void

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'rename_edge_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:445
-- graph::sql_facade::admin::list_graphs
CREATE  FUNCTION graph."list_graphs"() RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"owner_role" oid,  /* pgrx :: pg_sys :: Oid */
	"created_by" oid,  /* pgrx :: pg_sys :: Oid */
	"tenant" TEXT,  /* Option < String > */
	"namespace" TEXT,  /* Option < String > */
	"graph_kind" TEXT,  /* String */
	"residency" TEXT,  /* String */
	"materialization" TEXT,  /* String */
	"projection_mode" TEXT,  /* String */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'list_graphs_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/search.rs:126
-- graph::sql_facade::search::search_nodes
CREATE  FUNCTION graph."search_nodes"(
	"property_key" TEXT, /* & str */
	"property_value" TEXT, /* & str */
	"table_filter" oid DEFAULT NULL, /* Option < pgrx :: pg_sys :: Oid > */
	"mode" TEXT DEFAULT 'contains', /* & str */
	"case_sensitive" bool DEFAULT false, /* bool */
	"max_rows" INT DEFAULT 100, /* i32 */
	"row_offset" INT DEFAULT 0, /* i32 */
	"tenant" TEXT DEFAULT NULL /* Option < String > */
) RETURNS TABLE (
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT,  /* String */
	"match_type" TEXT,  /* String */
	"score" real,  /* f32 */
	"verified" bool,  /* bool */
	"node_table_name" TEXT  /* String */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_nodes_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3744
-- graph::sql_facade::admin::remove_table
CREATE  FUNCTION graph."remove_table"(
	"table_name" oid /* pgrx :: pg_sys :: Oid */
) RETURNS void
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'remove_table_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:633
-- graph::sql_facade::admin::transfer_graph_ownership
CREATE  FUNCTION graph."transfer_graph_ownership"(
	"graph_name" TEXT, /* & str */
	"new_owner" TEXT, /* & str */
	"tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"owner_role" oid,  /* pgrx :: pg_sys :: Oid */
	"created_by" oid,  /* pgrx :: pg_sys :: Oid */
	"tenant" TEXT,  /* Option < String > */
	"namespace" TEXT,  /* Option < String > */
	"graph_kind" TEXT,  /* String */
	"residency" TEXT,  /* String */
	"materialization" TEXT,  /* String */
	"projection_mode" TEXT,  /* String */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'transfer_graph_ownership_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:4488
-- graph::sql_facade::admin::apply_sync
CREATE  FUNCTION graph."apply_sync"() RETURNS TABLE (
	"inserts_applied" bigint,  /* i64 */
	"updates_applied" bigint,  /* i64 */
	"deletes_applied" bigint  /* i64 */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'apply_sync_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/cypher.rs:17
-- graph::sql_facade::cypher::cypher
CREATE  FUNCTION graph."cypher"(
	"query" TEXT, /* & str */
	"params" jsonb DEFAULT NULL, /* Option < pgrx :: JsonB > */
	"hydrate" bool DEFAULT true /* bool */
) RETURNS TABLE (
	"row" jsonb  /* pgrx :: JsonB */
)
VOLATILE  COST 1000
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'cypher_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:1967
-- graph::sql_facade::admin::sync_health
CREATE  FUNCTION graph."sync_health"() RETURNS TABLE (
	"sync_mode" TEXT,  /* String */
	"query_freshness" TEXT,  /* String */
	"sync_batch_size" INT,  /* i32 */
	"applied_sync_id" bigint,  /* i64 */
	"max_sync_log_id" bigint,  /* i64 */
	"pending_sync_rows" bigint,  /* i64 */
	"disabled_trigger_count" INT,  /* i32 */
	"edge_buffer_used" INT,  /* i32 */
	"edge_buffer_size" INT,  /* i32 */
	"needs_vacuum" bool,  /* bool */
	"needs_rebuild" bool,  /* bool */
	"read_only" bool,  /* bool */
	"read_only_reason" TEXT,  /* Option < String > */
	"projection_mode" TEXT,  /* String */
	"overlay_tombstone_count" INT,  /* i32 */
	"overlay_memory_bytes" bigint,  /* i64 */
	"compaction_recommended" bool,  /* bool */
	"tx_delta_dirty" bool,  /* bool */
	"tx_delta_added_nodes" INT,  /* i32 */
	"tx_delta_deleted_nodes" INT,  /* i32 */
	"tx_delta_added_edges" INT,  /* i32 */
	"tx_delta_deleted_edges" INT,  /* i32 */
	"tx_delta_memory_bytes" bigint,  /* i64 */
	"apply_sync_recommended" bool,  /* bool */
	"maintenance_recommended" bool,  /* bool */
	"durable_ingest_recommended" bool,  /* bool */
	"durable_compaction_recommended" bool,  /* bool */
	"durable_gc_recommended" bool,  /* bool */
	"durable_repair_recommended" bool,  /* bool */
	"sync_log_retention_floor" bigint,  /* Option < i64 > */
	"sync_log_prune_recommended" bool,  /* bool */
	"active_sync_watermark_backends" INT  /* i32 */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sync_health_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3674
-- graph::sql_facade::admin::lte
CREATE  FUNCTION graph."lte"(
	"column_name" TEXT, /* & str */
	"value" bigint /* i64 */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'lte_i64_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:5567
-- graph::sql_facade::admin::sync_policy_status
CREATE  FUNCTION graph."sync_policy_status"(
	"graph_name" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL, /* Option < & str > */
	"max_rows" INT DEFAULT 50 /* i32 */
) RETURNS TABLE (
	"policy_id" TEXT,  /* String */
	"job_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"enabled" bool,  /* bool */
	"schedule_interval_secs" bigint,  /* i64 */
	"max_sync_lag_rows" bigint,  /* Option < i64 > */
	"next_run_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"last_run_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"last_status" TEXT,  /* Option < String > */
	"last_error" TEXT  /* Option < String > */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sync_policy_status_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:1389
-- graph::sql_facade::admin::edge_types
CREATE  FUNCTION graph."edge_types"(
	"after_type_id" bigint DEFAULT 0, /* i64 */
	"max_rows" INT DEFAULT 1000 /* i32 */
) RETURNS TABLE (
	"type_id" bigint,  /* i64 */
	"label" TEXT  /* String */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'edge_type_page_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3545
-- graph::sql_facade::admin::neq
CREATE  FUNCTION graph."neq"(
	"column_name" TEXT, /* & str */
	"value" TEXT /* & str */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'neq_text_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3657
-- graph::sql_facade::admin::lt
CREATE  FUNCTION graph."lt"(
	"column_name" TEXT, /* & str */
	"value" bigint /* i64 */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'lt_i64_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/discovery.rs:7
-- graph::sql_facade::discovery::auto_discover
CREATE  FUNCTION graph."auto_discover"(
	"schema_name" TEXT DEFAULT 'public', /* & str */
	"graph_name" TEXT DEFAULT NULL, /* Option < & str > */
	"build" bool DEFAULT true, /* bool */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"item_type" TEXT,  /* String */
	"item_name" TEXT,  /* String */
	"details" TEXT  /* String */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'auto_discover_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/lib.rs:902
-- requires:
--   auto_discover

-- graph extension bootstrap SQL
-- Creates catalog tables for storing registered tables and edges.

DO $$
BEGIN
    CREATE TYPE graph.node_ref AS (
        node_table REGCLASS,
        node_id    TEXT
    );
EXCEPTION WHEN duplicate_object THEN
    NULL;
END
$$;

CREATE OR REPLACE FUNCTION graph.node_ref(node_table REGCLASS, node_id TEXT)
RETURNS graph.node_ref
LANGUAGE sql
IMMUTABLE
PARALLEL SAFE
AS $$
    SELECT (node_table, node_id)::graph.node_ref
$$;

CREATE OR REPLACE FUNCTION graph.traverse(
    starts        graph.node_ref[],
    max_depth     INTEGER DEFAULT (current_setting('graph.default_max_depth'))::INTEGER,
    edge_types    TEXT[] DEFAULT NULL,
    direction     TEXT DEFAULT 'any',
    node_tables   OID[] DEFAULT NULL,
    filter        JSONB DEFAULT NULL,
    tenant        TEXT DEFAULT NULL,
    strategy      TEXT DEFAULT 'bfs',
    uniqueness    TEXT DEFAULT 'node_global',
    include_start BOOLEAN DEFAULT true,
    hydrate       BOOLEAN DEFAULT true,
    max_rows      INTEGER DEFAULT 1000,
    row_offset    INTEGER DEFAULT 0,
    max_nodes     INTEGER DEFAULT COALESCE(NULLIF(current_setting('graph.max_nodes', true), '')::INTEGER, 100000),
    max_frontier  INTEGER DEFAULT COALESCE(NULLIF(current_setting('graph.max_frontier', true), '')::INTEGER, 100000)
)
RETURNS TABLE (
    root_table OID,
    root_id    TEXT,
    node_table OID,
    node_id    TEXT,
    depth      INTEGER,
    path       JSONB,
    edge_path  JSONB,
    node       JSONB,
    root_table_name TEXT,
    node_table_name TEXT,
    capped     BOOLEAN
)
LANGUAGE sql
STABLE
COST 1000
ROWS 1000
AS $$
    SELECT t.root_table,
           t.root_id,
           t.node_table,
           t.node_id,
           t.depth,
           t.path,
           t.edge_path,
           t.node,
           t.root_table_name,
           t.node_table_name,
           t.capped
    FROM graph.traverse(
        ARRAY(SELECT start_ref.node_table::oid FROM unnest($1) AS start_ref),
        ARRAY(SELECT start_ref.node_id FROM unnest($1) AS start_ref),
        $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
    ) AS t;
$$;

CREATE TABLE IF NOT EXISTS graph._registered_tables (
    table_name TEXT PRIMARY KEY,
    id_column  TEXT NOT NULL,
    columns    TEXT DEFAULT '',
    tenant_column TEXT
);

CREATE TABLE IF NOT EXISTS graph._registered_edges (
    from_table    TEXT NOT NULL,
    from_column   TEXT NOT NULL,
    to_table      TEXT NOT NULL,
    to_column     TEXT NOT NULL,
    label         TEXT NOT NULL,
    bidirectional BOOLEAN DEFAULT true,
    weight_column TEXT,
    label_column  TEXT,
    UNIQUE (from_table, from_column, to_table, to_column, label)
);

ALTER TABLE graph._registered_edges
    ADD COLUMN IF NOT EXISTS label_column TEXT;

ALTER TABLE graph._registered_tables
    ADD COLUMN IF NOT EXISTS tenant_column TEXT;

CREATE TABLE IF NOT EXISTS graph._registered_filter_columns (
    table_name  TEXT NOT NULL,
    column_name TEXT NOT NULL,
    column_type TEXT NOT NULL DEFAULT 'numeric',
    UNIQUE (table_name, column_name)
);

ALTER TABLE graph._registered_filter_columns
    ADD COLUMN IF NOT EXISTS column_type TEXT NOT NULL DEFAULT 'numeric';

CREATE TABLE IF NOT EXISTS graph._graphs (
    graph_id        UUID PRIMARY KEY,
    graph_name      TEXT NOT NULL,
    owner_role      OID NOT NULL,
    created_by      OID NOT NULL,
    tenant          TEXT,
    namespace       TEXT,
    graph_kind      TEXT NOT NULL CHECK (graph_kind IN ('global', 'user', 'tenant', 'workspace', 'subgraph')),
    residency       TEXT NOT NULL CHECK (residency IN ('hot', 'warm', 'cold')),
    materialization TEXT NOT NULL CHECK (materialization IN ('shared', 'dedicated')),
    projection_mode TEXT NOT NULL CHECK (projection_mode IN ('csr_readonly', 'mutable_overlay')),
    created_at      TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at      TIMESTAMPTZ NOT NULL DEFAULT now()
);

ALTER TABLE graph._graphs
    ADD COLUMN IF NOT EXISTS tenant TEXT,
    ADD COLUMN IF NOT EXISTS namespace TEXT,
    ADD COLUMN IF NOT EXISTS graph_kind TEXT,
    ADD COLUMN IF NOT EXISTS residency TEXT,
    ADD COLUMN IF NOT EXISTS materialization TEXT,
    ADD COLUMN IF NOT EXISTS projection_mode TEXT,
    ADD COLUMN IF NOT EXISTS created_at TIMESTAMPTZ,
    ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ,
    ADD COLUMN IF NOT EXISTS sync_log_pruned_before_id BIGINT;

UPDATE graph._graphs
SET namespace = COALESCE(namespace, 'public'),
    graph_kind = COALESCE(graph_kind, 'global'),
    residency = COALESCE(residency, 'hot'),
    materialization = COALESCE(materialization, 'shared'),
    projection_mode = COALESCE(projection_mode, 'csr_readonly'),
    created_at = COALESCE(created_at, now()),
    updated_at = COALESCE(updated_at, now()),
    sync_log_pruned_before_id = COALESCE(sync_log_pruned_before_id, 0);

ALTER TABLE graph._graphs
    ALTER COLUMN graph_kind SET NOT NULL,
    ALTER COLUMN residency SET NOT NULL,
    ALTER COLUMN materialization SET NOT NULL,
    ALTER COLUMN projection_mode SET NOT NULL,
    ALTER COLUMN created_at SET DEFAULT now(),
    ALTER COLUMN created_at SET NOT NULL,
    ALTER COLUMN updated_at SET DEFAULT now(),
    ALTER COLUMN updated_at SET NOT NULL,
    ALTER COLUMN sync_log_pruned_before_id SET DEFAULT 0,
    ALTER COLUMN sync_log_pruned_before_id SET NOT NULL;

DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._graphs'::regclass
          AND conname = '_graphs_graph_kind_check'
    ) THEN
        ALTER TABLE graph._graphs
            ADD CONSTRAINT _graphs_graph_kind_check
            CHECK (graph_kind IN ('global', 'user', 'tenant', 'workspace', 'subgraph'));
    END IF;
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._graphs'::regclass
          AND conname = '_graphs_residency_check'
    ) THEN
        ALTER TABLE graph._graphs
            ADD CONSTRAINT _graphs_residency_check
            CHECK (residency IN ('hot', 'warm', 'cold'));
    END IF;
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._graphs'::regclass
          AND conname = '_graphs_materialization_check'
    ) THEN
        ALTER TABLE graph._graphs
            ADD CONSTRAINT _graphs_materialization_check
            CHECK (materialization IN ('shared', 'dedicated'));
    END IF;
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._graphs'::regclass
          AND conname = '_graphs_projection_mode_check'
    ) THEN
        ALTER TABLE graph._graphs
            ADD CONSTRAINT _graphs_projection_mode_check
            CHECK (projection_mode IN ('csr_readonly', 'mutable_overlay'));
    END IF;
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._graphs'::regclass
          AND conname = '_graphs_sync_log_pruned_before_id_check'
    ) THEN
        ALTER TABLE graph._graphs
            ADD CONSTRAINT _graphs_sync_log_pruned_before_id_check
            CHECK (sync_log_pruned_before_id >= 0);
    END IF;
END $$;

INSERT INTO graph._graphs (
    graph_id,
    graph_name,
    owner_role,
    created_by,
    tenant,
    namespace,
    graph_kind,
    residency,
    materialization,
    projection_mode
)
SELECT '00000000-0000-0000-0000-000000000001'::uuid,
       'default',
       pg_catalog.quote_ident(CURRENT_USER)::pg_catalog.regrole::pg_catalog.oid,
       pg_catalog.quote_ident(CURRENT_USER)::pg_catalog.regrole::pg_catalog.oid,
       NULL,
       'public',
       'global',
       'hot',
       'shared',
       'csr_readonly'
WHERE NOT EXISTS (
    SELECT 1
    FROM graph._graphs
    WHERE graph_id = '00000000-0000-0000-0000-000000000001'::uuid
);

CREATE UNIQUE INDEX IF NOT EXISTS _graphs_identity_idx
    ON graph._graphs (
        COALESCE(tenant, ''),
        owner_role,
        COALESCE(namespace, ''),
        graph_name
    );

CREATE TABLE IF NOT EXISTS graph._graph_grants (
    graph_id   UUID NOT NULL REFERENCES graph._graphs(graph_id) ON DELETE CASCADE,
    grantee    OID NOT NULL,
    privilege  TEXT NOT NULL CHECK (privilege IN ('read', 'write', 'build', 'admin')),
    grantor    OID NOT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    PRIMARY KEY (graph_id, grantee, privilege)
);

ALTER TABLE graph._graph_grants
    ADD COLUMN IF NOT EXISTS created_at TIMESTAMPTZ,
    ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ;

UPDATE graph._graph_grants
SET created_at = COALESCE(created_at, now()),
    updated_at = COALESCE(updated_at, now());

ALTER TABLE graph._graph_grants
    ALTER COLUMN created_at SET DEFAULT now(),
    ALTER COLUMN created_at SET NOT NULL,
    ALTER COLUMN updated_at SET DEFAULT now(),
    ALTER COLUMN updated_at SET NOT NULL;

DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._graph_grants'::regclass
          AND conname = '_graph_grants_privilege_check'
    ) THEN
        ALTER TABLE graph._graph_grants
            ADD CONSTRAINT _graph_grants_privilege_check
            CHECK (privilege IN ('read', 'write', 'build', 'admin'));
    END IF;
END $$;

CREATE TABLE IF NOT EXISTS graph._graph_quotas (
    scope_type  TEXT NOT NULL CHECK (scope_type IN ('cluster', 'tenant', 'owner', 'namespace', 'graph')),
    scope_key   TEXT NOT NULL DEFAULT '',
    dimension   TEXT NOT NULL CHECK (
        dimension IN (
            'max_named_graphs',
            'max_physical_graphs',
            'max_graph_jobs',
            'max_sync_lag_rows',
            'max_artifact_storage_bytes',
            'max_build_memory_mb',
            'max_loaded_graphs_per_backend',
            'max_compaction_work'
        )
    ),
    limit_value BIGINT NOT NULL CHECK (limit_value >= 0),
    enforcement TEXT NOT NULL CHECK (enforcement IN ('hard', 'warn')),
    updated_by  OID NOT NULL DEFAULT (
        pg_catalog.quote_ident(CURRENT_USER)::pg_catalog.regrole::pg_catalog.oid
    ),
    created_at  TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at  TIMESTAMPTZ NOT NULL DEFAULT now(),
    PRIMARY KEY (scope_type, scope_key, dimension)
);

ALTER TABLE graph._graph_quotas
    ADD COLUMN IF NOT EXISTS updated_by OID,
    ADD COLUMN IF NOT EXISTS created_at TIMESTAMPTZ,
    ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ;

UPDATE graph._graph_quotas
SET updated_by = COALESCE(
        updated_by,
        pg_catalog.quote_ident(CURRENT_USER)::pg_catalog.regrole::pg_catalog.oid
    ),
    created_at = COALESCE(created_at, now()),
    updated_at = COALESCE(updated_at, now());

ALTER TABLE graph._graph_quotas
    ALTER COLUMN updated_by SET DEFAULT (
        pg_catalog.quote_ident(CURRENT_USER)::pg_catalog.regrole::pg_catalog.oid
    ),
    ALTER COLUMN updated_by SET NOT NULL,
    ALTER COLUMN created_at SET DEFAULT now(),
    ALTER COLUMN created_at SET NOT NULL,
    ALTER COLUMN updated_at SET DEFAULT now(),
    ALTER COLUMN updated_at SET NOT NULL;

DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._graph_quotas'::regclass
          AND conname = '_graph_quotas_scope_type_check'
    ) THEN
        ALTER TABLE graph._graph_quotas
            ADD CONSTRAINT _graph_quotas_scope_type_check
            CHECK (scope_type IN ('cluster', 'tenant', 'owner', 'namespace', 'graph'));
    END IF;
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._graph_quotas'::regclass
          AND conname = '_graph_quotas_dimension_check'
    ) THEN
        ALTER TABLE graph._graph_quotas
            ADD CONSTRAINT _graph_quotas_dimension_check
            CHECK (
                dimension IN (
                    'max_named_graphs',
                    'max_physical_graphs',
                    'max_graph_jobs',
                    'max_sync_lag_rows',
                    'max_artifact_storage_bytes',
                    'max_build_memory_mb',
                    'max_loaded_graphs_per_backend',
                    'max_compaction_work'
                )
            );
    END IF;
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._graph_quotas'::regclass
          AND conname = '_graph_quotas_enforcement_check'
    ) THEN
        ALTER TABLE graph._graph_quotas
            ADD CONSTRAINT _graph_quotas_enforcement_check
            CHECK (enforcement IN ('hard', 'warn'));
    END IF;
END $$;

ALTER TABLE graph._registered_tables
    ADD COLUMN IF NOT EXISTS graph_id UUID;

ALTER TABLE graph._registered_edges
    ADD COLUMN IF NOT EXISTS graph_id UUID;

ALTER TABLE graph._registered_filter_columns
    ADD COLUMN IF NOT EXISTS graph_id UUID;

-- Relation OIDs are the durable identity for registered source tables. The
-- legacy text columns remain display metadata so existing dumps can be read,
-- but runtime catalog reads derive names from these OIDs.
ALTER TABLE graph._registered_tables
    ADD COLUMN IF NOT EXISTS table_oid OID;

ALTER TABLE graph._registered_edges
    ADD COLUMN IF NOT EXISTS from_table_oid OID,
    ADD COLUMN IF NOT EXISTS to_table_oid OID,
    ADD COLUMN IF NOT EXISTS source_key_columns TEXT;

ALTER TABLE graph._registered_filter_columns
    ADD COLUMN IF NOT EXISTS table_oid OID;

UPDATE graph._registered_tables
SET table_oid = pg_catalog.to_regclass(table_name)::oid
WHERE table_oid IS NULL;

UPDATE graph._registered_edges
SET from_table_oid = pg_catalog.to_regclass(from_table)::oid,
    to_table_oid = pg_catalog.to_regclass(to_table)::oid
WHERE from_table_oid IS NULL
   OR to_table_oid IS NULL;

-- Backfill durable relationship source keys for existing mappings. Relations
-- without a declared primary key remain NULL and are rejected with guidance at
-- catalog read time; `ctid` is deliberately never used as a substitute.
UPDATE graph._registered_edges AS registered
SET source_key_columns = (
    SELECT string_agg(attribute.attname::text, ',' ORDER BY key_column.ordinality)
      FROM pg_catalog.pg_index AS index
      JOIN pg_catalog.unnest(index.indkey) WITH ORDINALITY
           AS key_column(attnum, ordinality) ON true
      JOIN pg_catalog.pg_attribute AS attribute
        ON attribute.attrelid = index.indrelid
       AND attribute.attnum = key_column.attnum
     WHERE index.indrelid = registered.from_table_oid
       AND index.indisprimary
)
WHERE source_key_columns IS NULL;

UPDATE graph._registered_filter_columns
SET table_oid = pg_catalog.to_regclass(table_name)::oid
WHERE table_oid IS NULL;

UPDATE graph._registered_tables
SET graph_id = '00000000-0000-0000-0000-000000000001'::uuid
WHERE graph_id IS NULL;

UPDATE graph._registered_edges
SET graph_id = '00000000-0000-0000-0000-000000000001'::uuid
WHERE graph_id IS NULL;

UPDATE graph._registered_filter_columns
SET graph_id = '00000000-0000-0000-0000-000000000001'::uuid
WHERE graph_id IS NULL;

ALTER TABLE graph._registered_tables
    ALTER COLUMN graph_id SET NOT NULL;

ALTER TABLE graph._registered_edges
    ALTER COLUMN graph_id SET NOT NULL;

CREATE SEQUENCE IF NOT EXISTS graph._registered_edges_mapping_id_seq;

ALTER TABLE graph._registered_edges
    ADD COLUMN IF NOT EXISTS mapping_id BIGINT;

UPDATE graph._registered_edges
SET mapping_id = nextval('graph._registered_edges_mapping_id_seq')
WHERE mapping_id IS NULL;

ALTER TABLE graph._registered_edges
    ALTER COLUMN mapping_id SET DEFAULT nextval('graph._registered_edges_mapping_id_seq'),
    ALTER COLUMN mapping_id SET NOT NULL;

CREATE UNIQUE INDEX IF NOT EXISTS _registered_edges_graph_mapping_id_idx
    ON graph._registered_edges (graph_id, mapping_id);

ALTER TABLE graph._registered_filter_columns
    ALTER COLUMN graph_id SET NOT NULL;

ALTER TABLE graph._registered_tables
    DROP CONSTRAINT IF EXISTS _registered_tables_pkey;

DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._registered_tables'::regclass
          AND conname = '_registered_tables_pkey'
    ) THEN
        ALTER TABLE graph._registered_tables
            ADD CONSTRAINT _registered_tables_pkey PRIMARY KEY (graph_id, table_name);
    END IF;
END $$;

DO $$
DECLARE
    constraint_name name;
BEGIN
    FOR constraint_name IN
        SELECT conname
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._registered_edges'::regclass
          AND contype = 'u'
    LOOP
        EXECUTE format('ALTER TABLE graph._registered_edges DROP CONSTRAINT %I', constraint_name);
    END LOOP;

    FOR constraint_name IN
        SELECT conname
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._registered_filter_columns'::regclass
          AND contype = 'u'
    LOOP
        EXECUTE format('ALTER TABLE graph._registered_filter_columns DROP CONSTRAINT %I', constraint_name);
    END LOOP;
END $$;

CREATE UNIQUE INDEX IF NOT EXISTS _registered_edges_graph_identity_idx
    ON graph._registered_edges (
        graph_id,
        from_table,
        from_column,
        to_table,
        to_column,
        label
    );

CREATE UNIQUE INDEX IF NOT EXISTS _registered_filter_columns_graph_identity_idx
    ON graph._registered_filter_columns (
        graph_id,
        table_name,
        column_name
    );

DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._registered_tables'::regclass
          AND conname = '_registered_tables_graph_id_fkey'
    ) THEN
        ALTER TABLE graph._registered_tables
            ADD CONSTRAINT _registered_tables_graph_id_fkey
            FOREIGN KEY (graph_id) REFERENCES graph._graphs(graph_id) ON DELETE RESTRICT;
    END IF;
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._registered_edges'::regclass
          AND conname = '_registered_edges_graph_id_fkey'
    ) THEN
        ALTER TABLE graph._registered_edges
            ADD CONSTRAINT _registered_edges_graph_id_fkey
            FOREIGN KEY (graph_id) REFERENCES graph._graphs(graph_id) ON DELETE RESTRICT;
    END IF;
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._registered_filter_columns'::regclass
          AND conname = '_registered_filter_columns_graph_id_fkey'
    ) THEN
        ALTER TABLE graph._registered_filter_columns
            ADD CONSTRAINT _registered_filter_columns_graph_id_fkey
            FOREIGN KEY (graph_id) REFERENCES graph._graphs(graph_id) ON DELETE RESTRICT;
    END IF;
END $$;

CREATE TABLE IF NOT EXISTS graph._build_jobs (
    build_id       TEXT PRIMARY KEY,
    graph_id       UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000001'::uuid,
    status         TEXT NOT NULL CHECK (status IN ('queued', 'running', 'completed', 'failed')),
    nodes_loaded   BIGINT,
    edges_loaded   BIGINT,
    build_time_ms  DOUBLE PRECISION,
    memory_used_mb DOUBLE PRECISION,
    sync_mode      TEXT NOT NULL DEFAULT 'trigger',
    projection_mode TEXT NOT NULL DEFAULT 'csr_readonly'
        CHECK (projection_mode IN ('csr_readonly', 'mutable_overlay')),
    progress_phase TEXT NOT NULL DEFAULT 'queued',
    progress_message TEXT,
    started_at     TIMESTAMPTZ,
    finished_at    TIMESTAMPTZ,
    error          TEXT,
    worker_pid     INTEGER,
    created_at     TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at     TIMESTAMPTZ NOT NULL DEFAULT now()
);

ALTER TABLE graph._build_jobs
    ADD COLUMN IF NOT EXISTS graph_id UUID,
    ADD COLUMN IF NOT EXISTS projection_mode TEXT,
    ADD COLUMN IF NOT EXISTS progress_phase TEXT,
    ADD COLUMN IF NOT EXISTS progress_message TEXT;

UPDATE graph._build_jobs
SET graph_id = '00000000-0000-0000-0000-000000000001'::uuid
WHERE graph_id IS NULL;

UPDATE graph._build_jobs
SET projection_mode = 'csr_readonly'
WHERE projection_mode IS NULL
   OR projection_mode NOT IN ('csr_readonly', 'mutable_overlay');

UPDATE graph._build_jobs
SET progress_phase = CASE status
    WHEN 'running' THEN 'building'
    ELSE status
END
WHERE progress_phase IS NULL;

UPDATE graph._build_jobs
SET progress_message = CASE status
    WHEN 'queued' THEN 'queued for background build'
    WHEN 'running' THEN 'building graph from registered source tables'
    WHEN 'completed' THEN 'build completed'
    WHEN 'failed' THEN COALESCE(error, 'build failed')
    ELSE progress_message
END
WHERE progress_message IS NULL;

ALTER TABLE graph._build_jobs
    ALTER COLUMN graph_id SET DEFAULT '00000000-0000-0000-0000-000000000001'::uuid,
    ALTER COLUMN graph_id SET NOT NULL,
    ALTER COLUMN projection_mode SET DEFAULT 'csr_readonly',
    ALTER COLUMN projection_mode SET NOT NULL,
    ALTER COLUMN progress_phase SET DEFAULT 'queued',
    ALTER COLUMN progress_phase SET NOT NULL;

DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._build_jobs'::regclass
          AND conname = '_build_jobs_graph_id_fkey'
    ) THEN
        ALTER TABLE graph._build_jobs
            ADD CONSTRAINT _build_jobs_graph_id_fkey
            FOREIGN KEY (graph_id) REFERENCES graph._graphs(graph_id) ON DELETE RESTRICT;
    END IF;
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._build_jobs'::regclass
          AND conname = '_build_jobs_projection_mode_check'
    ) THEN
        ALTER TABLE graph._build_jobs
            ADD CONSTRAINT _build_jobs_projection_mode_check
            CHECK (projection_mode IN ('csr_readonly', 'mutable_overlay'));
    END IF;
END $$;

CREATE INDEX IF NOT EXISTS _build_jobs_status_idx
    ON graph._build_jobs (status, created_at);

CREATE INDEX IF NOT EXISTS _build_jobs_graph_status_idx
    ON graph._build_jobs (graph_id, status, created_at);

CREATE TABLE IF NOT EXISTS graph._maintenance_jobs (
    job_id            TEXT PRIMARY KEY,
    graph_id          UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000001'::uuid,
    status            TEXT NOT NULL CHECK (status IN ('queued', 'running', 'completed', 'failed')),
    sync_rows_applied BIGINT,
    nodes_after       BIGINT,
    edges_after       BIGINT,
    vacuum_time_ms    DOUBLE PRECISION,
    progress_phase    TEXT NOT NULL DEFAULT 'queued',
    progress_message  TEXT,
    started_at        TIMESTAMPTZ,
    finished_at       TIMESTAMPTZ,
    error             TEXT,
    worker_pid        INTEGER,
    created_at        TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at        TIMESTAMPTZ NOT NULL DEFAULT now()
);

ALTER TABLE graph._maintenance_jobs
    ADD COLUMN IF NOT EXISTS graph_id UUID,
    ADD COLUMN IF NOT EXISTS progress_phase TEXT,
    ADD COLUMN IF NOT EXISTS progress_message TEXT;

UPDATE graph._maintenance_jobs
SET graph_id = '00000000-0000-0000-0000-000000000001'::uuid
WHERE graph_id IS NULL;

UPDATE graph._maintenance_jobs
SET progress_phase = CASE status
    WHEN 'running' THEN 'rebuilding'
    ELSE status
END
WHERE progress_phase IS NULL;

UPDATE graph._maintenance_jobs
SET progress_message = CASE status
    WHEN 'queued' THEN 'queued for background maintenance'
    WHEN 'running' THEN 'rebuilding graph for maintenance'
    WHEN 'completed' THEN 'maintenance completed'
    WHEN 'failed' THEN COALESCE(error, 'maintenance failed')
    ELSE progress_message
END
WHERE progress_message IS NULL;

ALTER TABLE graph._maintenance_jobs
    ALTER COLUMN graph_id SET DEFAULT '00000000-0000-0000-0000-000000000001'::uuid,
    ALTER COLUMN graph_id SET NOT NULL,
    ALTER COLUMN progress_phase SET DEFAULT 'queued',
    ALTER COLUMN progress_phase SET NOT NULL;

DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._maintenance_jobs'::regclass
          AND conname = '_maintenance_jobs_graph_id_fkey'
    ) THEN
        ALTER TABLE graph._maintenance_jobs
            ADD CONSTRAINT _maintenance_jobs_graph_id_fkey
            FOREIGN KEY (graph_id) REFERENCES graph._graphs(graph_id) ON DELETE RESTRICT;
    END IF;
END $$;

CREATE INDEX IF NOT EXISTS _maintenance_jobs_status_idx
    ON graph._maintenance_jobs (status, created_at);

CREATE INDEX IF NOT EXISTS _maintenance_jobs_graph_status_idx
    ON graph._maintenance_jobs (graph_id, status, created_at);

CREATE TABLE IF NOT EXISTS graph._jobs (
    job_id                 UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    graph_id               UUID NOT NULL REFERENCES graph._graphs(graph_id) ON DELETE CASCADE,
    policy_kind            TEXT NOT NULL,
    enabled                BOOLEAN NOT NULL DEFAULT true,
    schedule_interval_secs BIGINT NOT NULL DEFAULT 60,
    max_runtime_secs       BIGINT,
    max_retries            INTEGER NOT NULL DEFAULT 0,
    next_run_at            TIMESTAMPTZ,
    last_run_at            TIMESTAMPTZ,
    last_status            TEXT,
    last_error             TEXT,
    last_sqlstate          TEXT,
    created_at             TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at             TIMESTAMPTZ NOT NULL DEFAULT now(),
    CHECK (policy_kind IN ('sync_policy')),
    CHECK (schedule_interval_secs > 0),
    CHECK (max_runtime_secs IS NULL OR max_runtime_secs > 0),
    CHECK (max_retries >= 0),
    CHECK (last_status IS NULL OR last_status IN (
        'queued', 'running', 'completed', 'failed', 'disabled',
        'retryable_failed', 'permanent_failed', 'quota_blocked', 'lock_skipped'
    ))
);

CREATE INDEX IF NOT EXISTS _jobs_graph_kind_idx
    ON graph._jobs (graph_id, policy_kind, enabled, next_run_at);

CREATE TABLE IF NOT EXISTS graph._job_runs (
    run_id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    job_id          UUID NOT NULL REFERENCES graph._jobs(job_id) ON DELETE CASCADE,
    graph_id        UUID NOT NULL REFERENCES graph._graphs(graph_id) ON DELETE CASCADE,
    started_at      TIMESTAMPTZ NOT NULL DEFAULT now(),
    finished_at     TIMESTAMPTZ,
    status          TEXT NOT NULL DEFAULT 'running',
    sqlstate        TEXT,
    error           TEXT,
    rows_applied    BIGINT,
    retry_count     INTEGER NOT NULL DEFAULT 0,
    worker_identity TEXT,
    execution_mode  TEXT NOT NULL DEFAULT 'hosted',
    CHECK (status IN (
        'running', 'completed', 'failed', 'disabled',
        'retryable_failed', 'permanent_failed', 'quota_blocked', 'lock_skipped'
    )),
    CHECK (retry_count >= 0),
    CHECK (execution_mode IN ('hosted', 'internal'))
);

CREATE INDEX IF NOT EXISTS _job_runs_job_started_idx
    ON graph._job_runs (job_id, started_at DESC);

CREATE INDEX IF NOT EXISTS _job_runs_graph_started_idx
    ON graph._job_runs (graph_id, started_at DESC);

CREATE TABLE IF NOT EXISTS graph._sync_policies (
    policy_id              UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    graph_id               UUID NOT NULL REFERENCES graph._graphs(graph_id) ON DELETE CASCADE,
    job_id                 UUID NOT NULL UNIQUE REFERENCES graph._jobs(job_id) ON DELETE CASCADE,
    schedule_interval_secs BIGINT NOT NULL DEFAULT 60,
    max_sync_lag_rows      BIGINT,
    enabled                BOOLEAN NOT NULL DEFAULT true,
    last_run_at            TIMESTAMPTZ,
    next_run_at            TIMESTAMPTZ,
    last_status            TEXT,
    last_error             TEXT,
    created_at             TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at             TIMESTAMPTZ NOT NULL DEFAULT now(),
    CHECK (schedule_interval_secs > 0),
    CHECK (max_sync_lag_rows IS NULL OR max_sync_lag_rows >= 0),
    CHECK (last_status IS NULL OR last_status IN (
        'queued', 'running', 'completed', 'failed', 'disabled',
        'retryable_failed', 'permanent_failed', 'quota_blocked', 'lock_skipped'
    ))
);

CREATE INDEX IF NOT EXISTS _sync_policies_graph_enabled_idx
    ON graph._sync_policies (graph_id, enabled, next_run_at);

CREATE TABLE IF NOT EXISTS graph._sync_log (
    id             BIGSERIAL PRIMARY KEY,
    op             CHAR(1) NOT NULL,
    table_oid      OID,
    table_name     TEXT NOT NULL,
    pk             TEXT,
    old_pk         TEXT,
    new_pk         TEXT,
    properties     JSONB,
    old_row        JSONB,
    new_row        JSONB,
    xid            BIGINT,
    needs_vacuum   BOOLEAN DEFAULT false,
    error_message  TEXT,
    created_at     TIMESTAMPTZ DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_sync_log_id ON graph._sync_log (id);
CREATE INDEX IF NOT EXISTS idx_sync_log_created ON graph._sync_log (created_at);

CREATE TABLE IF NOT EXISTS graph._projection_generations (
    graph_id          UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000001'::uuid,
    generation_id     BIGINT NOT NULL CHECK (generation_id > 0),
    backend_pid       INTEGER NOT NULL DEFAULT 0,
    database_oid      OID NOT NULL,
    heartbeat_at      TIMESTAMPTZ NOT NULL DEFAULT now(),
    expires_at        TIMESTAMPTZ NOT NULL DEFAULT now(),
    sync_watermark    BIGINT NOT NULL DEFAULT 0 CHECK (sync_watermark >= 0),
    validation_status TEXT NOT NULL DEFAULT 'valid'
        CHECK (validation_status IN ('valid', 'corrupt', 'repairing')),
    repair_status     TEXT,
    is_current        BOOLEAN NOT NULL DEFAULT false,
    published_at      TIMESTAMPTZ,
    retained_until    TIMESTAMPTZ,
    created_at        TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at        TIMESTAMPTZ NOT NULL DEFAULT now(),
    PRIMARY KEY (graph_id, generation_id, backend_pid, database_oid)
);

ALTER TABLE graph._projection_generations
    ADD COLUMN IF NOT EXISTS graph_id UUID;

UPDATE graph._projection_generations
SET graph_id = '00000000-0000-0000-0000-000000000001'::uuid
WHERE graph_id IS NULL;

ALTER TABLE graph._projection_generations
    ALTER COLUMN graph_id SET DEFAULT '00000000-0000-0000-0000-000000000001'::uuid,
    ALTER COLUMN graph_id SET NOT NULL;

DO $$
BEGIN
    IF EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._projection_generations'::regclass
          AND conname = '_projection_generations_pkey'
    ) THEN
        ALTER TABLE graph._projection_generations
            DROP CONSTRAINT _projection_generations_pkey;
    END IF;

    IF NOT EXISTS (
        SELECT 1
        FROM pg_catalog.pg_constraint
        WHERE conrelid = 'graph._projection_generations'::regclass
          AND conname = '_projection_generations_pkey'
    ) THEN
        ALTER TABLE graph._projection_generations
            ADD CONSTRAINT _projection_generations_pkey
            PRIMARY KEY (graph_id, generation_id, backend_pid, database_oid);
    END IF;

END $$;

DROP INDEX IF EXISTS graph.idx_projection_generations_current;
DROP INDEX IF EXISTS graph.idx_projection_generations_active;

CREATE INDEX IF NOT EXISTS idx_projection_generations_current
    ON graph._projection_generations (graph_id, is_current, generation_id DESC);
CREATE INDEX IF NOT EXISTS idx_projection_generations_active
    ON graph._projection_generations (graph_id, database_oid, expires_at)
    WHERE backend_pid <> 0;

-- Per-backend, per-graph replay-progress heartbeat. Backend-local
-- applied_sync_id (csr_readonly mode) is otherwise invisible to other
-- backends and maintenance jobs, so graph._sync_log cannot be pruned safely
-- without it: a slower or idle backend that has not replayed a row yet
-- would silently diverge from PostgreSQL if that row were deleted. Mirrors
-- graph._projection_generations' heartbeat shape and lifecycle.
CREATE TABLE IF NOT EXISTS graph._sync_watermarks (
    graph_id         UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000001'::uuid,
    backend_pid      INTEGER NOT NULL,
    database_oid     OID NOT NULL,
    applied_sync_id  BIGINT NOT NULL DEFAULT 0 CHECK (applied_sync_id >= 0),
    heartbeat_at     TIMESTAMPTZ NOT NULL DEFAULT now(),
    expires_at       TIMESTAMPTZ NOT NULL DEFAULT now(),
    PRIMARY KEY (graph_id, backend_pid, database_oid)
);

CREATE INDEX IF NOT EXISTS idx_sync_watermarks_active
    ON graph._sync_watermarks (graph_id, expires_at);

CREATE TABLE IF NOT EXISTS graph._sync_buffer (
    id         BIGSERIAL PRIMARY KEY,
    op         CHAR(1) NOT NULL,
    table_name TEXT NOT NULL,
    pk         TEXT NOT NULL,
    old_pk     TEXT,
    new_pk     TEXT,
    properties JSONB,
    created_at TIMESTAMPTZ DEFAULT now()
);

ALTER TABLE graph._sync_buffer ADD COLUMN IF NOT EXISTS old_pk TEXT;
ALTER TABLE graph._sync_buffer ADD COLUMN IF NOT EXISTS new_pk TEXT;

CREATE INDEX IF NOT EXISTS idx_sync_buffer_created ON graph._sync_buffer (created_at);

-- Preserve extension-owned operational state across pg_dump/pg_restore.
-- Source tables remain authoritative for graph contents, but registered graph
-- catalogs, durable jobs, and unapplied sync rows are database state rather
-- than extension install metadata.
SELECT pg_catalog.pg_extension_config_dump('graph._registered_tables', '');
SELECT pg_catalog.pg_extension_config_dump('graph._registered_edges', '');
SELECT pg_catalog.pg_extension_config_dump('graph._registered_filter_columns', '');
SELECT pg_catalog.pg_extension_config_dump('graph._graphs', 'WHERE graph_id != ''00000000-0000-0000-0000-000000000001''');
SELECT pg_catalog.pg_extension_config_dump('graph._graph_grants', '');
SELECT pg_catalog.pg_extension_config_dump('graph._graph_quotas', '');
SELECT pg_catalog.pg_extension_config_dump('graph._build_jobs', '');
SELECT pg_catalog.pg_extension_config_dump('graph._maintenance_jobs', '');
SELECT pg_catalog.pg_extension_config_dump('graph._jobs', '');
SELECT pg_catalog.pg_extension_config_dump('graph._job_runs', '');
SELECT pg_catalog.pg_extension_config_dump('graph._sync_policies', '');
SELECT pg_catalog.pg_extension_config_dump('graph._sync_log', '');
SELECT pg_catalog.pg_extension_config_dump('graph._sync_log_id_seq', '');
SELECT pg_catalog.pg_extension_config_dump('graph._projection_generations', '');
SELECT pg_catalog.pg_extension_config_dump('graph._sync_watermarks', '');
SELECT pg_catalog.pg_extension_config_dump('graph._sync_buffer', '');
SELECT pg_catalog.pg_extension_config_dump('graph._sync_buffer_id_seq', '');

-- Do not run graph.auto_discover() during CREATE EXTENSION.
--
-- PostgreSQL records objects created while an extension script is running as
-- extension members. graph.auto_discover() calls graph.build(), and build uses
-- ON COMMIT DROP temp tables; if those temp tables are created inside the
-- extension transaction, PostgreSQL refuses to drop them because they are
-- marked as extension-owned. Users should run graph.auto_discover() after
-- CREATE EXTENSION completes.

-- ─── Privilege hardening ─────────────────────────────────────────────
-- Sensitive internal catalog tables should not be directly readable or
-- writable by non-admin users. Read access is mediated through filtered
-- graph.* SQL API functions; writes remain guarded by PostgreSQL ACLs and
-- Rust graph-admin checks.
REVOKE ALL ON TABLE graph._registered_tables       FROM PUBLIC;
REVOKE ALL ON TABLE graph._registered_edges        FROM PUBLIC;
REVOKE ALL ON TABLE graph._registered_filter_columns FROM PUBLIC;
REVOKE ALL ON TABLE graph._graphs                 FROM PUBLIC;
REVOKE ALL ON TABLE graph._graph_grants           FROM PUBLIC;
REVOKE ALL ON TABLE graph._graph_quotas           FROM PUBLIC;
REVOKE ALL ON TABLE graph._build_jobs             FROM PUBLIC;
REVOKE ALL ON TABLE graph._maintenance_jobs       FROM PUBLIC;
REVOKE ALL ON TABLE graph._jobs                   FROM PUBLIC;
REVOKE ALL ON TABLE graph._job_runs               FROM PUBLIC;
REVOKE ALL ON TABLE graph._sync_policies          FROM PUBLIC;
REVOKE ALL ON TABLE graph._sync_log               FROM PUBLIC;
REVOKE ALL ON TABLE graph._projection_generations FROM PUBLIC;
REVOKE ALL ON TABLE graph._sync_watermarks        FROM PUBLIC;
REVOKE ALL ON TABLE graph._sync_buffer            FROM PUBLIC;
REVOKE ALL ON SEQUENCE graph._sync_log_id_seq     FROM PUBLIC;
REVOKE ALL ON SEQUENCE graph._sync_buffer_id_seq  FROM PUBLIC;
GRANT SELECT ON TABLE graph._registered_tables       TO PUBLIC;
GRANT SELECT ON TABLE graph._registered_edges        TO PUBLIC;
GRANT SELECT ON TABLE graph._registered_filter_columns TO PUBLIC;

-- Catalog mutation, build/vacuum, sync apply, reset, and global analytics are
-- protected in Rust by graph-admin checks. Production deployments should still
-- grant application roles only the reader functions they need.
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/traversal.rs:504
-- graph::sql_facade::traversal::shortest_path
CREATE  FUNCTION graph."shortest_path"(
	"source_table" oid, /* pgrx :: pg_sys :: Oid */
	"source_id" TEXT, /* & str */
	"target_table" oid, /* pgrx :: pg_sys :: Oid */
	"target_id" TEXT, /* & str */
	"max_depth" INT DEFAULT 20, /* i32 */
	"hydrate" bool DEFAULT true /* bool */
) RETURNS TABLE (
	"step" INT,  /* i32 */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT,  /* String */
	"edge_label" TEXT,  /* Option < String > */
	"node" jsonb,  /* Option < pgrx :: JsonB > */
	"node_table_name" TEXT  /* String */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'shortest_path_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3149
-- graph::sql_facade::admin::registered_tables_for_graph
CREATE  FUNCTION graph."registered_tables_for_graph"(
	"graph_name" TEXT, /* & str */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"table_name" TEXT,  /* String */
	"id_columns" TEXT[],  /* Vec < String > */
	"columns" TEXT[],  /* Vec < String > */
	"tenant_column" TEXT  /* Option < String > */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'registered_tables_for_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3822
-- graph::sql_facade::admin::remove_edge
CREATE  FUNCTION graph."remove_edge"(
	"label" TEXT /* & str */
) RETURNS void
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'remove_edge_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/traversal.rs:235
-- graph::sql_facade::traversal::get_node
CREATE  FUNCTION graph."get_node"(
	"graph_name" TEXT, /* & str */
	"label" TEXT, /* & str */
	"id" TEXT, /* & str */
	"hydrate" bool DEFAULT true, /* bool */
	"tenant" TEXT DEFAULT NULL, /* Option < String > */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_table_name" TEXT,  /* String */
	"node_id" TEXT,  /* String */
	"node_idx" bigint,  /* i64 */
	"node" jsonb  /* Option < pgrx :: JsonB > */
)
 COST 100
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'get_node_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2971
-- graph::sql_facade::admin::add_table_to_graph
CREATE  FUNCTION graph."add_table_to_graph"(
	"graph_name" TEXT, /* & str */
	"table_name" oid, /* pgrx :: pg_sys :: Oid */
	"id_columns" TEXT[], /* Vec < String > */
	"columns" TEXT[] DEFAULT NULL, /* :: std :: option :: Option < Vec < String > > */
	"tenant_column" TEXT DEFAULT NULL, /* Option < String > */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS void
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'add_table_to_graph_with_id_columns_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:778
-- graph::sql_facade::admin::graph_quota_usage
CREATE  FUNCTION graph."graph_quota_usage"() RETURNS TABLE (
	"scope_type" TEXT,  /* String */
	"scope_key" TEXT,  /* String */
	"dimension" TEXT,  /* String */
	"limit_value" bigint,  /* Option < i64 > */
	"usage_value" bigint,  /* i64 */
	"enforcement" TEXT,  /* Option < String > */
	"exceeded" bool  /* bool */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'graph_quota_usage_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/runtime.rs:128
-- graph::sql_facade::runtime::load_graph
CREATE  FUNCTION graph."load_graph"(
	"graph_name" TEXT, /* & str */
	"tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"loaded" bool,  /* bool */
	"node_count" bigint,  /* Option < i64 > */
	"edge_count" bigint,  /* Option < i64 > */
	"memory_used_mb" double precision,  /* Option < f64 > */
	"projection_mode" TEXT  /* Option < String > */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'load_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:6301
-- graph::sql_facade::admin::maintenance_status
CREATE  FUNCTION graph."maintenance_status"(
	"job_id" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"job_id" TEXT,  /* String */
	"status" TEXT,  /* String */
	"sync_rows_applied" bigint,  /* Option < i64 > */
	"nodes_after" bigint,  /* Option < i64 > */
	"edges_after" bigint,  /* Option < i64 > */
	"vacuum_time_ms" double precision,  /* Option < f64 > */
	"progress_phase" TEXT,  /* String */
	"progress_message" TEXT,  /* Option < String > */
	"started_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"finished_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"error" TEXT  /* Option < String > */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'maintenance_status_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:263
-- graph::sql_facade::admin::_active_generation_count_for_current_role
CREATE  FUNCTION graph."_active_generation_count_for_current_role"() RETURNS INT /* i32 */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'active_generation_count_for_current_role_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/pgq.rs:11
-- graph::sql_facade::pgq::pgq
CREATE  FUNCTION graph."pgq"(
	"_query" TEXT /* & str */
) RETURNS void
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'pgq_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:285
-- graph::sql_facade::admin::_enforce_loaded_graph_quota_for_current_role
CREATE  FUNCTION graph."_enforce_loaded_graph_quota_for_current_role"(
	"projected_loaded_graphs" bigint /* i64 */
) RETURNS bool /* bool */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'enforce_loaded_graph_quota_for_current_role_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/components.rs:272
-- graph::sql_facade::components::largest_component
CREATE  FUNCTION graph."largest_component"(
	"max_rows" INT DEFAULT 100, /* i32 */
	"row_offset" INT DEFAULT 0, /* i32 */
	"hydrate" bool DEFAULT true /* bool */
) RETURNS TABLE (
	"component_id" bigint,  /* i64 */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT,  /* String */
	"node" jsonb  /* Option < pgrx :: JsonB > */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'largest_component_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:5890
-- graph::sql_facade::admin::run_due_jobs_async
CREATE  FUNCTION graph."run_due_jobs_async"(
	"max_jobs" INT DEFAULT 64 /* i32 */
) RETURNS bool /* bool */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'run_due_jobs_async_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:9
-- graph::sql_facade::admin::test_enabled
CREATE  FUNCTION graph."test_enabled"() RETURNS bool /* bool */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'test_enabled_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3848
-- graph::sql_facade::admin::remove_edge_from_graph
CREATE  FUNCTION graph."remove_edge_from_graph"(
	"graph_name" TEXT, /* & str */
	"label" TEXT, /* & str */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS void

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'remove_edge_from_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/search.rs:191
-- graph::sql_facade::search::traverse_search
CREATE  FUNCTION graph."traverse_search"(
	"property_key" TEXT, /* & str */
	"property_value" TEXT, /* & str */
	"table_filter" oid DEFAULT NULL, /* Option < pgrx :: pg_sys :: Oid > */
	"search_mode" TEXT DEFAULT COALESCE(NULLIF(current_setting('graph.default_search_mode'), ''), 'contains'), /* & str */
	"case_sensitive" bool DEFAULT current_setting('graph.default_case_sensitive')::boolean, /* bool */
	"search_max_rows" INT DEFAULT 100, /* i32 */
	"search_row_offset" INT DEFAULT 0, /* i32 */
	"max_depth" INT DEFAULT current_setting('graph.default_max_depth')::int, /* i32 */
	"edge_types" TEXT[] DEFAULT NULL, /* :: std :: option :: Option < Vec < String > > */
	"direction" TEXT DEFAULT 'any', /* & str */
	"node_tables" oid[] DEFAULT NULL, /* :: std :: option :: Option < Vec < pgrx :: pg_sys :: Oid > > */
	"filter" jsonb DEFAULT NULL, /* Option < pgrx :: JsonB > */
	"tenant" TEXT DEFAULT NULL, /* Option < String > */
	"strategy" TEXT DEFAULT 'bfs', /* & str */
	"uniqueness" TEXT DEFAULT 'node_per_root', /* & str */
	"include_start" bool DEFAULT true, /* bool */
	"hydrate" bool DEFAULT current_setting('graph.default_hydrate')::boolean, /* bool */
	"max_rows" INT DEFAULT 1000, /* i32 */
	"row_offset" INT DEFAULT 0 /* i32 */
) RETURNS TABLE (
	"root_table" oid,  /* pgrx :: pg_sys :: Oid */
	"root_id" TEXT,  /* String */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT,  /* String */
	"depth" INT,  /* i32 */
	"path" jsonb,  /* pgrx :: JsonB */
	"edge_path" jsonb,  /* pgrx :: JsonB */
	"node" jsonb,  /* Option < pgrx :: JsonB > */
	"root_table_name" TEXT,  /* String */
	"node_table_name" TEXT,  /* String */
	"capped" bool  /* bool */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'traverse_search_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:1488
-- graph::sql_facade::admin::active_generation_count
CREATE  FUNCTION graph."active_generation_count"() RETURNS INT /* i32 */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'active_generation_count_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/cypher.rs:6
-- graph::sql_facade::cypher::cypher_explain
CREATE  FUNCTION graph."cypher_explain"(
	"query" TEXT /* & str */
) RETURNS TEXT /* String */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'cypher_explain_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3571
-- graph::sql_facade::admin::contains_text
CREATE  FUNCTION graph."contains_text"(
	"column_name" TEXT, /* & str */
	"value" TEXT /* & str */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'contains_text_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:5796
-- graph::sql_facade::admin::run_job
CREATE  FUNCTION graph."run_job"(
	"job_id" TEXT /* & str */
) RETURNS TABLE (
	"job_id" TEXT,  /* String */
	"run_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"policy_kind" TEXT,  /* String */
	"status" TEXT,  /* String */
	"rows_applied" bigint,  /* Option < i64 > */
	"error" TEXT,  /* Option < String > */
	"started_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"finished_at" timestamp with time zone  /* Option < TimestampWithTimeZone > */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'run_job_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:29
-- graph::sql_facade::admin::_require_selected_graph_privilege_for_current_role
CREATE  FUNCTION graph."_require_selected_graph_privilege_for_current_role"(
	"privilege" TEXT /* & str */
) RETURNS bool /* bool */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'require_selected_graph_privilege_for_current_role_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/gql.rs:124
-- graph::sql_facade::gql::gql
CREATE  FUNCTION graph."gql"(
	"query" TEXT, /* & str */
	"params" jsonb DEFAULT NULL, /* Option < pgrx :: JsonB > */
	"hydrate" bool DEFAULT true /* bool */
) RETURNS TABLE (
	"row" jsonb  /* pgrx :: JsonB */
)
VOLATILE  COST 1000
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'gql_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:607
-- graph::sql_facade::admin::graph_privileges
CREATE  FUNCTION graph."graph_privileges"(
	"graph_name" TEXT DEFAULT NULL, /* Option < & str > */
	"tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"grantee" oid,  /* pgrx :: pg_sys :: Oid */
	"privilege" TEXT,  /* String */
	"grantor" oid,  /* pgrx :: pg_sys :: Oid */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'graph_privileges_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2933
-- graph::sql_facade::admin::add_table_to_graph
CREATE  FUNCTION graph."add_table_to_graph"(
	"graph_name" TEXT, /* & str */
	"table_name" oid, /* pgrx :: pg_sys :: Oid */
	"id_column" TEXT, /* & str */
	"columns" TEXT[] DEFAULT NULL, /* :: std :: option :: Option < Vec < String > > */
	"tenant_column" TEXT DEFAULT NULL, /* Option < String > */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS void
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'add_table_to_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3406
-- graph::sql_facade::admin::alter_edge
CREATE  FUNCTION graph."alter_edge"(
	"graph_name" TEXT, /* & str */
	"label" TEXT, /* & str */
	"bidirectional" bool DEFAULT NULL, /* Option < bool > */
	"weight_column" TEXT DEFAULT NULL, /* Option < String > */
	"label_column" TEXT DEFAULT NULL, /* Option < String > */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS void

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'alter_edge_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2616
-- graph::sql_facade::admin::build
CREATE  FUNCTION graph."build"(
	"mode" TEXT /* & str */
) RETURNS TABLE (
	"nodes_loaded" bigint,  /* i64 */
	"edges_loaded" bigint,  /* i64 */
	"build_time_ms" double precision,  /* f64 */
	"memory_used_mb" double precision,  /* f64 */
	"sync_mode" TEXT,  /* String */
	"projection_mode" TEXT  /* String */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'build_with_mode_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/traversal.rs:276
-- graph::sql_facade::traversal::get_neighbors
CREATE  FUNCTION graph."get_neighbors"(
	"graph_name" TEXT, /* & str */
	"label" TEXT, /* & str */
	"id" TEXT, /* & str */
	"direction" TEXT DEFAULT 'any', /* & str */
	"edge_types" TEXT[] DEFAULT NULL, /* :: std :: option :: Option < Vec < String > > */
	"tenant" TEXT DEFAULT NULL, /* Option < String > */
	"hydrate" bool DEFAULT true, /* bool */
	"max_rows" INT DEFAULT 1000, /* i32 */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"root_table" oid,  /* pgrx :: pg_sys :: Oid */
	"root_id" TEXT,  /* String */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT,  /* String */
	"depth" INT,  /* i32 */
	"path" jsonb,  /* pgrx :: JsonB */
	"edge_path" jsonb,  /* pgrx :: JsonB */
	"node" jsonb,  /* Option < pgrx :: JsonB > */
	"root_table_name" TEXT,  /* String */
	"node_table_name" TEXT,  /* String */
	"capped" bool  /* bool */
)
 COST 1000
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'get_neighbors_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3690
-- graph::sql_facade::admin::on_node
CREATE  FUNCTION graph."on_node"(
	"filter" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'on_node_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3518
-- graph::sql_facade::admin::eq
CREATE  FUNCTION graph."eq"(
	"column_name" TEXT, /* & str */
	"value" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'eq_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3559
-- graph::sql_facade::admin::in
CREATE  FUNCTION graph."in"(
	"column_name" TEXT, /* & str */
	"values" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'in_filter_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3231
-- graph::sql_facade::admin::registered_edges
CREATE  FUNCTION graph."registered_edges"() RETURNS TABLE (
	"from_table" TEXT,  /* String */
	"from_column" TEXT,  /* String */
	"to_table" TEXT,  /* String */
	"to_column" TEXT,  /* String */
	"label" TEXT,  /* String */
	"bidirectional" bool,  /* bool */
	"weight_column" TEXT,  /* Option < String > */
	"label_column" TEXT  /* Option < String > */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'registered_edges_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/traversal.rs:29
-- graph::sql_facade::traversal::traverse
CREATE  FUNCTION graph."traverse"(
	"seed_table" oid, /* pgrx :: pg_sys :: Oid */
	"seed_id" TEXT, /* & str */
	"max_depth" INT DEFAULT COALESCE(NULLIF(current_setting('graph.default_max_depth', true), '')::int, 5), /* i32 */
	"edge_types" TEXT[] DEFAULT NULL, /* :: std :: option :: Option < Vec < String > > */
	"direction" TEXT DEFAULT 'any', /* & str */
	"node_tables" oid[] DEFAULT NULL, /* :: std :: option :: Option < Vec < pgrx :: pg_sys :: Oid > > */
	"filter" jsonb DEFAULT NULL, /* Option < pgrx :: JsonB > */
	"tenant" TEXT DEFAULT NULL, /* Option < String > */
	"strategy" TEXT DEFAULT 'bfs', /* & str */
	"uniqueness" TEXT DEFAULT 'node_global', /* & str */
	"include_start" bool DEFAULT true, /* bool */
	"hydrate" bool DEFAULT true, /* bool */
	"max_rows" INT DEFAULT 1000, /* i32 */
	"row_offset" INT DEFAULT 0, /* i32 */
	"max_nodes" INT DEFAULT COALESCE(NULLIF(current_setting('graph.max_nodes', true), '')::int, 100000), /* i32 */
	"max_frontier" INT DEFAULT COALESCE(NULLIF(current_setting('graph.max_frontier', true), '')::int, 100000) /* i32 */
) RETURNS TABLE (
	"root_table" oid,  /* pgrx :: pg_sys :: Oid */
	"root_id" TEXT,  /* String */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT,  /* String */
	"depth" INT,  /* i32 */
	"path" jsonb,  /* pgrx :: JsonB */
	"edge_path" jsonb,  /* pgrx :: JsonB */
	"node" jsonb,  /* Option < pgrx :: JsonB > */
	"root_table_name" TEXT,  /* String */
	"node_table_name" TEXT,  /* String */
	"capped" bool  /* bool */
)
 COST 1000
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'traverse_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3512
-- graph::sql_facade::admin::equals
CREATE  FUNCTION graph."equals"(
	"column_name" TEXT, /* & str */
	"value" bigint /* i64 */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'equals_i64_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:753
-- graph::sql_facade::admin::graph_quotas
CREATE  FUNCTION graph."graph_quotas"() RETURNS TABLE (
	"scope_type" TEXT,  /* String */
	"scope_key" TEXT,  /* String */
	"dimension" TEXT,  /* String */
	"limit_value" bigint,  /* i64 */
	"enforcement" TEXT,  /* String */
	"updated_by" oid,  /* pgrx :: pg_sys :: Oid */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'graph_quotas_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3607
-- graph::sql_facade::admin::greater_than
CREATE  FUNCTION graph."greater_than"(
	"column_name" TEXT, /* & str */
	"value" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'greater_than_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2241
-- graph::sql_facade::admin::build_graph
CREATE  FUNCTION graph."build_graph"(
	"graph_name" TEXT, /* & str */
	"force_persist" bool DEFAULT false, /* bool */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"nodes_loaded" bigint,  /* i64 */
	"edges_loaded" bigint,  /* i64 */
	"build_time_ms" double precision,  /* f64 */
	"memory_used_mb" double precision,  /* f64 */
	"sync_mode" TEXT,  /* String */
	"projection_mode" TEXT  /* String */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'build_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:403
-- graph::sql_facade::admin::drop_graph
CREATE  FUNCTION graph."drop_graph"(
	"graph_name" TEXT, /* & str */
	"tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"owner_role" oid,  /* pgrx :: pg_sys :: Oid */
	"created_by" oid,  /* pgrx :: pg_sys :: Oid */
	"tenant" TEXT,  /* Option < String > */
	"namespace" TEXT,  /* Option < String > */
	"graph_kind" TEXT,  /* String */
	"residency" TEXT,  /* String */
	"materialization" TEXT,  /* String */
	"projection_mode" TEXT,  /* String */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'drop_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2058
-- graph::sql_facade::admin::run_scheduled_maintenance
CREATE  FUNCTION graph."run_scheduled_maintenance"() RETURNS TABLE (
	"applied_sync" bool,  /* bool */
	"maintenance_started" bool,  /* bool */
	"maintenance_job_id" TEXT,  /* Option < String > */
	"pending_sync_rows" bigint,  /* i64 */
	"edge_buffer_used" INT,  /* i32 */
	"message" TEXT  /* String */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'run_scheduled_maintenance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3354
-- graph::sql_facade::admin::list_edges
CREATE  FUNCTION graph."list_edges"(
	"graph_name" TEXT, /* & str */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"from_table" TEXT,  /* String */
	"from_column" TEXT,  /* String */
	"to_table" TEXT,  /* String */
	"to_column" TEXT,  /* String */
	"label" TEXT,  /* String */
	"bidirectional" bool,  /* bool */
	"weight_column" TEXT,  /* Option < String > */
	"label_column" TEXT  /* Option < String > */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'list_edges_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/components.rs:12
-- graph::sql_facade::components::connected_components
CREATE  FUNCTION graph."connected_components"() RETURNS TABLE (
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT,  /* String */
	"component_id" bigint,  /* i64 */
	"component_size" INT  /* i32 */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'connected_components_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3612
-- graph::sql_facade::admin::greater_than
CREATE  FUNCTION graph."greater_than"(
	"column_name" TEXT, /* & str */
	"value" bigint /* i64 */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'greater_than_i64_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/runtime.rs:44
-- graph::sql_facade::runtime::reset
CREATE  FUNCTION graph."reset"(
	"clear_registrations" bool /* bool */
) RETURNS void
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'reset_with_registrations_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:4012
-- graph::sql_facade::admin::graph_map
CREATE  FUNCTION graph."graph_map"(
	"graph_name" TEXT, /* & str */
	"format" TEXT DEFAULT 'json', /* & str */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS jsonb /* pgrx :: JsonB */

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'graph_map_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3436
-- graph::sql_facade::admin::add_filter_column
CREATE  FUNCTION graph."add_filter_column"(
	"table_name" oid, /* pgrx :: pg_sys :: Oid */
	"column_name" TEXT, /* & str */
	"column_type" TEXT DEFAULT 'numeric' /* & str */
) RETURNS void
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'add_filter_column_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/traversal.rs:922
-- graph::sql_facade::traversal::weighted_shortest_path
CREATE  FUNCTION graph."weighted_shortest_path"(
	"source_table" oid, /* pgrx :: pg_sys :: Oid */
	"source_id" TEXT, /* & str */
	"target_table" oid, /* pgrx :: pg_sys :: Oid */
	"target_id" TEXT, /* & str */
	"edge_types" TEXT[] /* Vec < String > */
) RETURNS TABLE (
	"step" INT,  /* i32 */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_table_name" TEXT,  /* String */
	"node_id" TEXT,  /* String */
	"edge_label" TEXT,  /* Option < String > */
	"edge_weight" bigint,  /* Option < i64 > */
	"step_cost" bigint,  /* i64 */
	"total_cost" bigint  /* i64 */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'weighted_shortest_path_typed_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3499
-- graph::sql_facade::admin::equals
CREATE  FUNCTION graph."equals"(
	"column_name" TEXT, /* & str */
	"value" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'equals_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:174
-- graph::sql_facade::admin::_expire_sync_watermarks_for_current_role
CREATE  FUNCTION graph."_expire_sync_watermarks_for_current_role"() RETURNS bool /* bool */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'expire_sync_watermarks_for_current_role_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2920
-- graph::sql_facade::admin::add_table
CREATE  FUNCTION graph."add_table"(
	"table_name" oid, /* pgrx :: pg_sys :: Oid */
	"id_columns" TEXT[], /* Vec < String > */
	"columns" TEXT[] DEFAULT NULL, /* :: std :: option :: Option < Vec < String > > */
	"tenant_column" TEXT DEFAULT NULL /* Option < String > */
) RETURNS void
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'add_table_with_id_columns_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:151
-- graph::sql_facade::admin::_expire_projection_heartbeats_for_current_role
CREATE  FUNCTION graph."_expire_projection_heartbeats_for_current_role"() RETURNS bool /* bool */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'expire_projection_heartbeats_for_current_role_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3719
-- graph::sql_facade::admin::all
CREATE  FUNCTION graph."all"(
	"filters" jsonb[] /* Vec < pgrx :: JsonB > */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'all_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3259
-- graph::sql_facade::admin::registered_edges_for_graph
CREATE  FUNCTION graph."registered_edges_for_graph"(
	"graph_name" TEXT, /* & str */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"from_table" TEXT,  /* String */
	"from_column" TEXT,  /* String */
	"to_table" TEXT,  /* String */
	"to_column" TEXT,  /* String */
	"label" TEXT,  /* String */
	"bidirectional" bool,  /* bool */
	"weight_column" TEXT,  /* Option < String > */
	"label_column" TEXT  /* Option < String > */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'registered_edges_for_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/components.rs:331
-- graph::sql_facade::components::isolated_nodes
CREATE  FUNCTION graph."isolated_nodes"(
	"max_rows" INT DEFAULT 100, /* i32 */
	"row_offset" INT DEFAULT 0, /* i32 */
	"hydrate" bool DEFAULT true /* bool */
) RETURNS TABLE (
	"component_id" bigint,  /* i64 */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT,  /* String */
	"node" jsonb  /* Option < pgrx :: JsonB > */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'isolated_nodes_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/runtime.rs:285
-- graph::sql_facade::runtime::graph_runtime_status
CREATE  FUNCTION graph."graph_runtime_status"() RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"residency" TEXT,  /* String */
	"loaded" bool,  /* bool */
	"artifact_exists" bool,  /* bool */
	"artifact_bytes" bigint,  /* Option < i64 > */
	"node_count" bigint,  /* Option < i64 > */
	"edge_count" bigint,  /* Option < i64 > */
	"memory_used_mb" double precision,  /* Option < f64 > */
	"projection_mode" TEXT,  /* Option < String > */
	"last_access_unix_micros" bigint  /* Option < i64 > */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'graph_runtime_status_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3680
-- graph::sql_facade::admin::between
CREATE  FUNCTION graph."between"(
	"column_name" TEXT, /* & str */
	"lower" jsonb, /* pgrx :: JsonB */
	"upper" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'between_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/workflow.rs:509
-- graph::sql_facade::workflow::connection
CREATE  FUNCTION graph."connection"(
	"source_key" TEXT, /* & str */
	"source_value" TEXT, /* & str */
	"target_key" TEXT, /* & str */
	"target_value" TEXT, /* & str */
	"source_table" oid DEFAULT NULL, /* Option < pgrx :: pg_sys :: Oid > */
	"target_table" oid DEFAULT NULL, /* Option < pgrx :: pg_sys :: Oid > */
	"source_k" INT DEFAULT 3, /* i32 */
	"target_k" INT DEFAULT 3, /* i32 */
	"search_mode" TEXT DEFAULT 'contains', /* & str */
	"max_depth" INT DEFAULT 6 /* i32 */
) RETURNS TABLE (
	"source_table_name" TEXT,  /* String */
	"source_id" TEXT,  /* String */
	"target_table_name" TEXT,  /* String */
	"target_id" TEXT,  /* String */
	"hop_count" INT,  /* i32 */
	"step" INT,  /* i32 */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_table_name" TEXT,  /* String */
	"node_id" TEXT,  /* String */
	"edge_label" TEXT,  /* Option < String > */
	"readable_path" TEXT,  /* String */
	"node" jsonb  /* Option < pgrx :: JsonB > */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'connection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:5368
-- graph::sql_facade::admin::alter_sync_policy
CREATE  FUNCTION graph."alter_sync_policy"(
	"policy_id" TEXT, /* & str */
	"schedule_interval_secs" bigint DEFAULT NULL, /* Option < i64 > */
	"max_sync_lag_rows" bigint DEFAULT NULL, /* Option < i64 > */
	"enabled" bool DEFAULT NULL /* Option < bool > */
) RETURNS TABLE (
	"policy_id" TEXT,  /* String */
	"job_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"enabled" bool,  /* bool */
	"schedule_interval_secs" bigint,  /* i64 */
	"max_sync_lag_rows" bigint,  /* Option < i64 > */
	"next_run_at" timestamp with time zone,  /* Option < TimestampWithTimeZone > */
	"last_status" TEXT  /* Option < String > */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'alter_sync_policy_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:227
-- graph::sql_facade::admin::_record_projection_heartbeat_for_current_role
CREATE  FUNCTION graph."_record_projection_heartbeat_for_current_role"() RETURNS bool /* bool */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'record_projection_heartbeat_for_current_role_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3629
-- graph::sql_facade::admin::at_least
CREATE  FUNCTION graph."at_least"(
	"column_name" TEXT, /* & str */
	"value" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'at_least_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:6094
-- graph::sql_facade::admin::vacuum
CREATE  FUNCTION graph."vacuum"() RETURNS TABLE (
	"nodes_before" bigint,  /* i64 */
	"nodes_after" bigint,  /* i64 */
	"tombstones_removed" bigint,  /* i64 */
	"edges_rebuilt" bigint,  /* i64 */
	"vacuum_time_ms" double precision  /* f64 */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vacuum_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/workflow.rs:16
-- graph::sql_facade::workflow::find
CREATE  FUNCTION graph."find"(
	"property_key" TEXT, /* & str */
	"property_value" TEXT, /* & str */
	"table_name" oid DEFAULT NULL, /* Option < pgrx :: pg_sys :: Oid > */
	"mode" TEXT DEFAULT 'contains', /* & str */
	"case_sensitive" bool DEFAULT false, /* bool */
	"max_rows" INT DEFAULT 20, /* i32 */
	"row_offset" INT DEFAULT 0, /* i32 */
	"tenant" TEXT DEFAULT NULL /* Option < String > */
) RETURNS TABLE (
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_table_name" TEXT,  /* String */
	"node_id" TEXT,  /* String */
	"match_type" TEXT,  /* String */
	"score" real,  /* f32 */
	"verified" bool,  /* bool */
	"rank" INT,  /* i32 */
	"node" jsonb  /* Option < pgrx :: JsonB > */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'find_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/components.rs:174
-- graph::sql_facade::components::components
CREATE  FUNCTION graph."components"(
	"max_rows" INT DEFAULT 100, /* i32 */
	"row_offset" INT DEFAULT 0 /* i32 */
) RETURNS TABLE (
	"component_id" bigint,  /* i64 */
	"component_size" bigint,  /* i64 */
	"rank" INT  /* i32 */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'components_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3837
-- graph::sql_facade::admin::remove_edge
CREATE  FUNCTION graph."remove_edge"(
	"graph_name" TEXT, /* & str */
	"label" TEXT, /* & str */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS void

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'remove_edge_for_named_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:6017
-- graph::sql_facade::admin::remove_job
CREATE  FUNCTION graph."remove_job"(
	"job_id" TEXT /* & str */
) RETURNS TABLE (
	"job_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"policy_kind" TEXT,  /* String */
	"removed" bool  /* bool */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'remove_job_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/runtime.rs:228
-- graph::sql_facade::runtime::loaded_graphs
CREATE  FUNCTION graph."loaded_graphs"() RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"residency" TEXT,  /* String */
	"node_count" bigint,  /* i64 */
	"edge_count" bigint,  /* i64 */
	"memory_used_mb" double precision,  /* f64 */
	"projection_mode" TEXT,  /* String */
	"last_access_unix_micros" bigint  /* i64 */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'loaded_graphs_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/search.rs:10
-- graph::sql_facade::search::search
CREATE  FUNCTION graph."search"(
	"property_key" TEXT, /* & str */
	"property_value" TEXT, /* & str */
	"table_filter" oid DEFAULT NULL, /* Option < pgrx :: pg_sys :: Oid > */
	"mode" TEXT DEFAULT 'contains', /* & str */
	"case_sensitive" bool DEFAULT false, /* bool */
	"max_rows" INT DEFAULT 100, /* i32 */
	"row_offset" INT DEFAULT 0, /* i32 */
	"tenant" TEXT DEFAULT NULL, /* Option < String > */
	"hydrate" bool DEFAULT true /* bool */
) RETURNS TABLE (
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT,  /* String */
	"match_type" TEXT,  /* String */
	"score" real,  /* f32 */
	"verified" bool,  /* bool */
	"node" jsonb,  /* Option < pgrx :: JsonB > */
	"node_table_name" TEXT  /* String */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/traversal.rs:869
-- graph::sql_facade::traversal::weighted_shortest_path
CREATE  FUNCTION graph."weighted_shortest_path"(
	"source_table" oid, /* pgrx :: pg_sys :: Oid */
	"source_id" TEXT, /* & str */
	"target_table" oid, /* pgrx :: pg_sys :: Oid */
	"target_id" TEXT /* & str */
) RETURNS TABLE (
	"step" INT,  /* i32 */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_table_name" TEXT,  /* String */
	"node_id" TEXT,  /* String */
	"edge_label" TEXT,  /* Option < String > */
	"edge_weight" bigint,  /* Option < i64 > */
	"step_cost" bigint,  /* i64 */
	"total_cost" bigint  /* i64 */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'weighted_shortest_path_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:6060
-- graph::sql_facade::admin::ingest_projection
CREATE  FUNCTION graph."ingest_projection"(
	"max_rows" bigint DEFAULT NULL, /* Option < i64 > */
	"max_bytes" bigint DEFAULT NULL /* Option < i64 > */
) RETURNS TABLE (
	"rows_ingested" bigint,  /* i64 */
	"segments_published" bigint,  /* i64 */
	"sync_watermark" bigint  /* i64 */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'ingest_projection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3669
-- graph::sql_facade::admin::lte
CREATE  FUNCTION graph."lte"(
	"column_name" TEXT, /* & str */
	"value" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'lte_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/components.rs:105
-- graph::sql_facade::components::component_stats
CREATE  FUNCTION graph."component_stats"() RETURNS TABLE (
	"num_components" INT,  /* i32 */
	"largest_component" INT,  /* i32 */
	"num_isolated_nodes" INT,  /* i32 */
	"total_active_nodes" INT  /* i32 */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'component_stats_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:4441
-- graph::sql_facade::admin::estimate
CREATE  FUNCTION graph."estimate"() RETURNS TABLE (
	"estimated_nodes" bigint,  /* i64 */
	"estimated_edges" bigint,  /* i64 */
	"estimated_memory_mb" double precision,  /* f64 */
	"memory_limit_mb" INT,  /* i32 */
	"fits_in_memory" bool  /* bool */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'estimate_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3565
-- graph::sql_facade::admin::not_in
CREATE  FUNCTION graph."not_in"(
	"column_name" TEXT, /* & str */
	"values" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'not_in_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:309
-- graph::sql_facade::admin::create_graph
CREATE  FUNCTION graph."create_graph"(
	"graph_name" TEXT, /* & str */
	"tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"namespace" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_kind" TEXT DEFAULT 'user', /* & str */
	"residency" TEXT DEFAULT 'hot', /* & str */
	"materialization" TEXT DEFAULT 'shared', /* & str */
	"projection_mode" TEXT DEFAULT 'csr_readonly' /* & str */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"owner_role" oid,  /* pgrx :: pg_sys :: Oid */
	"created_by" oid,  /* pgrx :: pg_sys :: Oid */
	"tenant" TEXT,  /* Option < String > */
	"namespace" TEXT,  /* Option < String > */
	"graph_kind" TEXT,  /* String */
	"residency" TEXT,  /* String */
	"materialization" TEXT,  /* String */
	"projection_mode" TEXT,  /* String */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'create_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3646
-- graph::sql_facade::admin::less_than
CREATE  FUNCTION graph."less_than"(
	"column_name" TEXT, /* & str */
	"value" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'less_than_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:5847
-- graph::sql_facade::admin::run_due_jobs
CREATE  FUNCTION graph."run_due_jobs"(
	"max_jobs" INT DEFAULT 64 /* i32 */
) RETURNS TABLE (
	"job_id" TEXT,  /* String */
	"run_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"policy_kind" TEXT,  /* String */
	"status" TEXT,  /* String */
	"rows_applied" bigint,  /* Option < i64 > */
	"error" TEXT,  /* Option < String > */
	"started_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"finished_at" timestamp with time zone  /* Option < TimestampWithTimeZone > */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'run_due_jobs_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:667
-- graph::sql_facade::admin::set_graph_residency
CREATE  FUNCTION graph."set_graph_residency"(
	"graph_name" TEXT, /* & str */
	"residency" TEXT, /* & str */
	"tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"owner_role" oid,  /* pgrx :: pg_sys :: Oid */
	"created_by" oid,  /* pgrx :: pg_sys :: Oid */
	"tenant" TEXT,  /* Option < String > */
	"namespace" TEXT,  /* Option < String > */
	"graph_kind" TEXT,  /* String */
	"residency" TEXT,  /* String */
	"materialization" TEXT,  /* String */
	"projection_mode" TEXT,  /* String */
	"created_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"updated_at" timestamp with time zone  /* TimestampWithTimeZone */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'set_graph_residency_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:2187
-- graph::sql_facade::admin::build
CREATE  FUNCTION graph."build"() RETURNS TABLE (
	"nodes_loaded" bigint,  /* i64 */
	"edges_loaded" bigint,  /* i64 */
	"build_time_ms" double precision,  /* f64 */
	"memory_used_mb" double precision,  /* f64 */
	"sync_mode" TEXT,  /* String */
	"projection_mode" TEXT  /* String */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'build_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3528
-- graph::sql_facade::admin::eq
CREATE  FUNCTION graph."eq"(
	"column_name" TEXT, /* & str */
	"value" bigint /* i64 */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'eq_i64_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3635
-- graph::sql_facade::admin::gte
CREATE  FUNCTION graph."gte"(
	"column_name" TEXT, /* & str */
	"value" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'gte_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/workflow.rs:437
-- graph::sql_facade::workflow::path
CREATE  FUNCTION graph."path"(
	"source_table" oid, /* pgrx :: pg_sys :: Oid */
	"source_id" TEXT, /* & str */
	"target_table" oid, /* pgrx :: pg_sys :: Oid */
	"target_id" TEXT, /* & str */
	"max_depth" INT DEFAULT 20 /* i32 */
) RETURNS TABLE (
	"step" INT,  /* i32 */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_table_name" TEXT,  /* String */
	"node_id" TEXT,  /* String */
	"edge_label" TEXT,  /* Option < String > */
	"readable_path" TEXT,  /* String */
	"node" jsonb  /* Option < pgrx :: JsonB > */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'path_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3553
-- graph::sql_facade::admin::neq
CREATE  FUNCTION graph."neq"(
	"column_name" TEXT, /* & str */
	"value" bigint /* i64 */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'neq_i64_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3761
-- graph::sql_facade::admin::remove_table_from_graph
CREATE  FUNCTION graph."remove_table_from_graph"(
	"graph_name" TEXT, /* & str */
	"table_name" oid, /* pgrx :: pg_sys :: Oid */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS void

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'remove_table_from_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3618
-- graph::sql_facade::admin::gt
CREATE  FUNCTION graph."gt"(
	"column_name" TEXT, /* & str */
	"value" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'gt_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3581
-- graph::sql_facade::admin::prefix_text
CREATE  FUNCTION graph."prefix_text"(
	"column_name" TEXT, /* & str */
	"value" TEXT /* & str */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'prefix_text_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/discovery.rs:111
-- graph::sql_facade::discovery::preview_discover_tables
CREATE  FUNCTION graph."preview_discover_tables"(
	"tables" oid[], /* Vec < pgrx :: pg_sys :: Oid > */
	"tenant_column" TEXT DEFAULT NULL, /* Option < String > */
	"graph_name" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"item_type" TEXT,  /* String */
	"item_name" TEXT,  /* String */
	"details" TEXT  /* String */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'preview_discover_tables_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/components.rs:301
-- graph::sql_facade::components::component
CREATE  FUNCTION graph."component"(
	"component_id" bigint, /* i64 */
	"max_rows" INT DEFAULT 100, /* i32 */
	"row_offset" INT DEFAULT 0, /* i32 */
	"hydrate" bool DEFAULT true /* bool */
) RETURNS TABLE (
	"component_id" bigint,  /* i64 */
	"node_table" oid,  /* pgrx :: pg_sys :: Oid */
	"node_id" TEXT,  /* String */
	"node" jsonb  /* Option < pgrx :: JsonB > */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'component_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/runtime.rs:88
-- graph::sql_facade::runtime::select_graph
CREATE  FUNCTION graph."select_graph"(
	"graph_name" TEXT, /* & str */
	"tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"loaded" bool  /* bool */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'select_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:5473
-- graph::sql_facade::admin::drop_sync_policy
CREATE  FUNCTION graph."drop_sync_policy"(
	"policy_id" TEXT /* & str */
) RETURNS TABLE (
	"policy_id" TEXT,  /* String */
	"job_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"dropped" bool  /* bool */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'drop_sync_policy_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:1426
-- graph::sql_facade::admin::build_resource_status
CREATE  FUNCTION graph."build_resource_status"() RETURNS TABLE (
	"budget_bytes" bigint,  /* i64 */
	"peak_bytes" bigint,  /* i64 */
	"peak_phase" TEXT,  /* Option < String > */
	"pressure_events" bigint  /* i64 */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'build_resource_status_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/traversal.rs:1449
-- graph::sql_facade::traversal::aggregate
CREATE  FUNCTION graph."aggregate"(
	"traversal" jsonb, /* pgrx :: JsonB */
	"aggregations" jsonb, /* pgrx :: JsonB */
	"scope" TEXT DEFAULT 'returned_nodes', /* & str */
	"path_limit" INT DEFAULT COALESCE(NULLIF(current_setting('graph.max_exact_path_count', true), '')::int, 100000) /* i32 */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'aggregate_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3663
-- graph::sql_facade::admin::at_most
CREATE  FUNCTION graph."at_most"(
	"column_name" TEXT, /* & str */
	"value" jsonb /* pgrx :: JsonB */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'at_most_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:3597
-- graph::sql_facade::admin::is_not_null
CREATE  FUNCTION graph."is_not_null"(
	"column_name" TEXT /* & str */
) RETURNS jsonb /* pgrx :: JsonB */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'is_not_null_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:1581
-- graph::sql_facade::admin::projection_compact
CREATE  FUNCTION graph."projection_compact"(
	"max_rows" INT DEFAULT 10000, /* i32 */
	"max_bytes" bigint DEFAULT NULL, /* Option < i64 > */
	"max_segments" INT DEFAULT 1000, /* i32 */
	"dirty_chunk_segment_threshold" INT DEFAULT NULL /* Option < i32 > */
) RETURNS TABLE (
	"manifest_generation" bigint,  /* i64 */
	"segments_compacted" INT,  /* i32 */
	"chunks_rewritten" INT,  /* i32 */
	"segment_count" INT,  /* i32 */
	"dirty_chunk_count" INT,  /* i32 */
	"sync_watermark" bigint  /* i64 */
)

LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'projection_compact_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/runtime.rs:191
-- graph::sql_facade::runtime::unload_graph
CREATE  FUNCTION graph."unload_graph"(
	"graph_name" TEXT, /* & str */
	"tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"unloaded" bool  /* bool */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'unload_graph_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:5518
-- graph::sql_facade::admin::run_sync_policy
CREATE  FUNCTION graph."run_sync_policy"(
	"policy_id" TEXT /* & str */
) RETURNS TABLE (
	"policy_id" TEXT,  /* String */
	"job_id" TEXT,  /* String */
	"run_id" TEXT,  /* String */
	"graph_id" TEXT,  /* String */
	"graph_name" TEXT,  /* String */
	"status" TEXT,  /* String */
	"rows_applied" bigint,  /* Option < i64 > */
	"error" TEXT,  /* Option < String > */
	"started_at" timestamp with time zone,  /* TimestampWithTimeZone */
	"finished_at" timestamp with time zone  /* Option < TimestampWithTimeZone > */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'run_sync_policy_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- src/sql_facade/admin.rs:6121
-- graph::sql_facade::admin::vacuum_graph
CREATE  FUNCTION graph."vacuum_graph"(
	"graph_name" TEXT, /* & str */
	"graph_tenant" TEXT DEFAULT NULL, /* Option < & str > */
	"graph_namespace" TEXT DEFAULT NULL /* Option < & str > */
) RETURNS TABLE (
	"nodes_before" bigint,  /* i64 */
	"nodes_after" bigint,  /* i64 */
	"tombstones_removed" bigint,  /* i64 */
	"edges_rebuilt" bigint,  /* i64 */
	"vacuum_time_ms" double precision  /* f64 */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pg_temp
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vacuum_graph_wrapper';
/* </end connected objects> */
