# Post-job scripts

{% hint style="info" %}
**Required license:** Professional or Enterprise
{% endhint %}

When a database generation job is complete, Tonic Structural can execute custom SQL scripts on the destination database.

Post-job scripts allow you to make adjustments to the destination database. For example, you might have a set of regular demo users that you always want to have available. You can use a post-job script to add these demo users to the destination database after each data generation run.

## Displaying the list of post-job scripts <a href="#post-job-scripts-list-display" id="post-job-scripts-list-display"></a>

You manage post-job scripts from the **Post-Job Actions** view. To display the **Post-Job Actions** view, either:

* On the workspace management view, in the workspace navigation bar, click **Post-Job Actions**.
* On **Workspaces** view, from the dropdown menu in the **Name** column, select **Post-Job Actions**.

On the **Post-Job Actions** view, the **Scripts** list contains the list of post-job scripts.

For each post-job script, the list contains:

* A toggle to enable or disable the script.
* The name of the script.
* The user who created the script.
* The date and time when the script was most recently updated.
* Options to edit or delete the script.

![Post-Job Actions view](https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2Fv9hSyQTi39MvAdMisjl4%2FPostJobActions.png?alt=media\&token=6983432c-83ec-4895-bcc7-2f0cf2fef8d0)

## Creating and configuring post-job scripts <a href="#post-job-scripts-manage" id="post-job-scripts-manage"></a>

{% hint style="info" %}
**Required workspace permission:** Configure post-job scripts and webhooks
{% endhint %}

### Creating a script <a href="#post-job-script-create" id="post-job-script-create"></a>

To create a post-job script, in the **Post-Job Scripts** panel, click **Create Post-Job Script**.

On the script configuration dialog, provide the script details, then click **Save**.

### Configuring a script <a href="#post-job-script-configure" id="post-job-script-configure"></a>

On the script configuration dialog:

![Post-job script configuration dialog](https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FqYSaEir4MGe9bFIcoXP9%2FPostJobScriptDetails.png?alt=media\&token=123dd1f5-616a-473c-bc24-2c2e7a65b21e)

1. In the **Script Name** field, provide a name for the script.
2. In the **SQL Script** field, type or paste the SQL script.\
   \
   For a MySQL database, you must explicitly pass a `USE` statement to define the database.
3. To format the script for readability, click **Beautify**.
4. By default, if a post-job script fails, then Structural registers a warning, but the data generation job does not fail.\
   \
   To instead fail the data generation job, toggle **Enable Warnings** to the off position.
5. To save the script configuration, click **Save**.

### Editing a script <a href="#post-job-script-edit" id="post-job-script-edit"></a>

To edit a post-job script:

1. In the **Scripts** list, click the edit icon for the script.
2. On the script configuration dialog, make the updates to the script.
3. Click **Save**.

## Deleting a script <a href="#post-job-script-delete" id="post-job-script-delete"></a>

{% hint style="info" %}
**Required workspace permission:** Configure post-job scripts and webhooks
{% endhint %}

To delete a post-job script configuration:

1. In the **Scripts** list, click the delete icon for the script.
2. On the confirmation dialog, click **Delete**. &#x20;

## Managing script execution <a href="#post-job-scripts-execution-settings" id="post-job-scripts-execution-settings"></a>

{% hint style="info" %}
**Required workspace permission:** Configure post-job scripts and webhooks
{% endhint %}

### Changing the script execution sequence <a href="#post-job-script-execution-sequence" id="post-job-script-execution-sequence"></a>

In the **Scripts** list, the script display sequence determines the execution sequence. The script at the top of the list is executed first, and the others follow in order from top to bottom.&#x20;

To change the execution sequence, change the display sequence.

To execute a script earlier, drag it to a higher location in the list.

To execute a script later, drag it to a lower location in the list.

### Enabling and disabling scripts <a href="#post-job-script-enable-disable" id="post-job-script-enable-disable"></a>

You use the toggle at the left of each script to control whether the script is enabled.&#x20;

When the toggle is in the on position, the script runs.

When the toggle is in the off position, the script does not run.

## Viewing and managing configuration inheritance  <a href="#post-job-scripts-inheritance" id="post-job-scripts-inheritance"></a>

{% hint style="info" %}
**Required license:** Enterprise license.
{% endhint %}

### Managing the inheritance status for a child workspace <a href="#post-job-scripts-inheritance-child" id="post-job-scripts-inheritance-child"></a>

By default, a child workspace inherits the configured post-job scripts from its parent workspace.

If you make any changes to the child workspace configuration, including adding, editing, or deleting a script, the inheritance is removed. The child workspace no longer inherits any post-job script changes from its parent workspace.

For a child workspace, the **Post-Job Scripts** view indicates the current inheritance status.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2F5CApoE0NssfYVr5X8K34%2FScriptsChildInherits.png?alt=media&#x26;token=296278c1-bf5a-40ff-96bd-6eef94efb2d4" alt=""><figcaption><p>Child workspace inherits the parent configuration</p></figcaption></figure>

* **Inherits parent configuration** means that the child workspace inherits the post-job scripts from the parent workspace.
* **Overrides** parent configuration means that the child workspace does not inherit the post-job scripts from the parent workspace.

To reset the inheritance, in the **Overrides parent configuration** notice, click **Reset**, then on the confirmation dialog, click **Reset** again.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FiSn0bU7HeTzTovWMiKvz%2FScriptsChildOverrides.png?alt=media&#x26;token=b7bfbff8-8e6c-4147-ae5f-015091594ed8" alt=""><figcaption><p>Option to reset inheritance on a child workspace</p></figcaption></figure>

The overrides are removed. The child workspace inherits any subsequent configuration changes from the parent workspace.

### Viewing the inheritance status for children of a parent workspace <a href="#post-job-scripts-inheritance-parent" id="post-job-scripts-inheritance-parent"></a>

For a parent workspace, you can view the current inheritance status of the child workspaces.

The **Child Workspaces** tab contains the list of child workspaces.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FQneG1UYFFRG9ekAb59L7%2FScriptsParentChildWorkspaces.png?alt=media&#x26;token=379336c8-e58b-44bb-8274-818cb267af25" alt=""><figcaption><p>Child Workspaces tab for a parent workspace</p></figcaption></figure>

For each workspace, the list includes:

* The workspace name.
* The inheritance status.\
  \
  **Inheriting** indicates that the child workspace inherits the configuration from the parent.\
  \
  **Overriding** indicates that the child workspace overrides the configuration and does not inherit it from the parent.
* Your role in the child workspace.
* The owner of the child workspace.

You cannot reset the inheritance status from the **Child Workspaces** tab. If you have access to a child workspace, then to switch to that workspace, click the arrow icon in the rightmost column.
