Data initialization
When shipping Casdoor as part of a larger product, preload organizations, applications, users, and other data so users get a working setup without manual configuration. Data initialization uses a JSON file that you provide or generate.
This page describes how to import and export configuration data.
Import
By default, Casdoor looks for init_data.json in the project root at startup and loads it if present. To use a different path, set initDataFile in conf/app.conf:
initDataFile = /path/to/your/init_data.json
A template is available at init_data.json.template. Copy and rename it to init_data.json and customize as needed.
Docker
Mount the file into the container with a volume:
docker run ... -v /path/to/init_data.json:/init_data.json
Kubernetes
Store the file in a ConfigMap and mount it into the Casdoor pod:
apiVersion: v1
kind: ConfigMap
metadata:
name: casdoor-init-data
data:
init_data.json:
Mount the ConfigMap in your Deployment, for example:
apiVersion: apps/v1
kind: Deployment
...
spec:
template:
...
spec:
containers:
...
volumeMounts:
- mountPath: /init_data.json
name: casdoor-init-data-volume
subPath: init_data.json
volumes:
- configMap:
name: casdoor-init-data
name: casdoor-init-data-volume
Export
Export all Casdoor config data to a JSON file for backup or migration.
Using the binary (recommended)
Run Casdoor with the -export flag to dump the database to JSON:
# Export to default location (init_data_dump.json)
./casdoor -export
# Export to a custom path
./casdoor -export -exportPath /path/to/backup.json
Export runs after DB init and then the process exits. It works with binary, Docker, or Kubernetes and does not require the Go toolchain.
Using Go test (from source)
From the Casdoor source tree:
go test ./object -v -run TestDumpToFile
This creates init_data_dump.json in that directory.
Migrating to another instance
Rename init_data_dump.json to init_data.json, put it in the root of the target Casdoor instance, and start Casdoor; the data will be loaded automatically.
Supported objects
The following object types can be included in the init file:
| Objeto | Estructura de Go | Documentación |
|---|---|---|
| organizaciones | struct | doc |
| aplicaciones | struct | doc |
| usuarios | struct | doc |
| certificados | struct | doc |
| proveedores | struct | doc |
| ldaps | struct | doc |
| modelos | estructura | |
| permisos | struct | doc |
| pagos | struct | doc |
| productos | estructura | doc |
| recursos | estructura | doc |
| roles | estructura | doc |
| sincronizadores | estructura | doc |
| tokens | estructura | doc |
| webhooks | estructura | doc |
| grupos | estructura | doc |
| adaptadores | estructura | doc |
| aplicadores | estructura | |
| planes | struct | doc |
| precios | struct | doc |
| invitaciones | estructura | doc |
| registros | estructura | |
| sesiones | estructura | |
| suscripciones | struct | doc |
| transacciones | estructura |
For the exact JSON shape, call the REST API or inspect GetXXX responses in the browser; they match the structure expected in init_data.json.