Forward Engineering

Forward Engineering is the process of generating a database schema from a physical model. It enables the synchronization of the data model with the database when physical changes have been made to the data model, such as adding, removing, or changing entities, fields, indexes, physical names, and relationships. It also employs all the changes that are made in the data model while restructuring it. While it executes physical changes, logical changes are not reflected in forward engineering.

How to Forward Engineer a Data Model

To forward engineer a data model, click on the forward engineering icon in the toolbar of the data model designer. By default, this option generates a DDL script when selected.

01-dwb-toolbar-forward-engineer-option

When you click the arrow next to the Forward Engineer icon, a drop-down menu appears, that shows the four options to forward engineer the data model.

These options are:

1. Apply DDL Script

2. Apply Diff Script

3. Generate DDL Script

4. Generate Diff Script

02-forward-engineer-dropdown

Let’s consider the following data model to explore each of these forward engineering options one by one.

03-data-model

This data model represents a simple star schema, with one Fact and four Dimensions.

Apply DDL Script

The Apply DDL Script option generates an SQL Script for the entire data model schema and automatically executes it on the specified database.

1. Specify the database connection where you want to execute the script. To do that, click on the Change Database Connection Info icon in the toolbar. Alternatively, press Shift+Alt+C to open the Database Connection window.

04-database-connection-icon

Specify the database connection information and click OK.

05-database-connection-window

2. Select the Apply DDL Script option from the Forward Engineer option dropdown menu. Alternatively, press Shift+Alt+F5.

06-apply-ddl-script

3. The Apply Scripts window shows all the operations that will be applied to the database once the script is executed. It gives the summary of the following:

  1. Operation
  2. Object Name
  3. Type

View all the changes and click Execute.

07-apply-script-window

The script will be executed, and the operations will be performed on the specified database. The results of the transaction can be seen in the Output window.

Note: If the Output window does not appear, go to View > Output in the main menu. Alternatively, you can press Ctrl+Alt+O to open the Output window.

08-output-apply-ddl-script

Apply Diff Script

A Diff Script is a SQL script that reflects any differences between the data model and the corresponding database. The Apply Diff Script option generates a Diff Script for all the differences between the data model and the corresponding database and automatically executes it on the specified database.

1. Specify the database connection where you want to execute the script.

2. Select the Apply Diff Script option from the Forward Engineer option dropdown menu. Alternatively, press Shift+Alt+F1.

09-apply-diff-script

If you select Apply Diff Script and there are no differences between the data model and the corresponding database, a message that ‘No changes were detected’ will be shown.

10-no-changes-detected

Let’s add a new Dimension to the data model and link it to the Fact with a non-identifying relationship. The data model now looks like this.

11-changed-data-model

Select the Apply Diff Script option after making the changes specified above.

3. The Apply Scripts window shows all the changes that were made to the data model. In this case, it shows that a new dimension has been added. View all the changes and click Execute.

12-apply-script-window-entity-added

The script will be executed, and the changes will be made to the specified database. The results of the transaction can be seen in the Output window.

13-output-apply-diff-script

Generate DDL Script

The Generate DDL Script option generates an SQL Script for the entire data model schema. It does not execute the script automatically. However, the generated script can be executed in the database.

To generate a DDL script for the data model, select Generate DDL Script option from the Forward Engineer option dropdown menu. Alternatively, press Shift+Alt+F2.

14-generate-ddl-script

You can also go to Data Model > Generate DDL Script from the main menu.

15-generate-ddl-script-main-menu

In the Save window that shows up, navigate to the desired directory, provide a name for the DDL script, and select Save.

16-save-ddl-script

The DDL script has been generated and saved. You can execute this script in the database server if required.

4. Generate Diff Script

The Generate Diff Script option generates a Diff Script for all the differences between the the data model and the corresponding database. It does not execute the script automatically. However, the generated script can be executed in the database.

To generate a Diff Script for the data model, select Generate Diff Script option from the Forward Engineer option dropdown menu. Alternatively, press Shift+Alt+F3.

17-generate-diff-script

In the Save window that shows up, navigate to the desired directory, provide a name for the Diff script, and select Save.

18-save-diff-script

The Diff script has been generated and saved. You can execute this script in the database if required.

Note: If you select Generate Diff Script and there are no differences between the data model and the corresponding database, a message stating that ‘No changes were detected’ will be shown.

19-no-changes-detected-2

Forward Engineering Selected Entities

Each of the four forward engineering options can also be applied to a single entity or a set of entities selected. Select the entity or the set of entities that you want to forward engineer and select one of the four forward engineering options. The script will be generated and/or applied only for the selected entities.

20-apply-script-to-selected-entities

This concludes our discussion on forward engineering a data model in Astera DW Builder.