You can prepare a reversed database for ongoing MDriven model and schema management by having MDrivenServer create and synchronize the required administrative tables.
Use MDrivenServer to create the administrative tables
Use this procedure after you reverse engineer an existing database and upload its model to MDrivenServer. Do not create these tables manually.
- Open the MDrivenServer web interface for the server that connects to the existing database.
- Configure the database connection for that server and select the database connection type.
- Mark the application as reversed. This tells MDrivenServer that the database already contains tables and that the first model upload must not regenerate it.
- Upload the reversed model and verify that it is the current model version.
- Run Ensure admin tables and sync mapping and DB.
- Review the operation output. On a database that does not yet contain the administrative tables, the output reports that the missing tables are being created and that mapping is synchronized.
- Refresh the database schema in your database administration tool and verify that the four MDriven administrative tables now appear.
For example, after reversing a PostgreSQL database, uploading the model with the application marked as reversed does not alter the existing application tables. Running Ensure admin tables and sync mapping and DB then adds the MDriven administrative tables and synchronizes the model mapping with the current database.
Why the reversed setting matters
A reversed database already has an application schema. With the reversed setting enabled, the first model upload does not treat the database as empty and does not regenerate it. The administrative-table operation is the next required step: it establishes the MDriven metadata needed to compare the uploaded model with the actual database schema.
Do not use a workflow intended to recreate an empty database when you need to preserve an existing database. For a database you intend to replace, see HowTos:Recreate the SQL Database and HowTos:Use SqlServer with MDriven Turnkey.
What MDrivenServer creates and maintains
MDrivenServer creates four administrative tables. They support MDriven's persistence and schema-evolution work; they are not replacements for the application tables that were reversed from the database.
| Administrative table purpose | How it is used |
|---|---|
| Object identifier support | Stores values used by MDriven's default key generation for classes created from the model. |
| Object-relational mapping storage | Stores the object-relational mapping XML. MDrivenServer compares this mapping with the model to determine differences and construct database-alteration work for the configured database. |
| MDriven-managed table registry | Records extra tables created from MDriven so MDriven can identify tables it currently manages. |
| Type discriminator registry | Stores discriminator information that can be needed when a superclass and its subclasses are represented by multiple tables. |
Keep these tables in the database. They may initially contain little data, but MDrivenServer uses them as the model and database evolve.
Verify the result
After the operation completes:
- Refresh the schema in the database administration tool.
- Confirm that four new administrative tables are present in addition to the pre-existing application tables.
- Check the MDrivenServer operation output for successful mapping synchronization.
- Test the uploaded application against the reversed database.
If application behavior fails after this step, inspect the MDrivenServer exception log and validate the reversed model's persistence mapping. Database reverse engineering can omit classes, associations, primary keys, or foreign keys when the original schema does not define them explicitly. Use the reverse worker or manual persistence-mapping work described in Reverse Engineer a Database.
Manual table creation
This page does not provide a manual SQL script. Use MDrivenServer's Ensure admin tables and sync mapping and DB function rather than manually creating the tables. Manual creation can leave the administrative metadata and the uploaded model mapping out of sync.
Related database work
For database evolution performed from application code, see HowTos:Evolve Database with Code. For MDrivenServer setup and maintenance topics, see HowTos:Configure and Maintain MDriven Server.
