Created
February 5, 2015 16:30
-
-
Save loganhasson/403d43f433000bffc566 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
results = ActiveRecord::Base.connection.execute( | |
'select d.github_source, e.* from | |
(select a.github_source, count(*) as count FROM | |
(SELECT DISTINCT github_source FROM assignments) as sources | |
INNER JOIN assignments as a ON sources.github_source = a.github_source group by a.github_source) as d | |
inner join assignments as e on d.github_source = e.github_source where d.count > 1;' | |
) | |
with_content_ids = [] | |
no_content_ids = [] | |
results.each do |result| | |
assignment = Assignment.find(result['id']) | |
if !!result['github_source'].match(/-admin$/) | |
puts "Destroying admin #{assignment.github_source}" | |
assignment.destroy | |
elsif !!result['content_id'] | |
with_content_ids << assignment | |
else | |
no_content_ids << assignment | |
end | |
end | |
no_content_ids.each do |assignment_no_id| | |
if with_content_ids.any? { |with_id| with_id.github_source == assignment_no_id.github_source } | |
puts "..Destroying assignment #{assignment_no_id.github_source}" | |
assignment_no_id.destroy | |
elsif Assignment.where(github_source: assignment_no_id.github_source).count > 1 | |
if assignment_no_id.batch | |
gh_source = "flatiron-school-curriculum/" + assignment_no_id.github_source.gsub("-#{assignment_no_id.batch.iteration}", '') | |
Lab.where(github_source: gh_source).each do |lab| | |
puts ".......Updating #{lab.title}" | |
lab.send(:create_assignment, assignment_no_id.batch.iteration) | |
end | |
end | |
puts ".....Destroying assignment #{assignment_no_id.github_source}" | |
assignment_no_id.destroy | |
end | |
end | |
Assignment.where(content: nil) | |
# Assignments with nil contents | |
# Duplicated assignments with contents | |
# Duplicated assignments with and without contents | |
# need dependent destroy contents -> assignments and batch -> assignments | |
# a bunch of orphaned contents/contents pointing to incorrect things |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment