Skip to content

Entities settings: switch the system, sync to files, export and import

Describes Entities 0.7.0.

The Entities settings page turns the whole Entities system on or off and keeps entity definitions and records in JSON files on the server, so they can be backed up, put under version control, or copied to another site.

Where to find it

Open Settings in the admin sidebar and choose Entities, or go to /admin/settings/entities.

You need the Change Entities settings permission, which sits under Entities in the roles’ permissions. Without it you’re sent back to the Entities list with You do not have permission to change Entities settings. When this permission was introduced, every role that already had the Entities permission received it once, automatically; a role given Entities later doesn’t get it unless you grant it.

Entities settings: system status with quick stats, and Mirror & Export with definitions, records, Export All and Import Entities settings: system status with quick stats, and Mirror & Export with definitions, records, Export All and Import

Entities settings: on/off, export and import.

System status

Entities System shows a Disable System or Enable System button. Disabling asks for confirmation first, because it makes all entities and their data inaccessible: the Entities admin pages are refused while it’s off. To switch it back on after leaving this page, use the Modules page.

Quick Stats counts Entities, Data Records, Published and Drafts.

Keeping entities in files

The Mirror & Export card writes one JSON file per entity into the folder shown as Export Path. The file holds the entity’s definition and, if records sync is on for it, its records.

The table lists each entity with its record count, a mark when its file already exists, and two Live Sync switches:

  • Definition: whenever the entity’s definition is saved, its file is rewritten. Turning it on writes the file straight away.
  • Records: whenever one of its records is created or changed, the file is rewritten with the records included. It can only be turned on once Definition is on (Enable definition sync first), and turning Definition off turns Records off too.

Export now on a row writes that entity’s file at once, with records if Records sync is on for it. The same switches and button appear on the entity’s own edit form, under Backup Settings.

Above the table, Enable All and Disable All do the same for every entity, once for Definitions and once for Records. Enabling records for all also enables definitions for all.

The footer shows Exported Files (how many definitions and records are in the folder) and Last Export (or Never).

Export All

Export All rewrites the file of every entity, whether or not its sync is on, and reports Export complete. … definitions, … records. In this version it writes definitions only, without records, unless a site-wide setting is on that this page doesn’t change. It also runs when you click either Enable All. Use a row’s Export now to write an entity’s file with its records.

Importing

Import reads the files in the export folder and opens Import Entities, a preview of what would change.

At the top, Definitions and Data Records count how many are new, identical or changed. Below, there’s a tab per entity. In each:

  • The Definition is marked NEW, IDENTICAL, CHANGED or ERROR, with the choice Skip, Import/Overwrite or Merge.
  • Data Records lists each record’s status, slug and title, with Skip, Import or Merge. Skip All and Import All set every record of that entity at once.

New items start set to import; identical and changed ones start set to skip, so nothing existing is overwritten unless you choose it. Overwrite replaces what’s in the database with the file’s version; Merge keeps the existing values where the file has none.

Import This Entity imports only the open tab; Import All Entities imports every tab. Cancel closes without importing. Afterwards a message counts what was created, updated and skipped, and names the first error if there were any. If a relation field pointed at a record that couldn’t be found, a warning lists those records; they’re imported without that link.

For developers

The export folder is the entities_mirror_path setting, defaulting to the host app’s priv/entities/; the page shows it but can’t change it. The same export and import run from the command line with mix phoenix_kit_entities.export and mix phoenix_kit_entities.import.

What it doesn’t do

  • Import doesn’t take an uploaded file: the files have to be in the export folder on the server already.
  • Nothing here deletes an entity or its records from the database.
  • There’s no schedule; files are written on save (with sync on) or when you export.