Skip to content

Commit

Permalink
remove hair_trigger gem
Browse files Browse the repository at this point in the history
it's unused

also remove support for automatically keeping things up to date between
and pre- and post- migrations for the Role migration, and ContextExternalToolPlacements

Change-Id: I80b5eb20399b402c38cea7c1051b099ad4ef3c80
Reviewed-on: https://gerrit.instructure.com/101891
Tested-by: Jenkins
Reviewed-by: Tyler Pickett <[email protected]>
Reviewed-by: Simon Williams <[email protected]>
Product-Review: Cody Cutrer <[email protected]>
QA-Review: Cody Cutrer <[email protected]>
  • Loading branch information
ccutrer committed Feb 14, 2017
1 parent f337911 commit 4cce1cb
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 339 deletions.
5 changes: 2 additions & 3 deletions Gemfile.d/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@
gem 'inst-jobs', '0.11.10'
gem 'rufus-scheduler', '3.3.3', require: false
gem 'ffi', '1.9.14', require: false
gem 'hairtrigger', '0.2.17'
gem 'ruby2ruby', '2.0.8', require: false
gem 'ruby_parser', '3.8.3', require: false
gem 'hashery', '2.1.2', require: false
gem 'highline', '1.7.8', require: false
gem 'httparty', '0.14.0'
gem 'i18n', '0.7.0'
gem 'i18nliner', '0.0.12'
gem 'ruby2ruby', '2.0.8', require: false
gem 'ruby_parser', '3.8.3', require: false
gem 'icalendar', '1.5.4', require: false
gem 'ims-lti', '2.1.0.beta.4', require: 'ims'
gem 'json', '2.0.3'
Expand Down
25 changes: 25 additions & 0 deletions config/initializers/postgresql_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,31 @@ def add_schema_to_search_path(schema)
end
end

# we no longer use any triggers, so we removed hair_trigger,
# but don't want to go modifying all the old migrations, so just
# make them dummies
class CreateTriggerChain
def on(*)
self
end

def after(*)
self
end

def where(*)
self
end
end

def create_trigger(*)
CreateTriggerChain.new
end

def drop_trigger(name, table, generated: false)
execute("DROP TRIGGER IF EXISTS #{name} ON #{quote_table_name(table)};\nDROP FUNCTION IF EXISTS #{quote_table_name(name)}();\n")
end

private

OID = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID
Expand Down
16 changes: 1 addition & 15 deletions db/migrate/20140530195058_add_context_to_content_exports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,7 @@ def self.up

remove_foreign_key :content_exports, :courses

if connection.adapter_name == 'PostgreSQL'
create_trigger("content_export_after_insert_row_when_context_id_is_null__tr", :generated => true).
on("content_exports").
after(:insert).
where("NEW.context_id IS NULL") do
<<-SQL_ACTIONS
UPDATE content_exports
SET context_id = NEW.course_id
WHERE id = NEW.id
SQL_ACTIONS
end
execute("ALTER FUNCTION #{connection.quote_table_name('content_export_after_insert_row_when_context_id_is_null__tr')}() SET search_path TO #{Shard.current.name}")

execute("ALTER TABLE #{ContentExport.quoted_table_name} ALTER context_type SET DEFAULT 'Course'")
end
change_column_default :content_exports, :context_type, 'Course'

while ContentExport.where("context_id IS NULL AND course_id IS NOT NULL").limit(1000).
update_all("context_id = course_id, context_type = 'Course'") > 0; end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,6 @@ def up

add_foreign_key :context_external_tool_placements, :context_external_tools

# create some triggers so nothing falls through the cracks
if connection.adapter_name == 'PostgreSQL'

EXTENSION_TYPES.each do |type|
column = "has_#{type}"
create_trigger("tool_after_insert_#{type}_is_true__tr", :generated => true).
on("context_external_tools").
after(:insert).
where("NEW.#{column}") do
<<-SQL_ACTIONS
INSERT INTO context_external_tool_placements(placement_type, context_external_tool_id)
VALUES ('#{type}', NEW.id)
SQL_ACTIONS
end
connection.set_search_path_on_function("tool_after_insert_#{type}_is_true__tr")

create_trigger("tool_after_update_#{type}_is_true__tr", :generated => true).
on("context_external_tools").
after(:update).
where("NEW.#{column}") do
<<-SQL_ACTIONS
INSERT INTO context_external_tool_placements(placement_type, context_external_tool_id)
SELECT '#{type}', NEW.id
WHERE NOT EXISTS(
SELECT 1 FROM context_external_tool_placements WHERE placement_type = '#{type}' AND context_external_tool_id = NEW.id
)
SQL_ACTIONS
end
connection.set_search_path_on_function("tool_after_update_#{type}_is_true__tr")


create_trigger("tool_after_update_#{type}_is_false__tr", :generated => true).
on("context_external_tools").
after(:update).
where("NOT NEW.#{column}") do
<<-SQL_ACTIONS
DELETE FROM context_external_tool_placements WHERE placement_type = '#{type}' AND context_external_tool_id = NEW.id
SQL_ACTIONS
end
connection.set_search_path_on_function("tool_after_update_#{type}_is_false__tr")
end
end

# now populate the placements
EXTENSION_TYPES.each do |type|
column = :"has_#{type}"
Expand Down
121 changes: 0 additions & 121 deletions db/migrate/20140903152155_add_role_id_columns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,127 +37,6 @@ def up
) LIMIT 1
)"
Role.connection.update(delete_duplicate_roles_sql)

# create triggers to handle things until the postdeploy runs
create_trigger("account_user_after_insert_set_role_id__tr", :generated => true).
on("account_users").
after(:insert).
where("NEW.role_id IS NULL") do
<<-SQL_ACTIONS
UPDATE account_users
SET role_id = (
SELECT id FROM roles WHERE roles.name = NEW.membership_type AND (
roles.workflow_state = 'built_in' OR (
roles.workflow_state = 'active' AND (
roles.account_id = NEW.account_id OR
roles.account_id IN (
WITH RECURSIVE t AS (
SELECT * FROM accounts WHERE id=NEW.account_id
UNION
SELECT accounts.* FROM accounts INNER JOIN t ON accounts.id=t.parent_account_id
)
SELECT id FROM t
)
)
)
) LIMIT 1
) WHERE id = NEW.id
SQL_ACTIONS
end
connection.set_search_path_on_function("account_user_after_insert_set_role_id__tr")

create_trigger("account_notification_role_after_insert_set_role_id__tr", :generated => true).
on("account_notification_roles").
after(:insert).
where("NEW.role_id IS NULL") do
<<-SQL_ACTIONS
UPDATE account_notification_roles
SET role_id = (
SELECT id FROM roles WHERE roles.name = NEW.role_type AND (
roles.workflow_state = 'built_in' OR (
roles.workflow_state = 'active' AND (
roles.account_id = (SELECT account_id FROM account_notifications WHERE id=NEW.account_notification_id LIMIT 1) OR
roles.account_id IN (
WITH RECURSIVE t AS (
SELECT * FROM accounts WHERE id=(SELECT account_id FROM account_notifications WHERE id=NEW.account_notification_id LIMIT 1)
UNION
SELECT accounts.* FROM accounts INNER JOIN t ON accounts.id=t.parent_account_id
)
SELECT id FROM t
)
)
)
) LIMIT 1
) WHERE id = NEW.id
SQL_ACTIONS
end
connection.set_search_path_on_function("account_notification_role_after_insert_set_role_id__tr")

