TMappingExplorer on existing database

Hi Wagner,

I am migrating an existing database by creating all new tables as entities so for example the existing database has 325 tables and I am adding 2 new ones.  when I run DBManager.ValidateDatabase I get the following Schema Messages even when I use the MappingSetup to register only the two new tables.

Invalid database structure. 325 Errors, 0 Warnings, 2 Actions 
Error: Table: Table001 - Removed.
Error: Table: Table002 - Removed.
Action: Table: Table326 - Created.
Action: Table: Table327 - Created.

I have lost tables in the past but currently the above Removed action does not work because of other errors.

Is there a way if getting Aurelius to ignore any existing tables that is not registered in Aurelius?

Eventually I will add the existing tables to the persistent entity classes but not all of them. The legacy code will still need to access the database outside of Aurelius.

Thanks Greg

Hi Greg, I'm confused about the whole scenario, I didn't understand it well.

Both TObjectManager and TDatabaseManager uses the TMappingexplorer object passed to it to know which classes (and thus tables) it should consider. Does this info help? If not please try to explain with code examples so it gets clearer for me what you are trying to do.

In the example above the MS Sql Server database, say MSSQLdb,1 already has tables 001 to 325 in it from another system and they are managed using DBExpress. I have added tables 326 and 327 using the following code.

function TMSSQLScenarioFactory.GetMapping: TMappingExplorer;
  MapSetup: TMappingSetup;
  MapSetup := TMappingSetup.Create;
    MapSetup.MappedClasses.RegisterClass(TGLOutput); \=Table326 in example
    MapSetup.MappedClasses.RegisterClass(TOutputMapping); \=Table327 in example
    Result := TMappingExplorer.Create(MapSetup);

procedure TMSSQLScenarioFactory.ValidateStructure;
  DBManager: TDatabaseManager;
  SchemaMessage: TSchemaMessage;
  DBManager := TDatabaseManager.Create(GetConnection,GetMapping);
  if DBManager.ValidateDatabase then
    iSystemLog.LogMessageAll('Database strucuture is valid.')
    WriteLn(Format('Invalid database structure. %d Errors, %d Warnings, %d Actions ',[DBManager.ErrorCount,
      DBManager.WarningCount, DBManager.ActionCount]));
    for SchemaMessage in DBManager.Warnings do
      WriteLn('Warning: ' + SchemaMessage.Text);
    for SchemaMessage in DBManager.Errors do
      WriteLn('Error: ' + SchemaMessage.Text);
    for SchemaMessage in DBManager.Actions do
      WriteLn('Action: ' + SchemaMessage.Text);

Even thought I have only two classes registered Aurelius still wants to deal with the other tables and remove them. What am I missing?

it's simple, you say in Aurelius your database should have two tables. It's checking your database and performing a validation saying that the database you have needs to have 325 tables remove and 2 tables to be the way you want. 

Either you add the 325 tables to Aurelius database manager or you have to live with it, I don't know how do you expect that Aurelius will tell if the table is a legacy table that must be kept, or is a leftover table that must be removed?