Skip to content

Database Setup

dannykopping edited this page Jul 26, 2011 · 3 revisions

In the Plugins/MySQL Workbench folder, you will find a file named AerialExport.grt.lua. This file is a plugin for the popular database management tool MySQL Workbench to export YAML-formatted data that represents your database schema.

If you do not have MySQL Workbench installed, you can download it from here. MySQL Workbench is a cross-platform tool, so you'll be able to find a version that is relevant for your operating system. Once you have installed MySQL Workbench, navigate to its installation directory and open the modules folder. You can copy the AerialExport.grt.lua file into this directory and restart MySQL Workbench. Now you are ready!

You do not have to use MySQL Workbench - although it is the tool recommended by the Aerial development team. If you do not wish to use MySQL Workbench, you can see the guide to writing YAML schema files on the Doctrine ORM website: http://www.doctrine-project.org/projects/orm/1.2/docs/manual/yaml-schema-files/en#yaml-schema-files

If you have a database with one or more tables already, you can Reverse Engineer the database so that you have a diagrammatic representation inside of MySQL Workbench. For more information on Reverse Engineering in MySQL Workbench, see http://dev.mysql.com/doc/workbench/en/wb-reverse-engineering.html

If you do not have any tables in your database, you can download this sample file and open it in MySQL Workbench.

Managing a Schema

Once you have reverse-engineered an existing database or downloaded the sample model and opened it, you should see a diagram like this in MySQL Workbench:

Workbench Start

NOTE: In the Catalog Tree, right-click on the top node of the tree and select Edit Schema... You need to ensure that the Name matches the name of your database you created earlier.

We will now ensure that what we see in the diagram is what will exist in our database - we can do this by synchronizing the model with the database. From the top menu, select Database and then Synchronize Model... This will bring up a dialog like this one:

Workbench Start

Keep clicking Next until you get to the Model and Database Differences section:

Workbench Start

This section will show you the synchronization status of your model and your database. Click Next and then Execute to execute the synchronization process. If all goes right, your database and your model will be synchronized.

We are now ready to export our YAML schema based on the Workbench model. To do this, go to the top menu click on the Plugins button, then Catalog and then Aerial Export 1.0: Copy to Clipboard. Next, open src_php/config/schema.yml and paste the YAML. The file should now look like this:

---
detect_relations: true
options:
  collate: utf8_general_ci
  charset: utf8
  type: InnoDB

User:
  tableName: User
  columns:
	id:
	  type: integer(4)
	  primary: true
	  notnull: true
	  autoincrement: true
	firstName:
	  type: string(255)
	lastName:
	  type: string(255)

Comment:
  tableName: Comment
  columns:
	id:
	  type: integer(4)
	  primary: true
	  notnull: true
	  autoincrement: true
	title:
	  type: string(100)
	message:
	  type: clob(65535)
	userId:
	  type: integer(4)
	  notnull: true
  relations:
	User:
	  class: User
	  local: userId
	  foreign: id
	  foreignAlias: comments
	  onDelete: cascade
	  onUpdate: cascade
  indexes:
	fk_Comments_User:
	  fields: [userId]

We're nearly there!

Next Step: Code Generation

Clone this wiki locally