ข้ามไปยังเนื้อหาหลัก

การเตรียมข้อมูล

หากคุณกำลังปรับใช้ Casdoor ร่วมกับบริการอื่นๆ เป็นแอปพลิเคชันที่สมบูรณ์ คุณอาจต้องการให้คุณสมบัติ พร้อมใช้งานทันที สำหรับผู้ใช้. นั่นหมายความว่าผู้ใช้สามารถใช้แอปพลิเคชันได้โดยไม่ต้องมีการตั้งค่าใดๆ

ในสถานการณ์เช่นนี้ คุณสามารถใช้การเตรียมข้อมูลเพื่อลงทะเบียนบริการของคุณใน Casdoor ผ่านไฟล์การตั้งค่า ไฟล์นี้สามารถกำหนดไว้ล่วงหน้าหรือสร้างขึ้นโดยบริการของคุณเอง

ที่นี่เราให้บทเรียนสำหรับการนำเข้าหรือส่งออกข้อมูลการตั้งค่า

นำเข้าข้อมูลการตั้งค่า

By default, if there is a configuration file named init_data.json at the root directory of Casdoor, it will be used to initialize data in Casdoor. You can also specify a custom path for the initialization file by setting the initDataFile parameter in conf/app.conf:

initDataFile = /path/to/your/init_data.json

If no custom path is specified, Casdoor will look for init_data.json in the root directory where Casdoor runs.

หากคุณกำลังใช้ Docker image อย่างเป็นทางการของ Casdoor นี่คือสคริปต์บางส่วนที่สามารถช่วยคุณติดตั้ง init_data.json เข้ากับคอนเทนเนอร์

แม่แบบสำหรับ init_data.json มีให้ที่: init_data.json.template เปลี่ยนชื่อเป็น init_data.json ก่อนใช้งาน

สำหรับ Docker

หากคุณปรับใช้ Casdoor ด้วย Docker คุณสามารถใช้คำสั่ง volume เพื่อติดตั้ง init_data.json เข้ากับคอนเทนเนอร์

docker run ... -v /path/to/init_data.json:/init_data.json

สำหรับ Kubernetes

หากคุณปรับใช้ Casdoor ด้วย Kubernetes คุณสามารถใช้ configmap เพื่อเก็บ init_data.json

apiVersion: v1
kind: ConfigMap
metadata:
name: casdoor-init-data
data:
init_data.json:

คุณสามารถติดตั้งข้อมูลเข้ากับ Casdoor pods โดยการติดตั้ง configmap. คุณสามารถแก้ไข deployment ของคุณตามนี้:

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

ส่งออกข้อมูลการตั้งค่า

You can export all Casdoor configuration data to a file for backup or migration purposes. There are two methods available:

If you're running Casdoor from a binary, use the -export flag to dump the database to a JSON file:

# Export to default location (init_data_dump.json)
./casdoor -export

# Export to a custom path
./casdoor -export -exportPath /path/to/backup.json

The export runs after database initialization but before the server starts, then exits automatically. This method works with any deployment method (binary, Docker, Kubernetes) and doesn't require Go toolchain or source code access.

Using Go Test

If you have access to the source code, you can use the test method:

go test ./object -v -run TestDumpToFile

This will generate init_data_dump.json in the same directory.

Migrating Data

After exporting, rename init_data_dump.json to init_data.json and place it in the root directory of your target Casdoor installation. On startup, Casdoor will automatically import the data.

อ้างอิง

วัตถุ Casdoor ทั้งหมดที่รองรับโดยการเตรียมข้อมูลมีดังต่อไปนี้:

วัตถุGo Structเอกสารประกอบ
องค์กรstructdoc
แอปพลิเคชันstructdoc
ผู้ใช้structdoc
ใบรับรองstructdoc
ผู้ให้บริการstructdoc
ldapsstructเอกสาร
โมเดลstruct
สิทธิ์structdoc
การชำระเงินstructเอกสาร
สินค้าstructเอกสาร
ทรัพยากรstructเอกสาร
บทบาทstructเอกสาร
ตัวประสานข้อมูลstructเอกสาร
โทเค็นstructเอกสาร
เว็บฮุคstructเอกสาร
กลุ่มstructเอกสาร
อะแดปเตอร์structเอกสาร
บังคับใช้struct
แผนstructdoc
การกำหนดราคาstructเอกสาร
คำเชิญstructเอกสาร
บันทึกstruct
เซสชันstruct
การสมัครสมาชิกstructdoc
ธุรกรรมstruct

หากคุณยังรู้สึกสับสนเกี่ยวกับการกรอกแบบฟอร์มนี้ คุณสามารถเรียกใช้ RESTful API หรือใช้โหมดดีบักของเบราว์เซอร์เพื่อดูการตอบสนองของ GetXXX ต่อวัตถุเหล่านี้ การตอบสนองอยู่ในรูปแบบเดียวกับ init_data.json