Quantcast
Channel: TMS Software
Viewing all articles
Browse latest Browse all 1008

My Top 10 Aurelius Features - #7 Schema Update

$
0
0

When creating a database-based application, one of the tasks I always considered boring was to create the database structure, table, fields, foreign keys. Even using a tool to generate a SQL would require me to create a table, add columns, column types, foreign keys, etc.

That's why I consider the ability to automatically create and update the database schema to be the #7 feature of My Top 10 Aurelius Features. It's simply something I don't need to care about anymore.



Updating the database is as easy as doing this:

TDatabaseManager.Update(Connection);
That simple command will check the existing schema in the database and create the missing objects needed to persist all the objects you are dealing with: new tables, columns, foreign keys.

Note that I'm talking about updating, not creating the database. That makes application prototyping and development really fast. Create the database, change your application, add a new table, update the database, and it goes on.

Even though updating the database is as simple as using one line of code, Aurelius provides advanced features for the database update process, like validation. With a code like the following, you can check the differences between the schema of the existing database, and what is needed in the schema to hold the current entity model you have. It shows you the differences without requiring you to actually execute the SQL statements:
procedure TForm1.ValidateMyDatabaseSchema;
var
  DBManager: TDatabaseManager;
  Action: TSchemaAction;
  Warning: TSchemaWarning;
  Error: TSchemaError;
begin
  DBManager := TDatabaseManager.Create(Connection);
  try
    DBManager.ValidateDatabase;

    { Show SQL statements }
    mmStatements.Clear;
    for Statement in DBManager.SQLStatements do
    begin
      mmStatements.Lines.Add(Statement);
      mmStatements.Lines.Add('');
    end;

    { Show validation results }
    mmValidation.Clear;

    mmValidation.Lines.Add('----- Actions -----');
    for Action in DBManager.Actions do
      mmValidation.Lines.Add(Format('%s -> %s', [Action.ClassName, Action.Text]));
    mmValidation.Lines.Add('');

    mmValidation.Lines.Add('----- Warnings -----');
    for Warning in DBManager.Warnings do
      mmValidation.Lines.Add(Format('%s: %s', [Warning.ClassName, Warning.Text]));
    mmValidation.Lines.Add('');

    mmValidation.Lines.Add('----- Errors -----');
    for Error in DBManager.Errors do
      mmValidation.Lines.Add(Format('%s: %s', [Error.ClassName, Error.Text]));
  finally
    DBManager.Free;
  end;
end;
Please watch the video (closed captions available!) to see how schema update and validate in action. As usual, don't forget to subscribe to our YouTube channel and receive notifications about upcoming videos!


Viewing all articles
Browse latest Browse all 1008

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>