Created
April 14, 2016 23:55
-
-
Save jamiecook/865054752aa61f05beadf543b84e25e3 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
# The two companies in questions | |
qms_id = 96 | |
goa_id = 7 | |
# Get all QMS assets | |
Site.where(company_id: qms_id).size # => 1080 | |
qms_sites = Site.where(company_id: qms_id) | |
qms_site_ids = qms_sites.map(&:id) # [133681, 129348, 129378, 133678, 132010, 132016, 132021, 132030, 132053, 131998, 131991, 132058, 139150, 132007, 139263, 132019, 132020, 132026, 132028, 132029, 140056, 139193, 132049, 132059, 132013, 132014, 132018, 140058, 132005, 132008, 132011, 132015, 132017, 132024, 132027, 129662, 129664, 140048, 140050, 140064, 142607, 126452, 132036, 132051, 132006, 129659, 129660, 132041, 129477, 126475, 126641, 126762, 126515, 126483, 126487, 126491, 126492, 126495, 126498, 126501, 126511, 126513, 126516, 126543, 126546, 126549, 126553, 126554, 126558, 126562, 126566, 126570, 126571, 126589, 126591, 126598, 126599, 126611, 126612, 126618, 126619, 126621, 126628, 126637, 126660, 126678, 126689, 126700, 126712, 126723, 126728, 126734, 126745, 126754, 126765, 126766, 126770, 126771, 126788, 126792, 126797, 126810, 126815, 126819, 126830, 126833, 126842, 126845, 126849, 126851, 126855, 126857, 126865, 126866, 126869, 126870, 126873, 126874, 126878, 126880, 126884, 126890, 126893, 127854, 127860, 127867, 127898, 127907, 127908, 127915, 127917, 127919, 127933, 127950, 127955, 127964, 127965, 128017, 128020, 128025, 128030, 128038, 128041, 128043, 128044, 128052, 128053, 128061, 128586, 128710, 128718, 128719, 128723, 128728, 128733, 128740, 128776, 129264, 129268, 129270, 129273, 129277, 129279, 129281, 129282, 129283, 129288, 129292, 129298, 129300, 129304, 129309, 129316, 129325, 129326, 129335, 129339, 129341, 129342, 129345, 129366, 129367, 129370, 129380, 129385, 129389, 129390, 129392, 129395, 129396, 129399, 129400, 129402, 129407, 129414, 129428, 129429, 129430, 129440, 129443, 129448, 129451, 129452, 129458, 129462, 129465, 129467, 129472, 129473, 129658, 132057, 126614, 129376, 133682, 139169, 139250, 139643, 139646, 140052, 140059, 140065, 126832, 127899, 126748, 126751, 133683, 132031, 132039, 132033, 132034, 132035, 132046, 132054, 132060, 129506, 127853, 129479, 129350, 129445, 126677, 126744, 126453, 126462, 126463, 126465, 126466, 126467, 126479, 126489, 126494, 126497, 126502, 126514, 126517, 126521, 126526, 126527, 126529, 126530, 126539, 126545, 126548, 126551, 126560, 126569, 126575, 126586, 126594, 126597, 126627, 126630, 126635, 126642, 126648, 126650, 126684, 126686, 126690, 126717, 126719, 126720, 126724, 126730, 126746, 126755, 126769, 126772, 126777, 126778, 126791, 126814, 126817, 126818, 126825, 126834, 126852, 126853, 126856, 126858, 126863, 126879, 126882, 127856, 127857, 127858, 127865, 127869, 127969, 128019, 128023, 128033, 128037, 128045, 128712, 128715, 128717, 129262, 129263, 129275, 129313, 129318, 129328, 129329, 129332, 129334, 129337, 129338, 129346, 129352, 129353, 129369, 129377, 129381, 129387, 129388, 129391, 129406, 129409, 129412, 129413, 129417, 129418, 129420, 129422, 129423, 129425, 129438, 129439, 129447, 129450, 129454, 143988, 143993, 144006, 144022, 144008, 144052, 144065, 131999, 128711, 126565, 126760, 144270, 144272, 144271, 144269, 126579, 126816, 127904, 128750, 128713, 126592, 136612, 144018, 144480, 144481, 126542, 132000, 128022, 132042, 132044, 132048, 132002, 132004, 126836, 126606, 126827, 128026, 129306, 129312, 129315, 129319, 129457, 126457, 126459, 129317, 126523, 126644, 129475, 129478, 128766, 129349, 129371, 126828, 128049, 126607, 129259, 129393, 139140, 126454, 126455, 126460, 126468, 126472, 139142, 126477, 126478, 126480, 126481, 126482, 126484, 126488, 126500, 126510, 126522, 126524, 126525, 126528, 126534, 126536, 126537, 126556, 126557, 126585, 126587, 126588, 126609, 126610, 126616, 126622, 126636, 126645, 126647, 126657, 126662, 126667, 126683, 126695, 126711, 126718, 126721, 126722, 126729, 126747, 126758, 126764, 126767, 126776, 126784, 126787, 126790, 126795, 126796, 126807, 126809, 126811, 126823, 126824, 126826, 126829, 126831, 126835, 126846, 126850, 126859, 126861, 126862, 126864, 126868, 126876, 127859, 127866, 127868, 127884, 127905, 127914, 127918, 127927, 127928, 127931, 127949, 127954, 127961, 127962, 127967, 128027, 128029, 128032, 128035, 128036, 128039, 128050, 128056, 128058, 128060, 128735, 128737, 128773, 129252, 129260, 129265, 129266, 129267, 129272, 129276, 129280, 129285, 129289, 129297, 129302, 129320, 129321, 129324, 129327, 129331, 129336, 129343, 129344, 129356, 129362, 129365, 129373, 129374, 129375, 129394, 129397, 129401, 129408, 129410, 129415, 129421, 129427, 129435, 129436, 129437, 129444, 129453, 129466, 129471, 129474, 139526, 139524, 129446, 128051, 139187, 139192, 139196, 139236, 139237, 139241, 139199, 132022, 139221, 128722, 139248, 139249, 139143, 129303, 126743, 140014, 140053, 140274, 140285, 140281, 140280, 140283, 140273, 140286, 140277, 140278, 140276, 140275, 140279, 140282, 126490, 126544, 133677, 132012, 129254, 129261, 129269, 129271, 129274, 129278, 129290, 129294, 129295, 129308, 129310, 129311, 129314, 129322, 129323, 129330, 129333, 129340, 129351, 129355, 129398, 126808, 128034, 126583, 132037, 132001, 126768, 127929, 127932, 127934, 129291, 129358, 129364, 129368, 126798, 139152, 132023, 126508, 126573, 126651, 126509, 126518, 129403, 129411, 129416, 129419, 129424, 128764, 129372, 129382, 129432, 129456, 129476, 127870, 127921, 129426, 126432, 126434, 126449, 126450, 126458, 126461, 126470, 126473, 126476, 126486, 126493, 126496, 126499, 126512, 126520, 126532, 126533, 126535, 126538, 126540, 126541, 126547, 126550, 126555, 126559, 126561, 126574, 126578, 126582, 126593, 126595, 126613, 126623, 126624, 126625, 126626, 126640, 126655, 126665, 126669, 126682, 126685, 126696, 126699, 126727, 126732, 126733, 126756, 126759, 126763, 126773, 126774, 126775, 126780, 126781, 126785, 126789, 126794, 126799, 126800, 126820, 126837, 126843, 126844, 126847, 126848, 126854, 126860, 126885, 126886, 126889, 127851, 127855, 127871, 127901, 127902, 127903, 127910, 127913, 127920, 127922, 127923, 127935, 128021, 128024, 128028, 128040, 128042, 128055, 128062, 128714, 128777, 129255, 129256, 129379, 129383, 129384, 129386, 129433, 129434, 129441, 129442, 129449, 129459, 136614, 128748, 126552, 126629, 126664, 126668, 126753, 126786, 127930, 132025, 133684, 136613, 139157, 139154, 139155, 139159, 139158, 139160, 126464, 128762, 127912, 139141, 139161, 139153, 139156, 139519, 139520, 139523, 139529, 139521, 139525, 139527, 139528, 139522, 126469, 126471, 126474, 139184, 139185, 139195, 139186, 139188, 139190, 139189, 139194, 139243, 139244, 139197, 139198, 139212, 139191, 139240, 139208, 139202, 139218, 139219, 139228, 139223, 139211, 139238, 139239, 139251, 139245, 139220, 139247, 139227, 139226, 139225, 139224, 139644, 139645, 126601, 126605, 126615, 126620, 139647, 139648, 127900, 127909, 127911, 127926, 127953, 127957, 127963, 127966, 132032, 128720, 128727, 128731, 128732, 128742, 128758, 128772, 129251, 129253, 129257, 129258, 129284, 129286, 129287, 129293, 129296, 129305, 129307, 129404, 129405, 129455, 129461, 129464, 129468, 129469, 129470, 126448, 126451, 126761, 126877, 126881, 126883, 126894, 127852, 127970, 128018, 128744, 128746, 128749, 126757, 126867, 126871, 126875, 128716, 128738, 128757, 128768, 128769, 139147, 139149, 139148, 139151, 139144, 139145, 139146, 139201, 139200, 139203, 139204, 139205, 139209, 139210, 139213, 139206, 139242, 139246, 140013, 140047, 140049, 140051, 140066, 140060, 140054, 140055, 140057, 140061, 140062, 140063, 140272, 140284, 126485, 126567, 126568, 129460, 126531, 126653, 126654, 126656, 126658, 126661, 126681, 126752, 126872, 128054, 128059, 129301, 126563, 131981, 128031, 129463, 126812, 126813, 126841, 139230, 139233, 139234, 139231, 139207, 126688, 126697, 126698, 126726, 126731, 126736, 126742, 127849, 127863, 127942, 127946, 128729, 126445, 126581, 126652, 126679, 126680, 126691, 126694, 126713, 126715, 126737, 126741, 126750, 126839, 126840, 126888, 126892, 127943, 127945, 127947, 127951, 127952, 126446, 126701, 126707, 126709, 126716, 126738, 126739, 126444, 126447, 126749, 126887, 126891, 127862, 127864, 127944, 127958, 127960, 128724, 128725, 126604, 126687, 126692, 126708, 126710, 126725, 126735, 126821, 126838, 127847, 127848, 127850, 127861, 128047, 126443, 126693, 126740, 126572, 128730, 126714, 131982, 131983, 131984, 131986, 139214, 139215, 139216, 139217, 139222, 139232, 139235, 139183, 139229, 126456, 126519, 126576, 126564, 126590, 126649, 126822, 128048, 128759, 129299, 129361, 129347, 129354, 129357, 129359, 129360, 129363, 129431, 129654, 129655, 129656, 129657, 129507, 131974, 131985, 131987, 131975, 131988, 131989, 131990, 131992, 131993, 131994, 131995, 132009, 132038, 132003, 132052, 132040, 132045, 132047, 132055, 132056, 132050, 132133, 132134, 132141, 132140, 132137, 132138, 132139, 132135, 132136] | |
# Find all the representatives that have been added to those assets | |
qms_reps = CompanySite.where(site_id: qms_sites.map(&:id)) # 1076 | |
# Check the make up of those reps to ensure that we are only dealing with GOA | |
# access to QMS assets (yes we are!) | |
qms_reps.to_a.group_by(&:company_id).map { |k,vs| [k,vs.size] } # => [[7, 1076]]" | |
# Actual Code to remove representatives from QMS assets | |
# Applied at 2016-04-14 at 1:30PM | |
errors = [] | |
qms_reps.each { |cs| | |
if cs.destroy | |
puts 'done a site' | |
else | |
errors << cs | |
end | |
} | |
p errors.size # 0 errors | |
# Actual Code to re-add representatives to ALL QMS assets after QMS changed their | |
# minds about this entire thing | |
# Applied at 2016-04-14 at 3:30PM | |
qms_site_ids.each { |id| | |
CompanySite.create!(:company_id => goa_id, :site_id => id) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment