Module: QDA::Backend::SQLite::Upgradeable

Defined in:
lib/weft/backend/sqlite/upgradeable.rb

Overview

This module provides support for opening projects created in older versions of Weft.

Instance Method Summary collapse

Instance Method Details

#do_version_format_upgradingObject

This is called when a project is opened. It checks whether any changes need to be made to the storage format.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/weft/backend/sqlite/upgradeable.rb', line 10

def do_version_format_upgrading()
  version = get_preference('LastModifiedVersion') || 
    get_preference('CreateVersion')

  # don't do anything to those created in testing versions, just
  # mark as last-opened in this version.
  if version == QDA::Version.default_version()
    save_preference('LastModifiedVersion', WEFT_VERSION)
  end

  # 0.9.4 and earlier - add indexes to tables
  if version.nil?
    @dbh.execute_batch(QDA::Backend::SQLite::Schema::SCHEMA_INDEXES)
  end

  # 0.9.5 and earlier - upgrade the category tree storage format
  if version.nil? || version == '0.9.5'
    legacy_category_tree_storage()
    save_preference('LastModifiedVersion', WEFT_VERSION)
  end
  
  begin
    old_codes = get_root_category('CODES')
    old_codes.name = 'CATEGORIES'
    save_category(old_codes)
  rescue QDA::NotFoundError
  end
end

#legacy_category_tree_storageObject

This is a change from 0.9.5 -> 0.9.6; Category tree structure used to be stored in XML in the database, is now stored as a marshalled CategoryTree pure ruby object.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/weft/backend/sqlite/upgradeable.rb', line 42

def legacy_category_tree_storage()
  @cat_tree = CategoryTree.new()

  build_cat = Proc.new do | elem, parent |
    cat =  @cat_tree.add( parent,
                          elem.attributes['dbid'].to_i,
                          elem.attributes['name'] )
    elem.each_child { | kid | build_cat.call(kid, cat.dbid) }
  end

  xml  = @dbh.get_first_value("SELECT xml FROM category_structure")
  doc = REXML::Document.new(xml)
  doc.root.each_child { | elem | build_cat.call(elem, nil) }

  @dbh.transaction do
    xml = @cat_tree.serialise
    @dbh.execute("UPDATE category_structure SET xml = ? ", xml )
  end
end