mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Made migration irreversable, support '$variable' syntax
This commit is contained in:
parent
4a7560c7a5
commit
da137aaeb8
8 changed files with 38 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
|||
class MigrateHipchatAndEfAgentToLiquid < ActiveRecord::Migration
|
||||
def change
|
||||
def up
|
||||
Agent.where(:type => 'Agents::HipchatAgent').each do |agent|
|
||||
LiquidMigrator.convert_all_agent_options(agent)
|
||||
end
|
||||
|
@ -8,4 +8,8 @@ class MigrateHipchatAndEfAgentToLiquid < ActiveRecord::Migration
|
|||
agent.save
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
class MigratePushbulletAgentToLiquid < ActiveRecord::Migration
|
||||
def change
|
||||
def up
|
||||
Agent.where(:type => 'Agents::PushbulletAgent').each do |agent|
|
||||
LiquidMigrator.convert_all_agent_options(agent)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
class MigrateJabberAgentToLiquid < ActiveRecord::Migration
|
||||
def change
|
||||
def up
|
||||
Agent.where(:type => 'Agents::JabberAgent').each do |agent|
|
||||
LiquidMigrator.convert_all_agent_options(agent)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
class MigrateDataOutputAgentToLiquid < ActiveRecord::Migration
|
||||
def change
|
||||
def up
|
||||
Agent.where(:type => 'Agents::DataOutputAgent').each do |agent|
|
||||
LiquidMigrator.convert_all_agent_options(agent)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
class MigrateTranslationAgentToLiquid < ActiveRecord::Migration
|
||||
def change
|
||||
def up
|
||||
Agent.where(:type => 'Agents::TranslationAgent').each do |agent|
|
||||
agent.options['content'] = LiquidMigrator.convert_hash(agent.options['content'], {:merge_path_attributes => true, :leading_dollarsign_is_jsonpath => true})
|
||||
agent.save
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class MigrateTwitterPublishAgentToLiquid < ActiveRecord::Migration
|
||||
def change
|
||||
def up
|
||||
Agent.where(:type => 'Agents::TwitterPublishAgent').each do |agent|
|
||||
if (message = agent.options.delete('message_path')).present?
|
||||
agent.options['message'] = "{{#{message}}}"
|
||||
|
@ -7,4 +7,8 @@ class MigrateTwitterPublishAgentToLiquid < ActiveRecord::Migration
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration, "Cannot revert migration to Liquid templating"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -52,11 +52,15 @@ module LiquidMigrator
|
|||
|
||||
def self.convert_json_path(string, filter = "")
|
||||
check_path(string)
|
||||
"{{#{string[2..-1]}#{filter}}}"
|
||||
if string.start_with? '$.'
|
||||
"{{#{string[2..-1]}#{filter}}}"
|
||||
else
|
||||
"{{#{string[1..-1]}#{filter}}}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_path(string)
|
||||
if string !~ /\A(\$\.)?(\w+\.)*(\w+)\Z/
|
||||
if string !~ /\A(\$\.?)?(\w+\.)*(\w+)\Z/
|
||||
raise "JSONPath '#{string}' is too complex, please check your migration."
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,10 +5,12 @@ describe LiquidMigrator do
|
|||
it "should work" do
|
||||
LiquidMigrator.convert_string("$.data", true).should == "{{data}}"
|
||||
LiquidMigrator.convert_string("$.data.test", true).should == "{{data.test}}"
|
||||
LiquidMigrator.convert_string("$first_title", true).should == "{{first_title}}"
|
||||
end
|
||||
|
||||
it "should ignore strings which just contain a JSONPath" do
|
||||
LiquidMigrator.convert_string("$.data").should == "$.data"
|
||||
LiquidMigrator.convert_string("$first_title").should == "$first_title"
|
||||
LiquidMigrator.convert_string(" $.data", true).should == " $.data"
|
||||
LiquidMigrator.convert_string("lorem $.data", true).should == "lorem $.data"
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue