Create and manage data models

更新时间:
复制 MD 格式

A data model is a collection of data tables that you create and orchestrate in a database. It provides the foundation for application development and enables you to generate Data Definition Language (DDL) statements to create database tables. This topic describes how to create, edit, and delete a data model.

Prerequisites

Create a data model

  1. Log in to BizWorks, in the select Platform drop-down list selected modeling Platform.

  2. Click the a7.pngicon or the text box in the upper-right corner of the page. From the drop-down list, click the name of the project that you want to view and click the Modeling tab. In the Modeling navigation bar, choose Technical Modeling > Bounding Context.

  3. On the Bounding Context page, click the name of the bounding context.

  4. In the target Bounded Context navigation bar, click Data Model. On the Data Model page, click New Data Model.

  5. In the New Data Model panel, enter basic information such as Model Name and Code.

    Note
    • The Code must be a combination of letters and digits, be no more than 80 characters in length, start with an uppercase letter, and be unique within the Bounded Context.

    • The Database Table Name is prefixed with t_ by default.

    The system automatically generates the database table name based on the data model code. The table name is used to generate the DDL script. If you need to modify the generation rules, you can go back to the Data Model page, select More > Table Information Generation Rule Settings, and change the settings in the Set Table Information Generation Rules panel.

  6. Click the Fields tab, and then click Add Field. If you select Normal Field, configure the field parameters as shown in the following figure. The field parameters include: Field Name, Code (a combination of letters and numbers that starts with a lowercase letter), Table Field Name, Field Type (select from the drop-down list), the Required, Unique, and Reserved Field checkboxes, and the Description text area. After you complete the configuration, click Create.

    Table 1. Data model parameters

    Parameter

    Description

    Field name

    A custom name for the field.

    Code

    A combination of letters and digits, up to 80 characters in length, starting with a lowercase letter, and unique in the data model.

    Table Field Name

    The system automatically generates table field names based on the data model code. The table name is used to generate DDL scripts. If you need to modify the generation rule, you can return to the data model list page, click Set Table Information Generation Rule, and change the settings in the Set Table Information Generation Rule panel.

    Field Type

    Text types: Text, LongText. You can specify whether the field is a Primary Key, is Required, or is Unique, and set a Default Value.

    Note

    If a field is set as the Primary Key, Unique and Required are automatically selected.

    Date types: Date, DateTime, and Timestamp. Fields of these types cannot be used as primary keys, and their default value can only be a fixed date. You cannot use relative times such as Today() or functions.

    Note

    Setting a default value does not affect code generation or the DDL statement.

    Integer numeric types: Integer, Long. You can set whether the field is a primary key, is required, or is unique, and specify a default value.

    Decimal number types: Double, Decimal. These types cannot be used as a primary key, and you must specify the Decimal places.

    Boolean: The value can be True or False.

    Reference: After you select this type, you must select an associated table and field. The actual type of this reference field is the same as the type of the associated field. The associated table is a data model that has already been saved in the current version's Bounded Context, and the associated field is a field within the associated table.

    Sequence: An auto-incrementing sequence that defaults to the Long data type. It is required and unique, can be set as the primary key, and requires an initial value.

    You can repeat this step to add multiple fields.

    To delete a field, hover over its card in the field list (for example, order_no) and click the delete icon on the right.

  7. If you select Batch Reservation, follow the configuration steps below.

    1. In the Batch Reserve Fields dialog box, click Add Type (you can add multiple).

    2. In the Field Type drop-down list, select a field type and click OK. The available types include Boolean, Text, LongText, Date, DateTime, Timestamp, Integer, and Long, and you must set the quantity for each type.

      Note

      Create reserved fields if you plan to distribute the data model to other tenants or projects for future extension.

  8. Click Create.

    After the model is created, you can view the model information in the model list or perform actions such as Edit and Delete.

Edit a data model

  1. On the Data Model page, in the Actions column for the target data model, click Edit. In the Edit Data Model panel, modify the parameters.

  2. Optional: Add an index to the data model.

    1. In the Edit Data Model panel, select the Index tab, and click Add Index. Configure the index information: In the Index Name and Code fields, enter an index identifier (for example, indexId), in the Index Columns field, select the fields to include (for example, id and orderline_id), and select Unique Index if needed.

    2. Enter the Index Name and Encoding, select one or more saved fields from the drop-down list as index columns, and then click Save.

Delete a data model

  1. On the Data Model page, click Delete in the Actions column of the target data model.

  2. In the confirmation dialog box, click Delete.

Batch generate application services

  1. In the navigation bar of the target Bounded Context, click Data Model.

  2. On the Data Model page, click Generate Application Service.

  3. In the Batch Generate Related Models panel, you can select Full Generation or Partial Generation.

    • Generate All

      1. In the Batch Generate Related Models panel, select Full Generation, and click Next.

      2. In the Generation Settings panel, in the Other Settings section, select the Duplicate Data Detection Rule and Duplicate Data Handling Policy, and click Start Generation.

        Table 2. Generation settings parameters

        Setting type

        Parameter

        Description

        Duplicate Data Detection Rules

        Duplicate Object Code

        • When generating a DTO, the system checks only if the model's code is a duplicate, without comparing its field codes.

        • When generating an application service, the system only checks if the service code exists and does not check the service's fields.

        Duplicate field code

        • When generating a DTO, if the model's code is a duplicate, the system also checks if the model's field codes are duplicates.

        • When generating an application service, the system only checks if the service code exists and does not check the service's fields.

        Duplicate Data Processing Policy

        Skip Duplicate Data

        • When generating a DTO, if its code already exists, the system does not modify the DTO's name, code, or fields.

        • When generating an application service, if its code already exists, the system does not modify the service information. The system then checks for duplicate methods. If a method's code is also a duplicate, the system does not check its parameters and does not regenerate the method.

        Overwrite Existing Data

        The system overwrites existing data (including names and types) that has the same code.

        Stop Generating Data

        If the code of any application service, application service method, or DTO is a duplicate of an existing one, the system immediately terminates the generation process, and no data is generated.

        Note

        Notes on generating application services and DTOs:

        • An application service is generated for each data model. The application service code is generated using the format: {data model code}Service. If the data model code exceeds 72 characters, it is truncated to the first 72 characters.

        • Basic create, read, update, and delete (CRUD) methods are generated in each application service.

        • The system generates a corresponding DTO for each data model. Its code is generated using the format: {data model code}DTO.

    • Partial Generation

      1. In the Batch Generate Related Models pane, select Partial Generation.

      2. In the Select Data Model section, select the checkbox to the left of the target model name, and click Next.

      3. In the Generation Settings panel, in the Other Settings area, select Duplicate Data Detection Rule and Duplicate Data Handling Policy, and click Start Generation.