> For the complete documentation index, see [llms.txt](https://jadelab.gitbook.io/jadegit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jadelab.gitbook.io/jadegit/0.18.0/admin/database-images/example/empty.md).

# Empty

The `empty.yml` template creates an empty image for each platform by obtaining a code-only copy of the database snapshot specified using the [`snapshot/download.yml`](/jadegit/0.18.0/admin/database-snapshots/example.md#download) template, upgrading it to the target platform version using the `upgrade.yml` template, and publishing the result to the catalog.

```yaml
parameters:
- name: snapshot
  type: object

- name: platforms
  type: object

- name: preview
  type: boolean
  default: false

jobs:
- ${{ each platform in parameters.platforms }}:
  - job: empty_${{ parameters.snapshot.database }}_${{ replace(platform.version, '.', '_') }}_${{ platform.charset }}
    displayName: "${{ parameters.snapshot.database }} - ${{ platform.name }}"
    workspace:
      clean: all
    variables:
      snapshot.path: $(Agent.TempDirectory)\snapshot
    steps:
    - checkout: none

    - template: ..\snapshot\download.yml
      parameters:
        path: $(snapshot.path)
        snapshot: ${{ parameters.snapshot }}
        codeonly: true

    - template: upgrade.yml
      parameters:
        path: $(snapshot.path)
        database: ${{ parameters.snapshot.database }}
        version: ${{ platform.version }}
        charset: ${{ platform.charset }}
        preview: ${{ parameters.preview }}

    - template: publish.yml
      parameters:
        path: $(snapshot.path)
        database: ${{ parameters.snapshot.database }}
        type: empty
        version: ${{ platform.version }}
        charset: ${{ platform.charset }}
```

## Upgrade

The `upgrade.yml` template upgrades a database to the specified platform version target by first checking whether an upgrade is required, and if so downloading the fresh empty image for the platform from which updated binaries are copied, followed by a major database upgrade if required. A meta certify is then run to check for any metamodel issues, with a meta repair performed automatically if any are found.

```yaml
parameters:
- name: path
  type: string

- name: database
  type: string

- name: version
  type: string

- name: charset
  type: string

- name: condition
  type: string
  default: succeeded()

- name: preview
  type: boolean
  default: false

steps:
  - powershell: |
      $verinfo = (bin\jverinfo out=stdout binmask=jade.exe sysmask=. datmask=. libmask=. noThinClients noExtraDirs) | Select-String -Pattern '(?m)^jade\.exe\s*(?<version>\d+\.\d+\.\d+)\.\d+.*-(?<charset>ansi|unicode).*$'
      $version = $verinfo | ForEach-Object { return $($_.Matches[0].Groups['version'].Value); }
      $charset = $verinfo | ForEach-Object { return $($_.Matches[0].Groups['charset'].Value); }
      Write-Host "Current Version: $version, Charset: $charset"
      if ($charset -ne "${{ parameters.charset }}") {
        Write-Host "Converting database is not supported"
        exit 1
      }
      $current = [System.Version]$version
      $latest = [System.Version]"${{ parameters.version }}"
      if ($current -ne $latest) {
        if ($current.Major -gt $latest.Major) {
          Write-Host "Major downgrades are not supported"
          exit 1
        }
        elseif ($current.Major -lt $latest.Major) {
          Write-Host "Major Upgrade Required"
          $major_upgrade = $true
        }
        else {
          Write-Host "Minor Upgrade Required"
        }
        $upgrade = $true
      }
      else {
        Write-Host "No Upgrade Required"
      }
      Write-Host "##vso[task.setvariable variable=major_upgrade]$major_upgrade"
      Write-Host "##vso[task.setvariable variable=upgrade]$upgrade"
      Write-Host "##vso[task.setvariable variable=metarepair]$false"
    displayName: "Check Version"
    workingDirectory: ${{ parameters.path }}
    condition: ${{ parameters.condition }}

  - template: download.yml
    parameters:
      path: $(Agent.TempDirectory)\fresh
      database: fresh
      type: empty
      version: ${{ parameters.version }}
      charset: ${{ parameters.charset }}
      condition: and(succeeded(), eq(variables.upgrade, true))

  - powershell: |
      Copy-Item -Path "$(Agent.TempDirectory)\fresh\bin\*" -Destination .\bin -Recurse -Force
    displayName: "Upgrade Server Binaries"
    workingDirectory: ${{ parameters.path }}
    condition: and(succeeded(), eq(variables.upgrade, true))

  - powershell: |
      function upgrade_client_binaries {
        param([string]$environment_type)
        $source = "$(Agent.TempDirectory)\fresh\$environment_type"
        $destination = ".\$environment_type"
        if (Test-Path $source) {
          New-Item -Path $destination -ItemType Directory -Force | Out-Null
          Copy-Item -Path $source\* -Destination $destination -Recurse -Force
        }
      }
      upgrade_client_binaries -environment_type "i686-msoft-win32-ansi"
      upgrade_client_binaries -environment_type "x64-msoft-win64-ansi"
    displayName: "Upgrade Client Binaries"
    workingDirectory: ${{ parameters.path }}
    condition: and(succeeded(), eq(variables.upgrade, true))

  - powershell: |
      Move-Item -Path "$(Agent.TempDirectory)\fresh\system\_monitor.dat" -Destination .\system -Force
      Out-File -FilePath "jade.ini"
      bin\jdbupgrade path= "$pwd\system" ini= "$pwd\jade.ini" action=UpgradeDB JadeLog.UseLogServer=true JadeLog.LogServer=Console JadeLog.DisplayApplicationMessages=true
    displayName: "Upgrade Database"
    workingDirectory: ${{ parameters.path }}
    condition: and(succeeded(), eq(variables.major_upgrade, true))
    continueOnError: ${{ parameters.preview }}

  - powershell: |
      $null = New-Item -Path logs\metacert -ItemType Directory
      Out-File -FilePath "jade.ini"
      bin\jadclient path= "$pwd\system" ini= "$pwd\jade.ini" schema=RootSchema app=JadeLogicalCertifierNonGui server=singleUser endJade operation=certifyMeta logDir= "$pwd\logs\metacert"
      if ($lastexitcode -eq 1182)
      {
        Write-Host "##vso[task.logissue type=warning]Meta certify errors encountered"
        Write-Host "##vso[task.setvariable variable=metarepair]$true"
        exit 0
      }
    displayName: "Meta Certify"
    workingDirectory: ${{ parameters.path }}
    continueOnError: true
    condition: and(succeeded(), eq(variables.upgrade, true))

  - powershell: |
      bin\jadclient path= "$pwd\system" ini= "$pwd\jade.ini" schema=RootSchema app=JadeLogicalCertifierNonGui server=singleUser endJade operation=repair logDir= "$pwd\logs\metacert"
    displayName: "Meta Repair"
    workingDirectory: ${{ parameters.path }}
    continueOnError: true
    condition: and(succeeded(), eq(variables.metarepair, true))

  - publish: ${{ parameters.path }}\logs
    artifact: ${{ parameters.database }}_upgrade_${{ replace(parameters.version, '.', '_') }}_${{ parameters.charset }}_logs
    condition: and(succeededOrFailed(), eq(variables.upgrade, true))
    displayName: Publish Logs
```
