This guide demonstrates how changes to the underlying data structure of your application are deployed to the database.
[!success]- Prerequisites for further work
To follow along, you must meet the following prerequisites:
In ORIGAM, an application consists of a model, which holds structures such as data, user interface, business logic, and APIs, and a database that stores all the data, including both default and user-created data.
While developing the client application in ORIGAM Architect, the external database is built and gradually extended. Whenever you add a new Entity, Field, Foreign Key, or Index, these changes need to be reflected in the database as well.
This process is managed using deployment scripts with SQL commands that the platform automatically generates for you. In the following sections, we will demonstrate how to work with the Deployment Scripts Generator tool and observe its impact on the database.
Deployment Script Generator
The Deployment Script Generator is a tool that does exactly what its name implies—generates deployment scripts. You can find it in the Architect’s main menu under Tools:
In the Generator, you can filter three different groups of items:
Filter: Missing in Database
The first category is the most relevant for this tutorial. It displays all items that are present in your model but not in the database. This typically occurs when you add a new object like an Entity or Field or establish a Foreign Key relationship between two entities. In this example, we added a new Project
entity with several Fields, including a Foreign Key (_Id
):
Script Generation
To generate the script, open the Deployment Script Generator and select the Missing in Database filter, if it’s not already selected. The Entity we created for this example will be listed:
Now, let’s take a look at the script it generates. Select your entity and click the Preview button:
Afterward, you will see the SQL script generated by the Generator in the right bar:
The first part of the script creates a new database table and fields for it, including both user-generated fields like Name
and Description
as well as default fields like Id
or RecordCreated
.
The second part (ALTER TABLE) defines a Foreign Key for one of the fields in the Entity.
Script Deployment
You can either edit the script or execute it as-is. To execute it, select the script and click the Add to Deployment button.
In the next step, confirm that you want to add the items to the search results, as we need to review them:
By doing this, the generated scripts will appear in the Found Results tab in the right bar:
Double-click on one of the items, and you will be directed to the Deployment section of the Model Browser, where you can see your new deployment scripts at the end of the list, alongside all previously created scripts:
If you want to view or edit the script before executing it, double-click on its name to open it in the editor. There, you can review the following:
This is the table creation script. The other script defines the foreign key:
Script Execution
Scripts must be executed in the order in which they were created, which you can identify by the script numbering:
To execute a script, right-click its name and select Execute or press Ctrl+X:
If nothing visible happens, the script was executed successfully. If you try to execute a script that has already been run, you will receive an error message, and no action will be taken.
Database Check
After executing a script, you can view its effect in the database. In our example, a new table named Project
is created, including all the Fields and Foreign Key we added in the database:
Filter: Missing in Model
The second filter is used for importing structures from the database into your model. This functionality is useful in certain situations, such as when building an application over an existing database or when you want to use database structures that are already defined in your model.
Filter: Different
The third filter lists objects that exist in both the model and the database but are different. This may be useful in some rare cases, but we will not cover this in this tutorial.
For more information on the Deployment Script Generator, you can refer to this article and for general deployment information, visit here.