Schema Synchronization

DbSchema projects can be uploaded from an existing database or they can be started from scratch. In both cases, DbSchema creates its own version of the schema, independent from the database.

Working with a project file means that:

  1. If you want to synchronize the local schema with the database, you have to compare and refresh them every time you open DbSchema. Read more about the synchronization process.
  2. The schema and layouts will be saved to project file. You can open the schema without being connected to the database and pick up where you left off. After you connect to the database, you can synchronize the schema.
  3. You can work on the schema while connected to the database (online) or without database connection (offline)
    • In the online mode, all the changes made to the schema will be applied to the database. The executed elements can be seen on the left side of the screen, in SQL History Pane.
    • In the offline mode, changes will be applied only to DbSchema local project. When you reconnect to the database you have to refresh the schema from database.

Create or Upgrade a schema into the database

If you created a schema from scratch and want to update it in the database, all you have to do is:

  1. Click on Schema in the upper menu;
  2. Select Create or Upgrade Schemas from the Database;
  3. If you are not connected to a database, the next step will be to establish connection. Learn more about how to connect to a database here.
  4. After you established connection, choose the schemas that you want to create/ update;
  5. After you execute the script, your schema will be updated in the database
Create Schema Select Schema

Synchronize local schemas with the database

This features is extremely useful if you work on the schema without being connected to the database.

  1. Select the Refresh button from the upper tool menu;
  2. If your schema is not synchronized, the next window should pop-up
  3. If you choose Refresh, the changes will be taken over into your local project;
  4. The Review Changes button will open the Sync Dialog
Refresh Refresh Dialog
Sync Dialog

Convert Schema to a Different Database

What does it mean to convert a schema to a different database?

  1. Open Project -> Project Properties;
  2. Insert a new name for your schema;
  3. Select the new database from the Rdbms field. Click Ok;



  4. A new dialog will appear. This shows you how the data types will be converted from the initial database to the new one;
  5. Save the project to a new file and connect to the new database.
Select Database Select Data Type

Synchronize the project with your team

The DbSchema project (.dbs) is an XML file, that can be opened in any text editor. This file can be stored in a version repository like GIT, Mercurial, SVN, CVS, etc. Multiple developers can work on it and synchronize the changes.


Schema Synchronization with other Project from Files

Project files store the schema, so why not to synchronize it with another project file? Suppose you develop a schema, save it to project file and store this file in a GIT or other versioning repository. Later you want to see the schema differences between the two different versions. You can open one file in DbSchema and compare it with the second. Than you can generate the migration script from one to the other.


Synchronization Filters

In the Synchronization Dialog there is a button for creating custom synchronization filters. Using this filters you may decide to always reject certain differences. For example you may want to always ignore tables existing on the server having a certain pattern. In the Sync Dialog you will find a button for creating custom Synchronization Filters. Use this to create a rule for always rejecting certain differences. For example, you may always want to ignore tables that contain a certain person.


    import com.wisecoders.dbs.rdbms.sync.engine.diffs.*
    import com.wisecoders.dbs.schema.*

     return new SyncFilter() {
       public boolean rejectDiff( AbstractDiff diff ) {
         if ( diff instanceof TableExistsDiff){
           SyncPair pair = ((TableExistsDiff) diff).pair;
           if ( pair.right != null && pair.right.getName().startsWith("OTHER")) return true;
         }
       return false;
       }
     };

The complete list of DbSchema classes is exposed in DbSchema API. For more examples about Groovy scripts visit the DbSchema Automation page.