Show/Hide Toolbars

TMS Aurelius Documentation

You can update the existing database structure using method UpdateDatabase:

 

uses

  Aurelius.Engine.DatabaseManager;

{...}

var

  DBManager: TDatabaseManager;

begin

  DBManager := TDatabaseManager.Create(MyConnection);

  DBManager.UpdateDatabase;

  DBManager.Free;

end;

 

This method will:

 

1. Perform a schema validation, which consists of:

a) Execute SQL statements to perform a reverse engineering in the database, retrieving the existing database schema (*).

b) Compare the existing schema with the target schema (all database objects - table, columns, etc. - need to persist the mapped entity classes.

c) Provide info about the differences between the two schema (see schema validation for details).

d) Generate the SQL Script needed to update the database schema

 

2. Execute the SQL Script in the database, unless command execution is disabled (see Generating SQL Script)

 

(*) Note: for Aurelius to properly import database schema, you need to register a schema importer according to the database server you are connecting to. For example, to import MySQL schema, just use the unit "Aurelius.Schema.MySQL" anywhere in your project.

 

If command execution is disabled, this method behaves exactly as the ValidateDatabase method.

 

Since this method performs on a database that has existing object and data, it has some limitations. First, if you are unsure of the effects of schema update, it's strongly recommended that you check schema validation results before updating. Errors might occur when updating the schema, for example, if new schema requires a foreign key creating but existing data doesn't fit into this new constraint. See schema validation for a list of current valid operations and limitations.

 

Note that UpdateDatabase is a non-destructive method. This means that even if the validation reports that a data-holding object (table or column) needs to be dropped, the SQL statement for it will not be performed.