create_trigger("enrollment_after_insert_set_role_id_if_role_name__tr", :generated => true).
on("enrollments").
after(:insert).
where("NEW.role_id IS NULL AND NEW.role_name IS NOT NULL") do
<<-SQL_ACTIONS
UPDATE enrollments
SET role_id = (
SELECT id FROM roles WHERE roles.name = NEW.role_name AND (
roles.workflow_state = 'built_in' OR (
roles.workflow_state = 'active' AND (
roles.account_id = (SELECT account_id FROM courses WHERE id=NEW.course_id LIMIT 1) OR
roles.account_id IN (
WITH RECURSIVE t AS (
SELECT * FROM accounts WHERE id=(SELECT account_id FROM courses WHERE id=NEW.course_id LIMIT 1)
UNION
SELECT accounts.* FROM accounts INNER JOIN t ON accounts.id=t.parent_account_id
)
SELECT id FROM t
)
)
)
) LIMIT 1
) WHERE id = NEW.id
SQL_ACTIONS
end
connection.set_search_path_on_function("enrollment_after_insert_set_role_id_if_role_name__tr")

create_trigger("enrollment_after_insert_set_role_id_if_no_role_name__tr", :generated => true).
on("enrollments").
after(:insert).
where("NEW.role_id IS NULL AND NEW.role_name IS NULL") do
<<-SQL_ACTIONS
UPDATE enrollments
SET role_id = (SELECT id FROM roles WHERE roles.workflow_state = 'built_in' AND roles.name = NEW.type LIMIT 1)
WHERE id = NEW.id
SQL_ACTIONS
end
connection.set_search_path_on_function("enrollment_after_insert_set_role_id_if_no_role_name__tr")

create_trigger("role_override_after_insert_set_role_id__tr", :generated => true).
on("role_overrides").
after(:insert).
where("NEW.role_id IS NULL AND NEW.context_type = 'Account'") do
<<-SQL_ACTIONS
UPDATE role_overrides
SET role_id = (
SELECT id FROM roles WHERE roles.name = NEW.enrollment_type AND (
roles.workflow_state = 'built_in' OR (
roles.workflow_state = 'active' AND (
roles.account_id = NEW.context_id OR
roles.account_id IN (
WITH RECURSIVE t AS (
SELECT * FROM accounts WHERE id=NEW.context_id
UNION
SELECT accounts.* FROM accounts INNER JOIN t ON accounts.id=t.parent_account_id
)
SELECT id FROM t
)
)
)
) LIMIT 1
) WHERE id = NEW.id
SQL_ACTIONS
end
connection.set_search_path_on_function("role_override_after_insert_set_role_id__tr")
end

# Populate the role_ids for account_users and role_overrides (and enrollments with custom role_names)
Expand Down
9 changes: 0 additions & 9 deletions lib/tasks/hair_trigger.rake

This file was deleted.

27 changes: 0 additions & 27 deletions spec/integration/hair_trigger_spec.rb

This file was deleted.

5 changes: 0 additions & 5 deletions spec/migrations/add_context_to_content_exports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,18 @@
it "should populate all content exports with course context type and context id" do
skip("PostgreSQL specific") unless ContentExport.connection.adapter_name == 'PostgreSQL'
course1 = course_factory
course2 = course_factory

RemoveCourseIdFromContentExports.down
AddContextToContentExports.down

ContentExport.connection.execute "INSERT INTO #{ContentExport.quoted_table_name}(course_id, workflow_state, created_at, updated_at) VALUES(#{course1.id}, '', '2014-07-07', '2014-07-07')"

AddContextToContentExports.up
ContentExport.connection.execute "INSERT INTO #{ContentExport.quoted_table_name}(course_id, workflow_state, created_at, updated_at) VALUES(#{course2.id}, '', '2014-07-07', '2014-07-07')"
RemoveCourseIdFromContentExports.up

ce1 = course1.content_exports.first
ce2 = course2.content_exports.first
expect(ce1.context_type).to eq 'Course'
ce1.context_id = course1.id
expect(ce2.context_type).to eq 'Course'
expect(ce2.context_id).to eq course2.id
end
end
end
Loading

0 comments on commit 4cce1cb

Please sign in to comment.