数据库
数据库同步器
The users table we created as a demo is imported from the template XLSX file.
To create a new syncer, go to the Syncers tab and fill in all the required information as shown below. Then, save the changes.
In general, you need to fill in at least the ID
and Name
in the Casdoor columns. Other important fields include createdTime
, Password
, and DisplayName
.
The following fields are required:
Organization
: The organization that the user will be imported toName
: 同步器名称Type
: Select "database"Host
: 原始数据库主机地址Port
: 原始数据库端口User
: 原始数据库用户名Password
: 原始数据库密码Database type
: All Xorm-supported databases such as MySQL, PostgreSQL, SQL Server, Oracle, and SQLiteDatabase
: 原始数据库名称Table
: The original user table name表格列
Column name
: The original user column nameColumn type
: The original user column typeCasdoor Column
: The Casdoor user column name
Optional fields:
Is hashed
: 是否计算哈希值. When this option is enabled, the syncer will only synchronize the user if the field of the user in the origin table is updated. If this option is disabled, the syncer will still synchronize the user even if only the field is updated. In short, the user will not be synchronized until the fields involved in the hash calculation (enabled "Is hashed") are updated.Is key
: Whether it is the primary key of the user in the origin table and the user in the Casdoor table. When synchronizing the database, it is determined based on the field whose "Is key" option is selected. At least one of the "Is key" buttons for fields should be selected. If none are selected, the first "Is key" option is selected by default.Avatar base URL
: When syncing users, if the Avatar base URL is not empty and the origin user.avatar does not have the prefix "http", the new user.avatar will be replaced by Avatar base URL + user.avatar.Affiliation table
: It is used to sync the affiliation of the user from this table in the database. Since the affiliation may be a code of type int in the "Affiliation table", it needs to be mapped to a string. Refer to getAffiliationMap(). Casdoor has some redundant fields to borrow, so here we usescore
to map the int code to a string name.
Once you have configured the syncer, enable the Is enable option and save. The syncer will start working.
You can also use the "Sync" button for database synchronization.
Update
When the Table columns
are set as shown in the following figure, the update operation is performed.
If the data in the two tables is different for the key, you can synchronize the data between the two tables based on the primary key.
- Update user in the original table
- Update user in the Casdoor table
Add
When the Table columns
are set as shown in the following figure, the add operation is performed.
If the number of data between the two tables is different, add the data to the table with the lower number of data based on the primary key.
- Add user in the original table
- Add user in the Casdoor table