Fixing Migration crashes on MySQL/MariaDB & PostgreSQL

This commit is contained in:
Jose D. Gomez R 2019-03-12 17:04:13 -04:00 committed by José D. Gómez R
parent 2a0552d6b2
commit 6cd1de21dd
7 changed files with 78 additions and 38 deletions

View file

@ -2,6 +2,6 @@
class AddAttendedToRegistrations < ActiveRecord::Migration
def change
add_column :registrations, :attended, :boolean, default: 0
add_column :registrations, :attended, :boolean, default: false
end
end

View file

@ -2,6 +2,6 @@
class AddScheduleChangesToCallForPapers < ActiveRecord::Migration
def change
add_column :call_for_papers, :schedule_changes, :boolean, default: 0
add_column :call_for_papers, :schedule_changes, :boolean, default: false
end
end

View file

@ -2,8 +2,16 @@
class CreateVisits < ActiveRecord::Migration
def change
adapter_type = connection.adapter_name.downcase.to_sym
create_table :visits do |t|
t.uuid :visitor_id
case adapter_type
when :postgresql
t.uuid :visitor_id
else
t.integer :visitor_id
end
# the rest are recommended but optional
# simply remove the columns you don't want

View file

@ -2,8 +2,16 @@
class CreateAhoyEvents < ActiveRecord::Migration
def change
adapter_type = connection.adapter_name.downcase.to_sym
create_table :ahoy_events do |t|
t.uuid :visit_id
case adapter_type
when :postgresql
t.uuid :visit_id
else
t.integer :visit_id
end
# user
t.integer :user_id
# add t.string :user_type if polymorphic

View file

@ -6,7 +6,15 @@ class SplitTicketPriceInPriceAndCurrency < ActiveRecord::Migration
end
def change
add_money :tickets, :price
adapter_type = connection.adapter_name.downcase.to_sym
case adapter_type
when :postgresql
add_monetize :tickets, :price
else
add_money :tickets, :price
end
TempTicket.all.each do |ticket|
# Replace currency symbol with ISO Code

View file

@ -2,6 +2,15 @@
class ChangeVisitIdTypeOfAhoyEventsToInteger < ActiveRecord::Migration[5.0]
def change
change_column :ahoy_events, :visit_id, :integer, limit: nil
adapter_type = connection.adapter_name.downcase.to_sym
case adapter_type
when :postgresql
change_column :ahoy_events, :visit_id, :integer, limit: nil, using: "('x' || translate(left(visit_id::text, 18), '-', ''))::bit(32)::int"
else
change_column :ahoy_events, :visit_id, :integer, limit: nil
end
end
end