Skip to content

API Reference parrot_formdesigner.services.fieldsync_schema

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.services.fieldsync_schema

View source

DDL canónico para el schema fieldsync — idempotente, sin migraciones.

El schema fieldsync es el system of record de FEAT-302:

  • fieldsync.projects — proyectos internos (contienen accounting_code = cost center propio; UNIQUE por (client_id, accounting_code)).
  • fieldsync.workday_cost_center_mappings — mapeo de salida hacia Workday; un proyecto → un código Workday (UNIQUE por project_id).
  • fieldsync.auth_policies — policies ABAC/PBAC persistidas como JSONB; compatibles con el formato YAML del engine de nav-auth.

Diseño:

  • NUNCA se lee ni escribe directamente sobre networkninja.projects. El seed inicial (scripts/seed_fieldsync_projects.py) lee de allí solo para poblar fieldsync.projects; después este schema es autónomo.
  • DDL 100% idempotente: CREATE SCHEMA IF NOT EXISTS + CREATE TABLE IF NOT EXISTS; segunda ejecución no falla.
  • Sin framework de migraciones; columnas añadidas en futuras tasks con ALTER TABLE idempotente o un script de migración explícito.

Uso::

pool = await asyncpg.create_pool(dsn=...)
schema_mgr = FieldsyncSchemaManager(pool)
await schema_mgr.initialize()  # crea schema + 3 tablas si no existen

Class FieldsyncSchemaManager

Apply the canonical fieldsync DDL to a Postgres database.

All DDL statements are idempotent — executing initialize() twice on the same database is safe and produces no side effects.

This class never opens a connection itself; it receives an existing asyncpg pool (or a compatible fake pool for unit tests).

Example::

pool = await asyncpg.create_pool(dsn=DB_DSN)
mgr = FieldsyncSchemaManager(pool)
await mgr.initialize()
Parameter Type Default Description
pool Any asyncpg connection pool (or fake with the same acquire() async context manager interface).

Method FieldsyncSchemaManager.initialize

Run all DDL statements in order, creating schema + 3 tables.

Idempotent: safe to call on startup even if the objects already exist.

initialize() -> None

Raises:

  • Exception — Any asyncpg error propagates as-is (e.g. permission denied, connection error).

Method FieldsyncSchemaManager.ddl_statements

Return the ordered list of DDL SQL strings (read-only copy).

ddl_statements() -> list[str]

Returns: list[str] — List of SQL strings in execution order.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally