3.1. Table editing

Whenever you want to create or edit the table structure, you will see the table editor. Tables can only be created within a schema, so you must create a schema first.

If the table is created via a layout (RMB on a free space, then "Create new table"), you will be offered a choice of schema and the option "create schema".

images/select_schema_for_new_table.png

The table editing option is available both through the project explorer and through the layout. Right-click on the desired table and select "Edit table structure" to get the desired result. This is the default action, so double-clicking on the table header will open the editor as well.

The table editor interface is divided into tabs. Each tab has a numeric bullet in the header that shows how many entities are currently in that tab.

images/table_editor/edit_table.png

Table editor window is a "singleton". If you try to edit a table that is already open in the editor, the existing window will be shown instead of creating a new one.

Editor shortcuts

  • Left, Right, Up, Down - cells navigation
  • PageUp, PageDown - scroll by one page of rows
  • Home, End or ⌘/Ctrl + Left, ⌘/Ctrl + Right - move cursor to first or last column
  • Shift + Home, Shift + End or ⌘/Ctrl + Up, ⌘/Ctrl + Down - move cursor to a first or last row
  • Enter, F2 - enter cell edit mode
  • Menu key or Application key - open context menu for a current cell

Columns editor

The column editor is made on the "edit-in-place" principle. To edit the desired parameter, simply change the value in the desired cell (except "Foreign key" column). To add a new column, fill in the blank at the bottom of the grid.

Description of grid columns:

  • Column "Name". Name of table column. Will be escaped in a create table/alter table step.
  • Data type. Column type in a database terms. For each database type here is drop-down suggestion with column types of the database.
  • Column with key icon. Indicates that this column is a primary key or a part of a primary key. In the case of a composite primary key, the order in the primary key will be the same as the order in this grid. If you need a custom order, specify it in the and do not touch the primary key checkboxes on the first one.
  • "Autoincrement" column. This column is specific to MySQL. Indicates that field will be added with "AUTOINCREMENT" keyword. Not compatible with default value.
  • "Nullable" column. It is inverted value of "NOT NULL" keyword presence. Inversion was made for a two reasons: checkbox with "not" is a anti-pattern and we believe that the ability to contain nulls should be included consciously.
  • "Default" column. Non-empty value will be included as is into create/alter DDL with "DEFAULT" keyword.
  • "Comment" column. This comment will be stored in database. Usable for database documentation. Will be included into structure for generator, so can be used also for a generated code documentation. Comments appears in the project tree tooltip and used in search.
  • "Foreign key" column. This column is read-only.. It contains comma-separated names of a foreign keys, which contains this field.

Context menu

images/table_editor/context_menu.png

The context menu allows you to delete a column, as well as create or edit a directly from the list of columns.

Constraints editor

images/table_editor/constraints.png

The constraints tab contains a primary key information, indexes and unique constraints lists.

Primary key

The primary key is defined by two fields: name and column set. Since in MySql the primary key has no name, the field with the name of the primary key does nothing. For PostgreSQL name is optional. If you leave the name field blank, the database will automatically generate a name for the primary key. The primary key will be named during the process. Note: OrmFactory will try to change primary key to match column names, if you rename column name in the first tab.

Indexes and unique constraints

Below the primary key there is two similar grids for indexes and unique constraints. They both have two parts: name and columns. Name field is required for adding a new index or unique. Columns field must contain comma-separated column names. Autocomplete will show drop-down list of column names from "Columns" tab. Since MySql requires a length prefix for a some types, so you can specify length right after column name, for example movie_id, trailer_name(10). Note: OrmFactory will try to change index/unique here to match column names, if you rename column name in the first tab. Length prefix will be preserve.

Foreign keys

images/table_editor/foreign_keys.png

"Foreign keys" tab has the same "edit-in-place" principle as previous tabs. But you can edit foreign key in a separate window.

images/table_editor/foreign_key_editor.png

This window has "name generation" feature. It will automatically generate the name when you fill in the foreign key fields. Feature will be enabled when foreign key name is empty. You can enable it yourself by clicking the button on the right inside the foreign key name field.

Note: OrmFactory will attempt to update foreign keys automatically if you rename the referenced table or column.

Custom parameters

images/table_editor/custom_parameters.png

Parameters are the part of the model that does not participate in defining the database structure, but are stored in the project file. You can use parameters for additional information when generating code for your language.

Applying changes

After changes was made, you can press Apply button to apply changes to database structure. If changes can be transformed into DDL, you will see next window:

images/table_editor/preview_changes.png

This is a DDL preview window. All structure changes will be forced to be confirmed by user. This is not only preview. You can edit DDL before apply to database. OrmFactory will try to execute changed text.

Model reloading

When you successfully apply changes to table in the preview window, table model will be reloaded. OrmFactory retrieves table structure from database and replaces model information to actual one.

Information to be replaced:

  • Column type. This allows to convert alias types to native ones.
  • Column default value. To show real default value in special cases.
  • Primary key. This will reload primary key name given by database.
  • Indexes. Because MySql can create index when created new foreign key. PostgreSQL automatically creates indexes on primary keys and unique constraints.