# openDB

Database design is the foundation of the digital economy and an important soft infrastructure.

openDB is a set of open data table design specifications, including schema definitions such as table names, fields, and initial data.

Taking the user table as an example, it stipulates the table name and field definition of a standard user table, and based on the characteristics of nosql, the fields can be extended by developers themselves.

openDB is an important soft infrastructure of uniCloud, supporting the development of the uniCloud digital ecosystem.

# Requirements background

  • In traditional development, database design is the work of back-end engineers such as php/java; however, most front-end engineers are not familiar with database design. When using uniCloud to develop projects, many front-end engineers hope to have mature database templates. avoid detours
  • Conducive to industrial division of labor. Business development, statistical analysis, intelligent recommendation, data conversion, etc. are all different professional roles. Most developers are only good at business development and need professional data service providers to provide services for them. If the database standards are unified, each role can be used in the plug-in. The marketplaces each offer plugins.
    • For example, there are professional data service providers that provide "guess what you like" plug-ins based on e-commerce specifications in openDB, which can be easily introduced into developers' applications;
    • For example, there are professional data import and export plug-ins, which can easily migrate historical data from ecshop and other systems;
    • For example, there are professional cms background manufacturers, based on the news specification in openDB, to provide better news editing tools.
  • A unified database standard is helpful for developers to switch plug-ins according to their preferences. It is conducive to the prosperity of the plug-in ecology, and finally feeds back the plug-in authors by attracting more users to make a bigger cake.
    • For example, there are multiple news application templates, all based on the news specification in openDB, so developers can easily switch to better plug-ins.
  • Data silos problem. When multiple applications have the same database specification, the cross-application data exchange between them becomes easier. In the future, uniCloud will provide a more convenient cross-application data exchange mechanism.
  • Unified initial data. For example, data such as regional tables, there is initialized data in openDB, and developers can share the same data source.

uni-id的账户统一,是openDB的成功实践。基于uni-id规范,有电商插件、有IM插件、有PC管理插件,开发者可以方便的把这些插件整合到自己的同一应用中。

# Existing specifications in openDB

Currently openDB already supports dozens of tables. It can be viewed at https://gitee.com/dcloud/opendb/tree/master/collection.

Some commonly used tables are classified as follows:

  1. User management (uni-id): user-related table definitions, such as roles, permissions, points, tasks, etc.
  2. Log management (opendb-admin): manage common functions in the background, application management, upgrade center, statistical results (new, active, retained, etc.)
  3. Articles & Comments (opendb-news)
  4. E-commerce system (opendb-mall)
  5. News system (opendb-news)

# Preset data

openDB not only supports the definition of commonly used data table fields, but also can preset initialization data.

For example, opendb-city-china is the Chinese city dictionary table defined in opendb, its definition Divided into two parts:

  • collection.json: define the name of the data table, the fields it contains, the type of each field, and the read and write permission rules;
  • data.json: define initialization content

When you create an openDB table through the uniCloud web console, uniCloud will automatically check whether the opendb table definition contains data.json. , data.json is automatically imported after the table definition is created.

If in your HBuilderX project, the data table defined in the uniCloud/database directory contains an opendb table definition, when the Upload DB Schema operation is performed on the opendb table, the uniCloud server will determine whether the opendb table already exists:

  • If the opendb table already exists, only update DB Schema;
  • If the opendb table does not exist, create the table first, and then check whether the opendb table definition contains data.json. If it contains data.json, it will automatically import data.json

# Data table upgrade

The openDB data table may involve changes to schema and preset data in subsequent update iterations. Since HBuilderX 3.5.1, opendb tables support checking for updates.

Take opendb-city-china as an example, when we want to modify or supplement the city, in order to be compatible with the deployed The data table should provide differential data, then what we need to do is:

  • Update the version field in opendb-city-china/package.json to the upgraded version number;
  • Added opendb-city-china/collection.update-original version number-upgrade version number.jql JQL database manager file, the content is JQL statement of differential data;

For example, the revocation or establishment of an administrative area requires data upgrade, and the upgraded version number is defined as 0.0.2, then the difference data needs to be written into the file opendb-city-china/collection.update-0.0 in the form of JQL statements .1-0.0.2.jql, and update the version field of opendb-city-china/package.json.

# How to introduce into your own service space

In the uniCloud web console, when creating a new table, you can directly select all openDB tables.

First select the category, there are several tables under each category, and the table structure and preset data can be previewed directly. Multiple tables are supported to be created together.

The table name of openDB should not be modified. After modification, it cannot be combined with other plugins.

# Welcome to participate

openDB is an evolving specification built by developers. DCloud welcomes professional developers in various business fields to provide specifications.

Developers can add specifications to openDB, or add fields to tables with existing specifications, or add initialization data by submitting PRs. gitee supports lightweight pr, which is especially suitable for co-editing specifications.

  • You will leave your name on the list of contributors to this important project
  • The pr you mentioned becoming the norm will help you enjoy the support of the entire industry chain

Other Notes:

  • For backward compatibility, openDB only adds tables and fields, but does not delete or modify them.

# Precautions

  • opendb provides a relatively comprehensive data table index for developers to use, but too many indexes may cause slow insertion of data or data update. If you confirm that the relevant index does not need to be used, you can delete it yourself