Skip to content

Commit

Permalink
Improved migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
martini committed Sep 11, 2017
1 parent 714cede commit 7d76805
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class OutOfOffice < ActiveRecord::Migration[4.2]
class OutOfOffice2 < ActiveRecord::Migration[4.2]
def up

# return if it's a new setup
Expand All @@ -9,6 +9,18 @@ def up
Overview.reset_column_information
end

if !ActiveRecord::Base.connection.column_exists?(:users, :out_of_office)
add_column :users, :out_of_office, :boolean, null: false, default: false
add_column :users, :out_of_office_start_at, :date, null: true
add_column :users, :out_of_office_end_at, :date, null: true
add_column :users, :out_of_office_replacement_id, :integer, null: true

add_index :users, [:out_of_office, :out_of_office_start_at, :out_of_office_end_at], name: 'index_out_of_office'
add_index :users, [:out_of_office_replacement_id]
add_foreign_key :users, :users, column: :out_of_office_replacement_id
User.reset_column_information
end

role_ids = Role.with_permissions(['ticket.agent']).map(&:id)
overview_role = Role.find_by(name: 'Agent')
Overview.create_or_update(
Expand Down Expand Up @@ -41,18 +53,6 @@ def up
created_by_id: 1,
)

if !ActiveRecord::Base.connection.column_exists?(:users, :out_of_office)
add_column :users, :out_of_office, :boolean, null: false, default: false
add_column :users, :out_of_office_start_at, :date, null: true
add_column :users, :out_of_office_end_at, :date, null: true
add_column :users, :out_of_office_replacement_id, :integer, null: true

add_index :users, [:out_of_office, :out_of_office_start_at, :out_of_office_end_at], name: 'index_out_of_office'
add_index :users, [:out_of_office_replacement_id]
add_foreign_key :users, :users, column: :out_of_office_replacement_id
User.reset_column_information
end

Cache.clear
end
end

0 comments on commit 7d76805

Please sign in to comment.