Skip to content

Commit

Permalink
Merge pull request #2571 from DMPRoadmap/rails5-ar-monkeypatch
Browse files Browse the repository at this point in the history
Rails5 ActiveRecord monkey patch for SchemaDumper
  • Loading branch information
briri committed Jun 24, 2020
2 parents 12dd9c9 + c56895d commit 2848351
Show file tree
Hide file tree
Showing 13 changed files with 235 additions and 129 deletions.
2 changes: 1 addition & 1 deletion app/javascript/src/orgAdmin/conditions/updateConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default function updateConditions(id) {
content.html(e.detail[0].container);
}
setSelectPicker();
webhookForm(data.webhooks, undefined);
webhookForm(e.detail[0].webhooks, undefined);
});

// add condition
Expand Down
19 changes: 10 additions & 9 deletions app/services/org/create_created_plan_service.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# frozen_string_literal: true

#import statements fix Circular dependancy errors due to threading
import OrgDateRangeable
import StatCreatedPlan
import StatCreatedPlan::CreateOrUpdate
import Role
import User
import Plan
import Perm
import Template
# statements fix Circular dependancy errors due to threading
# see: https://github.com/grosser/parallel#nameerror-uninitialized-constant
OrgDateRangeable.class
StatCreatedPlan.class
StatCreatedPlan::CreateOrUpdate.class
Role.class
User.class
Plan.class
Perm.class
Template.class

class Org

Expand Down
17 changes: 9 additions & 8 deletions app/services/org/create_exported_plan_service.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true

#import statements fix Circular dependancy errors
import OrgDateRangeable
import StatExportedPlan
import StatExportedPlan::CreateOrUpdate
import Role
import Plan
import User
import ExportedPlan
# statements fix Circular dependancy errors due to threading
# see: https://github.com/grosser/parallel#nameerror-uninitialized-constant
OrgDateRangeable.class
StatExportedPlan.class
StatExportedPlan::CreateOrUpdate.class
Role.class
Plan.class
User.class
ExportedPlan.class

class Org

Expand Down
11 changes: 6 additions & 5 deletions app/services/org/create_joined_user_service.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# frozen_string_literal: true

#import statements fix Circular dependancy errors due to threading
import OrgDateRangeable
import StatJoinedUser
import StatJoinedUser::CreateOrUpdate
import User
# statements fix Circular dependancy errors due to threading
# see: https://github.com/grosser/parallel#nameerror-uninitialized-constant
OrgDateRangeable.class
StatJoinedUser.class
StatJoinedUser::CreateOrUpdate.class
User.class

class Org

Expand Down
19 changes: 10 additions & 9 deletions app/services/org/create_last_month_created_plan_service.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# frozen_string_literal: true

#import statements fix Circular dependancy errors due to threading
import OrgDateRangeable
import StatCreatedPlan
import StatCreatedPlan::CreateOrUpdate
import Role
import User
import Plan
import Perm
import Template
# statements fix Circular dependancy errors due to threading
# see: https://github.com/grosser/parallel#nameerror-uninitialized-constant
OrgDateRangeable.class
StatCreatedPlan.class
StatCreatedPlan::CreateOrUpdate.class
Role.class
User.class
Plan.class
Perm.class
Template.class


class Org
Expand Down
17 changes: 9 additions & 8 deletions app/services/org/create_last_month_exported_plan_service.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true

#import statements fix Circular dependancy errors
import OrgDateRangeable
import StatExportedPlan
import StatExportedPlan::CreateOrUpdate
import Role
import Plan
import User
import ExportedPlan
# statements fix Circular dependancy errors due to threading
# see: https://github.com/grosser/parallel#nameerror-uninitialized-constant
OrgDateRangeable.class
StatExportedPlan.class
StatExportedPlan::CreateOrUpdate.class
Role.class
Plan.class
User.class
ExportedPlan.class

class Org

Expand Down
11 changes: 6 additions & 5 deletions app/services/org/create_last_month_joined_user_service.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# frozen_string_literal: true

#import statements fix Circular dependancy errors due to threading
import OrgDateRangeable
import StatJoinedUser
import StatJoinedUser::CreateOrUpdate
import User
# statements fix Circular dependancy errors due to threading
# see: https://github.com/grosser/parallel#nameerror-uninitialized-constant
OrgDateRangeable.class
StatJoinedUser.class
StatJoinedUser::CreateOrUpdate.class
User.class

class Org

Expand Down
15 changes: 8 additions & 7 deletions app/services/org/create_last_month_shared_plan_service.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# frozen_string_literal: true

#import statements fix Circular dependancy errors due to threading
import OrgDateRangeable
import StatSharedPlan
import StatSharedPlan::CreateOrUpdate
import User
import Plan
import Role
# statements fix Circular dependancy errors due to threading
# see: https://github.com/grosser/parallel#nameerror-uninitialized-constant
OrgDateRangeable.class
StatSharedPlan.class
StatSharedPlan::CreateOrUpdate.class
User.class
Plan.class
Role.class

class Org

Expand Down
15 changes: 8 additions & 7 deletions app/services/org/create_shared_plan_service.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# frozen_string_literal: true

#import statements fix Circular dependancy errors due to threading
import OrgDateRangeable
import StatSharedPlan
import StatSharedPlan::CreateOrUpdate
import User
import Plan
import Role
# statements fix Circular dependancy errors due to threading
# see: https://github.com/grosser/parallel#nameerror-uninitialized-constant
OrgDateRangeable.class
StatSharedPlan.class
StatSharedPlan::CreateOrUpdate.class
User.class
Plan.class
Role.class

class Org

Expand Down
71 changes: 71 additions & 0 deletions config/initializers/dmproadmap_schema_dumper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: true

module ActiveRecord

# The Rails 5.x SchemaDumper includes an `options:` arrgument on table definitions
# that is not DB agnostic. This Monkey Patch comments out the `options:` section.
#
# TODO: Determine if this is still necessary in Rails 6.x+
class SchemaDumper

# Method definition taken from the 5.2-stable branch of ActiveRecord:
# https://github.com/rails/rails/blob/5-2-stable/activerecord/lib/active_record/schema_dumper.rb
def table(table, stream)
columns = @connection.columns(table)
begin
tbl = StringIO.new

# first dump primary key column
pk = @connection.primary_key(table)

tbl.print " create_table #{remove_prefix_and_suffix(table).inspect}"

case pk
when String
tbl.print ", primary_key: #{pk.inspect}" unless pk == "id"
pkcol = columns.detect { |c| c.name == pk }
pkcolspec = column_spec_for_primary_key(pkcol)
if pkcolspec.present?
tbl.print ", #{format_colspec(pkcolspec)}"
end
when Array
tbl.print ", primary_key: #{pk.inspect}"
else
tbl.print ", id: false"
end

# Commenting out Table Options because they are not DB agnostic
# table_options = @connection.table_options(table)
# if table_options.present?
# tbl.print ", #{format_options(table_options)}"
# end

tbl.puts ", force: :cascade do |t|"

# then dump all non-primary key columns
columns.each do |column|
raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type)
next if column.name == pk
type, colspec = column_spec(column)
tbl.print " t.#{type} #{column.name.inspect}"
tbl.print ", #{format_colspec(colspec)}" if colspec.present?
tbl.puts
end

indexes_in_create(table, tbl)

tbl.puts " end"
tbl.puts

tbl.rewind
stream.print tbl.read
rescue => e
stream.puts "# Could not dump table #{table.inspect} because of following #{e.class}"
stream.puts "# #{e.message}"
stream.puts
end
end

end

end

0 comments on commit 2848351

Please sign in to comment.