Comparing Schema and Project

The following walkthrough describes how to edit project and how to synchronize a schema and a project. A project from the walkthrough will be used there.

Prerequisites

You should have the following privileges:

  • CREATE privilege on the demobase database
  • DROP privilege on the demobase database
  • ALTER privilege on the demobase database
  • SELECT global privilege

To complete this walkthrough, you must have completed the walkthrough.

Updating project

In the previous walkthrough the project Demobase was created and deployed. Now, you will add stored procedures to it. For this:

  1. Right-click the Database objects folder node in Solution Explorer.
  2. Select Add Folder on the shortcut menu.
  3. Enter the new folder name (Procedures).
  4. Click on the Devart - Main toolbar.
  5. Type or paste the following code into the SQL document:
CREATE PROCEDURE demobase.addemp(IN EmpName CHAR(20), IN Salary INT)
BEGIN 
  DECLARE e_No   INT;
  DECLARE e_Name CHAR (20) DEFAULT 'Unnamed';
  DECLARE e_Sal  INT DEFAULT 1100;
  IF EmpName IS NOT NULL THEN
    SET e_Name = EmpName;
  END IF;
  IF Salary IS NOT NULL THEN
    SET e_Sal = Salary;
  END IF;
  SELECT
    MAX(empno)
  INTO
    e_No
  FROM
    demobase.emp;
  INSERT INTO demobase.emp (empno, ename, sal, hiredate)
  VALUES
    (e_no + 10, e_name, e_sal, CURDATE());
END
  1. Click the Save button on the Standard toolbar.
  2. Choose file location and enter file name (for example, Procedure Addemp) in the appeared Save As dialog box.
  3. Save the file.
  4. Right-click on the Procedures folder in Solution Explorer and choose Add Existing File on the shortcut menu

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. These elements are determined by your Visual Studio edition and settings. For more information, see Visual Studio Settings.

  1. Choose the created file in the Open dialog box.
  2. Repeat steps 1-7 for the RaiseSalary procedure
CREATE PROCEDURE demobase.RaiseSalary(IN department VARCHAR(14), IN rate FLOAT)
  COMMENT 'Raise salary of all employee working in this department'
BEGIN 
 DECLARE  d_No INT DEFAULT 0;
 SELECT DeptNo INTO d_No FROM Dept WHERE Dname=Department;
 UPDATE Emp SET Sal=Sal*Rate WHERE DeptNo=d_No;
END

Now, suppose you don’t need to store sum of the employee salary for the departments. Delete salsum column in the dept table and all triggers, updating it.

  1. Expand the Tables folder in Solution Explorer and double-click the Table Dept.sql file.
  2. Delete the salsum FLOAT, line and save the document.
  3. Click the Triggers folder and press the DELETE key.
  4. Click Yes in the appeared dialog box.

Comparing the project and the schema

Now, you’ll compare your project with the schema. Perform the following steps to create new schema comparison document.

  1. Select New Schema Comparison on the Tools -> dbForge Fusion for MySQL menu.

    or

    Click the Open Schema Comparison Wizard button on the Devart - Main toolbar.

  2. Click Project in source or in target, then choose the project in the field below.
  3. Select connection for the compared schema. You can edit the selected connections or create a new one by clicking the Edit Connection or New Connection buttons.
  4. Select the compared database demobase.
  5. Click the OK button.

The schema comparison document will open. You can see comparison status of all schema and project options here. Table emp has Equal status. It has the synchronization operation Skip and will not be affected when synchronizing schema and project. Table dept has Different status. Click on it to see differences in the DDL. It has the Update synchronization operation and will be updated during synchronization.

View staff also has Different status. That’s because view select statement is stored in unformatted and single-line form. Views in project and in database will always have Different status, unless you use the same unformatted view form in the project. You don’t need to synchronize view now, click on its operation and choose Skip from the drop-down list.

Procedures have Only in Source status. They exist only in project and will be created during synchronization. Triggers exist only in target and will be dropped during synchronization.

Click the View Schema Update Script button on the Devart - Comparison toolbar to preview update script. To synchronize project, return back to the schema comparison document and click the Synchronize button on the Devart - Comparison toolbar. Select what you want to do with the synchronization script in the displayed Schema synchronization wizard. Click the Synchronize button to close the wizard and complete the synchronization. Review the synchronization script (if you selected to view it in the editor) and then execute it by clicking the Execute button on the toolbar or selecting SQL -> Execute on the top menu.