:thinking_face: Migration seems to work. Have a blinky test, though.
parent
518ffca00e
commit
f4521b56fc
|
@ -14,26 +14,25 @@
|
|||
# automagically run if the API determines a sequence is out of date.
|
||||
module SequenceMigration
|
||||
class Base
|
||||
# When we last ran a compaction (22 NOV 17), the highest version number was
|
||||
# this:
|
||||
HIGHEST_VERSION_AT_TIME_OF_LAST_COMPACTION = 4
|
||||
# MAGIC NUMBER. Assume that versionless sequences are "legacy" sequences
|
||||
# from a time before versioning. Since the lowest migration version is 0, a
|
||||
# version of -1 will require all migrations to run.
|
||||
LEGACY_VERSION = -1
|
||||
VERSION = "YOU MUST CHANGE THIS!!!"
|
||||
# When we last ran a compaction (22 NOV 17), the highest version number was
|
||||
# this:
|
||||
HIGHEST_VERSION_AT_TIME_OF_LAST_COMPACTION = 4
|
||||
# I shouldn't need to do this, as this method comes with ActiveSupport, but
|
||||
# it's acting weird with autoloading right now :shipit:. TODO: See if there
|
||||
# is a way to automatically infer all classes
|
||||
def self.descendants
|
||||
[]
|
||||
[SequenceSpeedChange]
|
||||
end
|
||||
|
||||
def self.latest_version
|
||||
self
|
||||
.descendants
|
||||
.map { |k| k::VERSION }
|
||||
.tap { |x| x.push(HIGHEST_VERSION_AT_TIME_OF_LAST_COMPACTION) }
|
||||
.each { |v|
|
||||
if v < HIGHEST_VERSION_AT_TIME_OF_LAST_COMPACTION
|
||||
raise "VERSION TOO LOW"
|
||||
|
@ -52,7 +51,7 @@ module SequenceMigration
|
|||
expected_version = self.class::VERSION - 1
|
||||
incorrect_version = sequence_version != expected_version
|
||||
if incorrect_version
|
||||
raise "Version must be #{expected_version} to run #{self.class}"
|
||||
raise "Version must be #{expected_version} to run #{self.class}. Got: #{sequence_version}"
|
||||
end
|
||||
Rollbar.info "RUNNING MIGRATION #{sequence_version} on #{sequence.id}"
|
||||
end
|
||||
|
|
|
@ -11,9 +11,11 @@ module SequenceMigration
|
|||
"find_home" ]
|
||||
|
||||
def up
|
||||
CeleryScript::TreeClimber.travel(sequence.body, ->(n) {
|
||||
# binding.pry
|
||||
})
|
||||
sequence
|
||||
.body
|
||||
.map do |x|
|
||||
x[:args][:speed] = 100 if MUST_BE_100.include?(x.try(:[], :kind))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,6 +46,8 @@ class Sequence < ApplicationRecord
|
|||
before_validation :set_defaults
|
||||
|
||||
def set_defaults
|
||||
self.args ||= {}
|
||||
self.args["version"] ||= SequenceMigration::Base.latest_version
|
||||
self.color ||= "gray"
|
||||
self.kind ||= "sequence"
|
||||
end
|
||||
|
|
|
@ -6,7 +6,9 @@ FactoryBot.define do
|
|||
color { Sequence::COLORS.sample }
|
||||
device
|
||||
kind "sequence"
|
||||
args({})
|
||||
args({
|
||||
version: 4 # Hard coding it for now - RC Nov 22
|
||||
})
|
||||
body([])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -101,7 +101,7 @@ describe CeleryScript::Corpus do
|
|||
it "serializes into JSON" do
|
||||
result = JSON.parse(corpus.to_json)
|
||||
|
||||
expect(result["tag"]).to eq(4)
|
||||
expect(result["tag"]).to eq(5)
|
||||
expect(result["args"]).to be_kind_of(Array)
|
||||
expect(result["nodes"]).to be_kind_of(Array)
|
||||
expect(result["nodes"].sample.keys.sort).to eq(["allowed_args",
|
||||
|
|
|
@ -1,7 +1,66 @@
|
|||
require 'spec_helper'
|
||||
|
||||
FIXTURE = JSON.parse('[
|
||||
{
|
||||
"kind":"move_absolute",
|
||||
"args":{
|
||||
"location":{
|
||||
"kind":"coordinate",
|
||||
"args":{
|
||||
"x":0,
|
||||
"y":0,
|
||||
"z":0
|
||||
}
|
||||
},
|
||||
"offset":{
|
||||
"kind":"coordinate",
|
||||
"args":{
|
||||
"x":0,
|
||||
"y":0,
|
||||
"z":0
|
||||
}
|
||||
},
|
||||
"speed":200
|
||||
},
|
||||
"uuid":"c1d740a1-5807-42dd-949f-3f28993d96bc"
|
||||
},
|
||||
{
|
||||
"kind":"move_relative",
|
||||
"args":{
|
||||
"x":0,
|
||||
"y":0,
|
||||
"z":0,
|
||||
"speed":200
|
||||
},
|
||||
"uuid":"003101ee-63b6-4a41-bfe8-cdd6b95480ea"
|
||||
},
|
||||
{
|
||||
"kind":"find_home",
|
||||
"args":{
|
||||
"axis":"all",
|
||||
"speed":200
|
||||
},
|
||||
"uuid":"7be663f7-56ff-4b77-9356-49e965a8fa87"
|
||||
}
|
||||
]')
|
||||
|
||||
describe SequenceMigration do
|
||||
it 'has a latest version' do
|
||||
expect(SequenceMigration::Base.latest_version).to eq(4)
|
||||
expect(SequenceMigration::Base.latest_version).to eq(5)
|
||||
end
|
||||
|
||||
it 'updates speed on all the things < v5' do
|
||||
s = FactoryBot.create(:sequence)
|
||||
s.args["version"] = 4
|
||||
s.body = FIXTURE
|
||||
expect(s.body[0]["args"]["speed"]).to eq(200)
|
||||
expect(s.body[1]["args"]["speed"]).to eq(200)
|
||||
expect(s.body[2]["args"]["speed"]).to eq(200)
|
||||
|
||||
s.maybe_migrate
|
||||
|
||||
expect(s.body[0]["args"]["speed"]).to eq(100)
|
||||
expect(s.body[1]["args"]["speed"]).to eq(100)
|
||||
expect(s.body[2]["args"]["speed"]).to eq(100)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,6 @@ describe Sequence do
|
|||
|
||||
it "picks random values" do
|
||||
FactoryBot.create(:sequence)
|
||||
3.times { expect(Sequence.random).to be_kind_of(Sequence) }
|
||||
5.times { expect(Sequence.random).to be_kind_of(Sequence) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue