# PDSAdminTool Extension: Copy Model

This document describes the workflow for copying PDS models from an old PDS project to a new PDS project.

## Overview

- A schema file is passed to the tool.
- Two projects are selected, `pd_projname`, by using a combo box.
- The tool checks whether the versions of the **old** and **new** projects are identical.
- If the versions are different, the process stops.

Use the following query to check the project version:

```sql
SELECT pdtable_103.product_version_no FROM pdtable_103;
```

## Model Selection

- In the tree view, list all model files from `pdtable_113` in the **old** project.
- Group the list by discipline, `_111`, and area, `_112`.
- Allow the tree view to be selected by using a text file in which the file names are listed line by line.
- Process all selected files in a loop.

For the old project, read the model entry with:

```sql
select * from pdtable_113 where model_no='filename';
```

## Validation in the New Project

Check whether the `model_index_no` and `partition_no` already exist in the **new** project.

- If they already exist, write an entry to the log file and continue with the next file.
- If they do not exist, continue with the copy process.

Then check whether the following objects exist in the **new** project:

- discipline, `_111`
- area, `_112`

If they do not exist, create them by copying the corresponding row from the old schema.

After that, copy the row from `pdtable_113` from the old project into the new project.

## Update Node and Path Information

Update the node and path values by using the values from `pdtable_115` in the new project.

```sql
SELECT pdtable_115.default_node, pdtable_115.default_path_name
FROM pdtable_115
WHERE (((pdtable_115.discipline_indx_no)=1));
```

If `discipline_no = 3`, the path is not taken from `_115`, but from `_116`, by using `sub_project_ndx_no` from `_117`.

## Discipline-Specific DD Schema Transfer

### If `discipline_no = 1`

Unload the following tables from `dd_projnameALT`:

- `pdtable_12_partitionNo`
- `pdtable_34_partitionNo`
- `pdtable_50_partitionNo`
- `pdtable_67_partitionNo`
- `pdtable_80_partitionNo`

Example:

```text
risunlod -mw -o c:\temp\xx.txt -s pd_schwedt table with data pdtable_12_partNo index pdtable_12_partNo grant pdtable_12_partNo view pdtable_12_partNo
```

Load these five tables into `dd_projnameNEU`:

```text
rislod -m w -i c:\temp\xx.txt -s dd_projname clear table with data all view all index all grant all
```

### If `discipline_no = 2`

Unload the following tables from `dd_projnameALT`:

- `pdtable_21_partitionNo`
- `pdtable_22_partitionNo`
- `pdtable_23_partitionNo`
- `pdtable_24_partitionNo`
- `pdtable_25_partitionNo`
- `pdtable_26_partitionNo`
- `pdtable_27_partitionNo`
- `pdtable_28_partitionNo`

Load these eight tables into `dd_projnameNEU`:

```text
rislod -m w -i c:\temp\xx.txt -s dd_projname clear table with data all view all index all grant all
```

## Copy the Model File

Finally, copy the model from the path in `113_alt` to the path in `113_neu` in the new project.
