<commit_before>class FluxxGrantSwitchAroundProgramInitiativeEtc < ActiveRecord::Migration
  def self.up
    # get rid of referential integrity
    unless adapter_name =~ /SQLite/i
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY rfs_sub_initiative_id"
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY request_funding_sources_funding_source_id"
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY request_funding_sources_initiative_id"
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY request_funding_sources_program_id"
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY request_funding_sources_request_id"
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY rfs_board_authority_id"
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY rfs_sub_program_id"
      execute "ALTER TABLE requests DROP FOREIGN KEY requests_program_id"
      execute "ALTER TABLE requests DROP FOREIGN KEY requests_initiative_id"
      execute "ALTER TABLE initiatives DROP FOREIGN KEY initiatives_program_id"
      execute "ALTER TABLE sub_initiatives DROP FOREIGN KEY sub_initiative_sub_program_id"
      execute "ALTER TABLE sub_programs DROP FOREIGN KEY sub_program_initiative_id"
    end
    
    # requests; initiative_id should be renamed to sub_program_id
    execute "ALTER TABLE requests change column initiative_id sub_program_id int(11) DEFAULT NULL"
    
    # request_funding_sources nothing changes but referential integrity
    
    # rename sub_programs and initiatives
    execute "RENAME TABLE sub_programs to tmp_table"
    execute "RENAME TABLE initiatives to sub_programs"
    execute "RENAME TABLE tmp_table to initiatives"
    
    # change initiatives column initiative_id to sub_program_id 
    execute "ALTER TABLE initiatives change column initiative_id sub_program_id  int(11) DEFAULT NULL"
    # change sub_initiatives column sub_program_id to initiative_id
    execute "ALTER TABLE sub_initiatives change column sub_program_id initiative_id  int(11) DEFAULT NULL"
    
    # resume referential integrity
    unless adapter_name =~ /SQLite/i
      execute "ALTER TABLE sub_programs ADD CONSTRAINT `sub_programs_program_id` FOREIGN KEY (`program_id`) REFERENCES `programs` (`id`)"<commit_msg>needed to mod request_funding_sources to swap initiative_id and sub_program_id<commit_after>class FluxxGrantSwitchAroundProgramInitiativeEtc < ActiveRecord::Migration
  def self.up
    # get rid of referential integrity
    unless adapter_name =~ /SQLite/i
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY rfs_sub_initiative_id"
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY request_funding_sources_funding_source_id"
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY request_funding_sources_initiative_id"
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY request_funding_sources_program_id"
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY request_funding_sources_request_id"
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY rfs_board_authority_id"
      execute "ALTER TABLE request_funding_sources DROP FOREIGN KEY rfs_sub_program_id"
      execute "ALTER TABLE requests DROP FOREIGN KEY requests_program_id"
      execute "ALTER TABLE requests DROP FOREIGN KEY requests_initiative_id"
      execute "ALTER TABLE initiatives DROP FOREIGN KEY initiatives_program_id"
      execute "ALTER TABLE sub_initiatives DROP FOREIGN KEY sub_initiative_sub_program_id"
      execute "ALTER TABLE sub_programs DROP FOREIGN KEY sub_program_initiative_id"
    end
    
    # requests; initiative_id should be renamed to sub_program_id
    execute "ALTER TABLE requests change column initiative_id sub_program_id int(11) DEFAULT NULL"
    
    # rename sub_programs and initiatives
    execute "RENAME TABLE sub_programs to tmp_table"
    execute "RENAME TABLE initiatives to sub_programs"
    execute "RENAME TABLE tmp_table to initiatives"
    
    # change initiatives column initiative_id to sub_program_id 
    execute "ALTER TABLE initiatives change column initiative_id sub_program_id  int(11) DEFAULT NULL"
    # change sub_initiatives column sub_program_id to initiative_id
    execute "ALTER TABLE sub_initiatives change column sub_program_id initiative_id  int(11) DEFAULT NULL"

    # request_funding_sources swap initiative_id and sub_program_id 
    execute "ALTER TABLE request_funding_sources change column sub_program_id tmp_initiative_id  int(11) DEFAULT NULL"
    execute "ALTER TABLE request_funding_sources change column initiative_id sub_program_id int(11) DEFAULT NULL"
    execute "ALTER TABLE request_funding_sources change column tmp_initiative_id initiative_id  int(11) DEFAULT NULL"
    
    # resume referential integrity
    unless adapter_name =~ /SQLite/i
      execute "ALTER TABLE sub_programs ADD CONSTRAINT `sub_programs_program_id` FOREIGN KEY (`program_id`) REFERENCES `programs` (`id`)"
{'fraction_non_alphanumeric': 0.03368337626312661, 'fraction_numerical': 0.0035664751337428175, 'mean_word_length': 4.995249406175772, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6990158', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1435, 'n_words': 457}