Method: GoodData::Model::ProjectCreator.migrate_datasets

Defined in:
lib/gooddata/models/project_creator.rb

.migrate_datasets(spec, opts = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/gooddata/models/project_creator.rb', line 38

def migrate_datasets(spec, opts = {})
  opts = { client: GoodData.connection }.merge(opts)
  dry_run = opts[:dry_run]
  replacements = opts['maql_replacements'] || opts[:maql_replacements] || {}
  update_preference = opts[:update_preference]
  exist_fallback_to_hard_sync_config = !update_preference.nil? && !update_preference[:fallback_to_hard_sync].nil?
  include_maql_fallback_hard_sync = exist_fallback_to_hard_sync_config && GoodData::Helpers.to_boolean(update_preference[:fallback_to_hard_sync])

  _, project = GoodData.get_client_and_project(opts)

  bp = ProjectBlueprint.new(spec)
  response = opts[:maql_diff]
  unless response
    maql_diff_params = [:includeGrain]
    maql_diff_params << :excludeFactRule if opts[:exclude_fact_rule]
    maql_diff_params << :includeDeprecated if opts[:include_deprecated]
    maql_diff_params << :includeMaqlFallbackHardSync if include_maql_fallback_hard_sync

    maql_diff_time = Benchmark.realtime do
      response = project.maql_diff(blueprint: bp, params: maql_diff_params)
    end
    GoodData.logger.debug("MAQL diff took #{maql_diff_time.round} seconds")
  end

  GoodData.logger.debug("projectModelDiff") { response.pretty_inspect }
  chunks = response['projectModelDiff']['updateScripts']
  return [], nil if chunks.empty?

  ca_maql = response['projectModelDiff']['computedAttributesScript'] if response['projectModelDiff']['computedAttributesScript']
  ca_chunks = ca_maql && ca_maql['maqlDdlChunks']

  maqls = include_maql_fallback_hard_sync ? pick_correct_chunks_hard_sync(chunks, opts) : pick_correct_chunks(chunks, opts)
  replaced_maqls = apply_replacements_on_maql(maqls, replacements)
  apply_maqls(ca_chunks, project, replaced_maqls, opts) unless dry_run
  [replaced_maqls, ca_maql]
end