Module: StructuredStore::MigrationHelper

Defined in:
lib/structured_store/migration_helper.rb

Overview

Helper method for creating versioned schemas

Instance Method Summary collapse

Instance Method Details

#create_versioned_schema(name, version) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/structured_store/migration_helper.rb', line 4

def create_versioned_schema(name, version)
  reversible do |dir|
    dir.up do
      json_schema_string = Rails.root.join("db/structured_store_versioned_schemas/#{name}-#{version}.json").read
      json_schema = JSON.parse(json_schema_string)
      ::StructuredStore::VersionedSchema.create(
        name: name,
        version: version,
        json_schema: json_schema
      )
    end
    dir.down do
      ::StructuredStore::VersionedSchema.where(name: name, version: version).destroy_all
    end
  end
end