6.8. Swap objects ids

The objects ids swapping tool is mostly used to solve some conflicts that the validation tool can't. It basically grants the user full control over the creation order of the objects in the database model. You seldom need to use this feature but there are very few cases in which its use is needed.

One example could be a function that inside its source code references a table somehow but the table is being created after the function. Since the validation tool lacks the ability to check conflicts inside the object's SQL code, in the presented scenario, the model would validate without problems except when running the SQL code validation (fourth and optional step). In this case, PostgreSQL would detect the reference breaking due to the malformed code. In order to solve problems like this the user can manually swap the creation order of the objects using the dialog below. In that form one can specify which object will be created before another so any reference breaking not detected by the validation can be solved.

Another example of usage of this tool is when the default value of a column uses a function call like nextval(some_sequence::regclass) and that sequence is being created after the table that owns the column. The solution here is to swap the ids of the sequence and table making the first object be createad before the latter. It's important to warn that changes made in this dialog are irreversible and causes the operation list to be erased an puts the model in a modified state which demands a validation. The fields of the form are described below.

Action/Field Description
Create This object picker defines the object to be created before another one.
Before This object picker defines the object which will be placed after the one selected in the above picker.
Swap values This button swap the object pickers values.
Swap ids This button applies the ids swapping.
Filter This field is used to filter objects by name.
Object listing The object listing shows the creation order of all objects in the database model and is used as an alternative way the select the objects to be swapped. Objects can be selected by double clicking any item on the grid. The first double click will place the object in the Create picker and a second double click will set the Before picker with the object selected on the listing.

Aug 31, 2018 at 15:56