Filesystem storage operations for entity mirror/export system.
Stores exported JSON files in the parent app's priv/entities/ directory. Each entity is stored as a single file containing both the definition and all data records.
Directory Structure
priv/entities/
brand.json # Contains definition + all data records
product.json # Contains definition + all data recordsFile Format
{
"export_version": "1.0",
"exported_at": "2025-12-11T10:30:00Z",
"definition": { ... entity schema ... },
"data": [ ... array of data records ... ]
}Configuration
The export path can be configured via settings:
entities_mirror_path- Custom path (empty = use default priv/entities/)
Summary
Functions
Checks if entity data mirroring is enabled.
Returns the default storage path in the parent app's priv directory.
Checks if entity definitions mirroring is enabled.
Deletes an entity file.
Disables entity data mirroring.
Disables entity definitions mirroring.
Enables entity data mirroring.
Enables entity definitions mirroring.
Ensures the root directory exists.
Checks if a file exists for the given entity.
Returns the file path for a specific entity.
Returns statistics about exported files.
Lists all exported entity names.
Reads an entity file containing definition and data.
Returns the root path for entity mirror storage.
Writes an entity file containing definition and optionally data.
Functions
@spec data_enabled?() :: boolean()
Checks if entity data mirroring is enabled.
@spec default_path() :: String.t()
Returns the default storage path in the parent app's priv directory.
@spec definitions_enabled?() :: boolean()
Checks if entity definitions mirroring is enabled.
Deletes an entity file.
Disables entity data mirroring.
Disables entity definitions mirroring.
Enables entity data mirroring.
Enables entity definitions mirroring.
@spec ensure_directory() :: :ok | {:error, term()}
Ensures the root directory exists.
Checks if a file exists for the given entity.
Returns the file path for a specific entity.
@spec get_stats() :: map()
Returns statistics about exported files.
Returns
Map with:
definitions_count- Number of exported entity filesdata_count- Total number of data records across all entitiesentities_with_data- List of entity names that have data recordslast_export- Timestamp of most recent export (nil if no files)
@spec list_entities() :: [String.t()]
Lists all exported entity names.
Returns a list of entity names (without .json extension).
Reads an entity file containing definition and data.
Parameters
entity_name- The entity name
Returns
{:ok, map}with decoded JSON on success{:error, reason}on failure
@spec root_path() :: String.t()
Returns the root path for entity mirror storage.
Uses custom path from settings if configured, otherwise defaults to the parent app's priv/entities/ directory.
Writes an entity file containing definition and optionally data.
Parameters
entity_name- The entity name (used as filename)content- The full content map with definition and data
Returns
{:ok, file_path}on success{:error, reason}on failure