Skip to content

Commit

Permalink
Reset HEAD to first commit and reapply changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sashadev-sky committed Feb 9, 2019
1 parent e6f66b0 commit 29e50a0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
16 changes: 16 additions & 0 deletions config/initializers/column_definition.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# prior to MySQL5.7, MySQL would silently convert a column that is part of a primary key and is
# DEFAULT NULL into NOT NULL with a default value of 0 (non standard behavior and not a recommended
# practice) As of MySQL 5.7, this column is converted to NOT NULL, but without a default value,
# throwing an error.

# the below customization both prevents that error and standardizes all of the DBs primary key data
# with a SQL compliant syntax. All the primary keys will be sequential numbers starting from 1.

# Plese keep in mind the compatability of this initializer with your db - if you do not want
# all of your primary keys to be sequential numbers then you can customize this function further

# or, alternatively,

# This can also be removed if DEFAULT NULL is removed from all columns;
# Read more at https://github.com/publiclab/mapknitter/pull/323

class ActiveRecord::ConnectionAdapters::ColumnDefinition
def sql_type
type.to_sym == :primary_key ? 'int(11) auto_increment PRIMARY KEY' : base.type_to_sql(type.to_sym, limit, precision, scale) rescue type
Expand Down
32 changes: 32 additions & 0 deletions config/initializers/duration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# pulled from https://github.com/rails/rails/blob/v3.2.22.5/activesupport/lib/active_support/core_ext/numeric/time.rb

class Numeric
def days
ActiveSupport::Duration.new(24.hours * self, [[:days, self]])
end
alias :day :days

def weeks
ActiveSupport::Duration.new(7.days * self, [[:days, self * 7]])
end
alias :week :weeks

def fortnights
ActiveSupport::Duration.new(2.weeks * self, [[:days, self * 14]])
end
alias :fortnight :fortnights
end

# pulled from https://github.com/rails/rails/blob/v3.2.22.5/activesupport/lib/active_support/core_ext/integer/time.rb

class Integer
def months
ActiveSupport::Duration.new(30.days * self, [[:months, self]])
end
alias :month :months

def years
ActiveSupport::Duration.new(365.25.days * self, [[:years, self]])
end
alias :year :years
end
28 changes: 28 additions & 0 deletions config/initializers/visitor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# this is a customization created to bridge incompatabilities when upgrading Ruby 2.1.2
# to 2.4.4 with Rails 3.2.

#explanation
# Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005
# Ruby ~2.3 `1234.class` is `Fixnum` and `123456789012345678901234567890.class` is `Bignum`.
# Ruby 2.4+ `1234.class` is `Integer` and `123456789012345678901234567890.class` is `Integer`.

# So for compatability with 2.4 arel defined a visit_Integer method

# Arel is now bundled in the Active Record gem, and maintained in the rails/rails repository.
# This code can be deleted on update to `activerecord >= 6.0`, which is available in Rails 6.0

module Arel
module Visitors
class DepthFirst < Arel::Visitors::Visitor
alias :visit_Integer :terminal
end

class Dot < Arel::Visitors::Visitor
alias :visit_Integer :visit_String
end

class ToSql < Arel::Visitors::Visitor
alias :visit_Integer :literal
end
end
end

0 comments on commit 29e50a0

Please sign in to comment.