Those table structure design ideas you don't know-the birth of open source software 9

The Design of ERP Table Structure-Part 9

Log the birth of "open source software"

Chilong ERP open source address:

Light up the star, thank you for your support, and communicate with the developer kzca2000

Code Cloud: https://gitee.com/redragon/redragon-erp

GitHub:https://github.com/redragon1985/redragon-erp

Redragon ERP official website: https://www.redragon-erp.com

Those table structure design ideas you don't know

 

Preface

The last article talked about the ERP system design. The database structure was just a brief introduction. Today I will focus on what special designs I have made in the table structure of [Chilong ERP] and why.

ID and code

I have added two default fields in every table almost without exception, namely ID and Code. These two fields seem to be unique fields that can identify data, but why design two? Of course they have their own uses.

(1) ID is the primary key of a table, which is generally self-increasing. It is mainly used for sorting, positioning, and querying. Because it is a number, it is clearer and faster.

(2) Code is the only key, and the type is mostly characters. It can be generated by UUID or snowflake algorithm. Of course, in the case of a specific business scenario, it can be input by the user or generated logically. In addition to having strong semantics, it is also preferred for foreign key associations.

Here is a special explanation: why use Code as a foreign key, and ID can also be used as a foreign key. Foreign keys must have two biggest characteristics: unique and immutable. Since ID is mostly self-incremented or generated by the characteristics of the database, it cannot be guaranteed to be absolutely unchanged during data migration. So using Code is safer and more reliable.

organization

This field is named: org_code, which means organization. So what is an organization? Simply put, it is an independent company or entity. The function is mainly used for data isolation. Since there is no need to create different data tables for different companies, a field is used to isolate the data of different companies. A bit like the concept of a financial set of accounts.

Operation record

Four fields will be added to each table to record who did the data operation at what time. They are:

(1) CREATED_DATE (created time)

(2) LAST_UPDATED_DATE (last modification time)

(3) CREATED_BY (creator)

(4) LAST_UPDATED_BY (last modified person)

The creator and creation time are set when the data is added; the last modification person and the last modification time are set when the data is updated

data permission

Information systems all need the control of data permissions, that is, who can manipulate which data. In general enterprise-level informatization, the logic of data permissions is controlled at the level of organizational structure. Generally include: operating your own data, sharing data in different levels of departments, and sharing data across the company.

In order to solve the above-mentioned data access control needs, a field DEPARTMENT_CODE (department code) is added. This field will only record the department of the person who created the current data, that is, the department of this data. The code level combined with data permissions can realize the control of data permissions.

Version and log table

Add VERSION (version number) to the table that needs to record the data version. A common business scenario is "change function". Here is an example, such as: purchase order changes. When we create a purchase order, and after the approval is passed, the data cannot be modified by nature, but when it needs to be modified, we need to use the purchase order change function. When the order changes, all that needs to be done is the version number +1 and historical data is generated in the log table.

Custom field

The role of custom fields is to allow users to add a table field and save data according to their business needs. The approach is to add attribute fields to a table. In most cases, multiple attribute fields are reserved, with field names attribute1, attribute2, attribute3 and so on. Then use the configurable function to set the corresponding relationship between the attribute field and the field Chinese name.

 

I hope you can help the author enter [Code Cloud] or [GitHub] to search for "Chilong ERP" and click on the star after reading this article. Waiting for your support!


Guess you like

Origin blog.51cto.com/14933131/2539785