Skip to content

Commit

Permalink
Merge pull request #1188 from ctti-clinicaltrials/fix-ctgov-v2
Browse files Browse the repository at this point in the history
updates to tasks
  • Loading branch information
micronix authored Jun 3, 2024
2 parents a886a39 + ca3fa7b commit 7779f48
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 21 deletions.
29 changes: 29 additions & 0 deletions lib/tasks/constraints.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace :constraints do
desc 'show indexes and foreign keys'
task :show, [:schema] => :environment do |t, args|
with_search_path(args[:schema]) do
StudyRelationship.study_models.each do |model|
puts model.table_name.blue
model.connection.foreign_keys(model.table_name).each do |fk|
puts " #{fk.column} -> #{fk.to_table}.#{fk.primary_key}"
end
end
end
end

desc 'add constraints'
task :add, [:schema] => :environment do |t, args|
with_search_path(args[:schema]) do
db = Util::DbManager.new(schema: args[:schema])
db.add_constraints
end
end

desc 'remove constraints'
task :remove, [:schema] => :environment do |t, args|
with_search_path(args[:schema]) do
db = Util::DbManager.new(schema: args[:schema])
db.remove_constraints
end
end
end
29 changes: 29 additions & 0 deletions lib/tasks/indexes.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace :indexes do
desc 'show indexes and foreign keys'
task :show, [:schema] => :environment do |t, args|
with_search_path(args[:schema]) do
StudyRelationship.study_models.each do |model|
puts model.table_name.blue
model.connection.indexes(model.table_name).each do |index|
puts " #{index.name} -> #{index.columns.join(', ')}"
end
end
end
end

desc 'add constraints'
task :add, [:schema] => :environment do |t, args|
with_search_path(args[:schema]) do
db = Util::DbManager.new(schema: args[:schema])
db.add_constraints
end
end

desc 'remove constraints'
task :remove, [:schema] => :environment do |t, args|
with_search_path(args[:schema]) do
db = Util::DbManager.new(schema: args[:schema])
db.remove_constraints
end
end
end
8 changes: 0 additions & 8 deletions lib/tasks/load.rake
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,4 @@ namespace :db do
db.add_indexes
end
end

desc 'remove constraints from the database'
task :remove_constraints, [:schema] => :environment do |t, args|
with_search_path(args[:schema]) do
db = Util::DbManager.new(schema: args[:schema])
db.remove_constraints
end
end
end
13 changes: 0 additions & 13 deletions lib/tasks/stats.rake
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,4 @@ namespace :stats do
end
end
end

desc 'show indexes and foreign keys'
task :indexes, [:schema] => :environment do |t, args|
with_search_path(args[:schema]) do
StudyRelationship.study_models.each do |model|
puts model.table_name.blue
#model.connection.indexes(model.table_name)
model.connection.foreign_keys(model.table_name).each do |fk|
puts " #{fk.column} -> #{fk.to_table}.#{fk.primary_key}"
end
end
end
end
end

0 comments on commit 7779f48

Please sign in to comment.