PhoenixKit.Modules.Entities.Mirror.Exporter (phoenix_kit v1.7.38)

Copy Markdown View Source

Exports entities and their data to JSON files.

Each entity is exported as a single file containing:

  • The entity definition (schema)
  • All data records for that entity (when data mirroring is enabled)

File Format

{
  "export_version": "1.0",
  "exported_at": "2025-12-11T10:30:00Z",
  "definition": {
    "name": "brand",
    "display_name": "Brand",
    ...
  },
  "data": [
    {"title": "Acme Corp", "slug": "acme-corp", ...},
    {"title": "Globex", "slug": "globex", ...}
  ]
}

Summary

Functions

Exports all entities with their data (full export).

Exports all data for all entities.

Exports all entities (definitions only, no data).

Exports a single entity with its definition and optionally data.

Exports a single entity data record.

Serializes an entity struct to a map suitable for JSON export.

Serializes an entity data record to a map suitable for JSON export.

Functions

export_all()

@spec export_all() ::
  {:ok, %{definitions: non_neg_integer(), data: non_neg_integer()}}

Exports all entities with their data (full export).

Returns definition count and data record count.

export_all_data()

@spec export_all_data() :: {:ok, [result]}
when result: {:ok, String.t()} | {:error, term()}

Exports all data for all entities.

Re-exports each entity file with its data included.

export_all_entities()

@spec export_all_entities() :: {:ok, [result]}
when result: {:ok, String.t()} | {:error, term()}

Exports all entities (definitions only, no data).

export_entity(entity)

@spec export_entity(struct() | String.t()) ::
  {:ok, String.t(), :with_data | :definition_only} | {:error, term()}

Exports a single entity with its definition and optionally data.

Parameters

  • entity - Entity struct or entity name string

Returns

  • {:ok, file_path} on success
  • {:error, reason} on failure

export_entity_data(entity_data)

@spec export_entity_data(struct()) :: {:ok, String.t()} | {:error, term()}

Exports a single entity data record.

This re-exports the entire entity file with updated data.

serialize_entity(entity)

@spec serialize_entity(struct()) :: map()

Serializes an entity struct to a map suitable for JSON export.

serialize_entity_data(record)

@spec serialize_entity_data(struct()) :: map()

Serializes an entity data record to a map suitable for JSON export.