diff --git a/lib/tasks/constraints.rake b/lib/tasks/constraints.rake new file mode 100644 index 00000000..5e46c257 --- /dev/null +++ b/lib/tasks/constraints.rake @@ -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 \ No newline at end of file diff --git a/lib/tasks/indexes.rake b/lib/tasks/indexes.rake new file mode 100644 index 00000000..9e8625d2 --- /dev/null +++ b/lib/tasks/indexes.rake @@ -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 \ No newline at end of file diff --git a/lib/tasks/load.rake b/lib/tasks/load.rake index b626c6d1..5c6b9ea4 100644 --- a/lib/tasks/load.rake +++ b/lib/tasks/load.rake @@ -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 diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake index be1b0aaa..e1b66cb5 100644 --- a/lib/tasks/stats.rake +++ b/lib/tasks/stats.rake @@ -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 \ No newline at end of file