lib/schema_moves.rb in landable-1.13.1 vs lib/schema_moves.rb in landable-1.13.2
- old
+ new
@@ -1,23 +1,23 @@
module SchemaMoves
module Helpers
def create_schema(schema)
connection = ActiveRecord::Base.connection
- sql = %{
+ sql = %(
CREATE SCHEMA #{schema};
- }
+ )
puts "Creating #{schema} schema"
connection.execute sql
end
def drop_schema(schema)
connection = ActiveRecord::Base.connection
- sql = %{
+ sql = %(
DROP SCHEMA #{schema};
- }
+ )
puts "Dropping #{schema} schema"
connection.execute sql
end
def move_objects(from_schema, to_schema, relkind, object_type)
@@ -33,14 +33,14 @@
AND o.relkind = '#{relkind}'
ORDER BY o.relname
")
objects.each do |object|
- sql = %{
+ sql = %(
ALTER #{object_type} #{from_schema}.#{object['relname']}
SET SCHEMA #{to_schema}
- }
+ )
puts "Moving #{from_schema}.#{object['relname']} TO #{to_schema}"
connection.execute sql
end
end
@@ -127,11 +127,11 @@
CREATE TRIGGER #{new_schema}_page_revisions__no_update
BEFORE UPDATE OF notes, is_minor, page_id, author_id, created_at, ordinal ON #{new_schema}.page_revisions
FOR EACH STATEMENT EXECUTE PROCEDURE #{new_schema}.tg_disallow();
}
- puts "Creating new triggers..."
+ puts 'Creating new triggers...'
connection.execute sql
end
def drop_old_triggers(old_schema, new_schema)
connection = ActiveRecord::Base.connection
@@ -146,28 +146,27 @@
DROP FUNCTION IF EXISTS #{old_schema}.pages_revision_ordinal();
DROP FUNCTION IF EXISTS #{old_schema}.template_revision_ordinal();
DROP FUNCTION IF EXISTS #{old_schema}.tg_disallow();
}
- puts "Dropping old triggers..."
+ puts 'Dropping old triggers...'
connection.execute sql
end
def ask(*args, &block)
HighLine.new.ask(*args, &block)
end
def get_schema_names(new = true)
# Always get old schemas
- @old_landable = ask("Enter the OLD main landable schema: ") { |q| q.default = 'landable' }
- @old_traffic = ask("Enter the OLD traffic schema: ") { |q| q.default = 'landable_traffic' }
+ @old_landable = ask('Enter the OLD main landable schema: ') { |q| q.default = 'landable' }
+ @old_traffic = ask('Enter the OLD traffic schema: ') { |q| q.default = 'landable_traffic' }
# Only ask for new names if new == true
- if new
- @new_landable = ask("Enter the NEW main landable schema: ") { |q| q.default = "#{appname}_landable" }
- @new_traffic = ask("Enter the NEW traffic schema: ") { |q| q.default = "#{appname}_landable_traffic" }
- end
+ return unless new
+ @new_landable = ask('Enter the NEW main landable schema: ') { |q| q.default = "#{appname}_landable" }
+ @new_traffic = ask('Enter the NEW traffic schema: ') { |q| q.default = "#{appname}_landable_traffic" }
end
def create_schemas
create_schema @new_landable
create_schema @new_traffic
@@ -193,11 +192,11 @@
drop_schema @old_traffic
end
def want_to_drop_old_schemas?
drop = nil
- until ['yes', 'no'].include?(drop.to_s.downcase)
- drop = ask("Would you like to drop the old schemas? (Yes or No)") { |q| q.default = 'no' }
+ until %w(yes no).include?(drop.to_s.downcase)
+ drop = ask('Would you like to drop the old schemas? (Yes or No)') { |q| q.default = 'no' }
end
drop.to_s.downcase == 'yes'
end
def appname