diff --git a/config/initializers/column_definition.rb b/config/initializers/column_definition.rb index 31fa564cc..ec8438adf 100644 --- a/config/initializers/column_definition.rb +++ b/config/initializers/column_definition.rb @@ -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 diff --git a/config/initializers/duration.rb b/config/initializers/duration.rb new file mode 100644 index 000000000..d38feb3b3 --- /dev/null +++ b/config/initializers/duration.rb @@ -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 \ No newline at end of file diff --git a/config/initializers/visitor.rb b/config/initializers/visitor.rb new file mode 100644 index 000000000..9f93ea9a1 --- /dev/null +++ b/config/initializers/visitor.rb @@ -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 \ No newline at end of file