-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
class MakeMaintenanceZoneRecord < ActiveRecord::Migration[5.0] | ||
class Zone < ActiveRecord::Base | ||
validates_presence_of :name | ||
validates_uniqueness_of :name | ||
|
||
MAINTENANCE_ZONE_NAME = "__maintenance__".freeze | ||
end | ||
|
||
def up | ||
say_with_time("Creating Maintenance Zone") do | ||
Zone.create_with(:description => "Maintenance Zone", :visible => false).find_or_create_by!(:name => 'maintenance') | ||
zone = Zone.where(:name => Zone::MAINTENANCE_ZONE_NAME).first | ||
if zone.present? | ||
zone.name = "#{zone.name}_0" | ||
zone.save | ||
end | ||
|
||
Zone.create_with(:description => "Maintenance Zone", :visible => false).find_or_create_by!(:name => Zone::MAINTENANCE_ZONE_NAME) | ||
end | ||
end | ||
|
||
def down | ||
say_with_time("Deleting Maintenance Zone") do | ||
Zone.where(:name => 'maintenance').where(:visible => false).destroy_all | ||
Zone.where(:name => Zone::MAINTENANCE_ZONE_NAME).where(:visible => false).destroy_all | ||
|
||
orig = Zone.where(:name => "#{Zone::MAINTENANCE_ZONE_NAME}_0").first | ||
if orig.present? | ||
orig.name = orig.name[0..orig.name.size - 3] | ||
orig.save | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters