source_migrations.bs

import "pkg:/source/utils/conditional.bs"
import "pkg:/source/utils/misc.bs"

' @fileoverview Functions that update the registry based on the last run version and the currently running version

' client version that the registry was changed in a non-backwards compatible way
const BASE_MIGRATION = "0.1.0"

' Run all necessary registry mirations on the "global" JellyRock registry section
sub runGlobalMigrations()
  appLastRunVersion = m.global.app.lastRunVersion
  ' BASE_MIGRATION
  if isValid(appLastRunVersion) and not versionChecker(appLastRunVersion, BASE_MIGRATION)
    ' last app version used < BASE_MIGRATION
    m.wasMigrated = true
    print `Running ${BASE_MIGRATION} global registry migrations`

  end if
end sub

sub runRegistryUserMigrations()
  regSections = getRegistrySections()
  for each section in regSections
    if LCase(section) <> "jellyrock"
      reg = CreateObject("roRegistrySection", section)
      lastRunVersion = invalid
      if reg.exists("LastRunVersion")
        lastRunVersion = reg.read("LastRunVersion")
      end if

      ' BASE_MIGRATION
      if isValid(lastRunVersion) and not versionChecker(lastRunVersion, BASE_MIGRATION)
        m.wasMigrated = true
        print `Running Registry Migration for ${BASE_MIGRATION} for userid: ${section}`

      end if
    end if
  end for
end sub