Last active
February 9, 2026 23:48
-
-
Save peteonrails/7499b331c2a0b36f4a85293738d6c824 to your computer and use it in GitHub Desktop.
Seed script for testing marketing codes data migration locally
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
| contact_ids = [ | |
| 1069803, 1101193, 1365371, 1378337, 1416654, 1417908, 1423274, 1449297, | |
| 1449298, 1449300, 1449308, 1449309, 1449359, 1449365, 1449415, 1449438, | |
| 1449592, 1449644, 1449690, 1449756, 1449761, 1450003, 1450055, 1450157, | |
| 1450218, 1450309, 1450762, 1450923, 1451070, 1451095, 1451209, 1451265, | |
| 1451392, 1451443, 1451562, 1451680, 1451835, 1451937, 1451946, 1451963, | |
| 1452013, 1452156, 1452181, 1452222, 1452275, 1452289, 1452299, 1452300, | |
| 1452413, 1452418, 1452421, 1452425, 1452426, 1452441, 1452516, 1452545, | |
| 1452597, 1452598, 1452643, 1452733, 1452747, 1452762, 1452950, 1452955, | |
| 1452960, 1452964, 1452969, 1452971, 1452979, 1452987, 1453015, 1453052, | |
| 1453055, 1453095, 1453103, 1453120, 1453148, 1453161, 1453184, 1453220, | |
| 1453247, 1453248, 1453263, 1453266, 1453275, 1453277, 1453307, 1453312, | |
| 1453342, 1453370, 1453393, 1453395, 1453451, 1453461, 1453492, 1453496, | |
| 1453513, 1453521, 1453530, 1453538, 1453566, 1453578, 1453583, 1453594, | |
| 1453596, 1453603, 1453609, 1453613, 1453629, 1453630, 1453640, 1453647, | |
| 1453657, 1453681, 1453683, 1453688, 1453698, 1453702, 1453710, 1453717, | |
| 1453728, 1453738, 1453739, 1453743, 1453751, 1453752, 1453753, 1453766, | |
| 1453784, 1453786, 1453798, 1453811, 1453813, 1453816, 1453818, 1453822, | |
| 1453835, 1453836, 1453845, 1453849, 1453867, 1453892, 1453896, 1453921, | |
| 1453944, 1453951, 1453952, 1453983, 1454002, 1454022, 1454027, 1454040, | |
| 1454045, 1454050, 1454054, 1454066, 1454105, 1454136, 1454163, 1454174, | |
| 1454202, 1454214, 1454216, 1454236, 1454255, 1454289, 1454303, 1454327, | |
| 1454355, 1454356, 1454357, 1454366, 1454373, 1454381, 1454383, 1454387, | |
| 1454391, 1454528, 1454562, 1454607, 1454610, 1454611, 1454613, 1454640, | |
| 1454642, 1454645, 1454665, 1454669, 1454672, 1454681, 1454748, 1454772, | |
| 1454774, 1454776, 1454778, 1454803, 1454806, 1454830, 1454902, 1454917, | |
| 1454928, 1454965, 1454967, 1454969, 1454983, 1455040, 1455059, 1455073, | |
| 1455115, 1455124, 1455142, 1455144, 1455157, 1455160, 1455162, 1455164, | |
| 1455166, 1455172, 1455187, 1455188, 1455199, 1455201, 1455266, 1455270, | |
| 1455282, 1455362, 1455406, 1455458, 1455476, 1455477, 1455478, 1455487, | |
| 1455546, 1455553, 1455618, 1455651, 1455689, 1455707, 1455742, 1455755, | |
| 1455777, 1455817, 1455819, 1455854, 1455866, 1455885, 1455888, 1455896, | |
| 1455897, 1455904, 1455923, 1455941, 1455967, 1456177, 1456208, 1456338, | |
| 1456344, 1456346, 1456354, 1456376, 1456381, 1456405, 1456977, 1457013, | |
| 1457064, 1457329, 1457390, 1457420, 1457482, 1457489, 1457520, 1457527, | |
| 1457540, 1457553, 1457576, 1457593, 1457602, 1457622, 1457634, 1457644, | |
| 1457646, 1457652, 1457654, 1457658, 1457670, 1457671, 1457685, 1457722, | |
| 1457753, 1457756, 1457765, 1457782, 1457795, 1457822, 1457829, 1457830, | |
| 1457842, 1457857, 1457873, 1457890, 1457899, 1457922, 1457933, 1457935, | |
| 1457942, 1457944, 1457955, 1457963, 1457974, 1457991, 1457999, 1458004, | |
| 1458022, 1458027, 1458040, 1458041, 1458075, 1458084, 1458133, 1458155, | |
| 1458169, 1458170, 1458175, 1458186, 1458210, 1458218, 1458238, 1458262, | |
| 1458288, 1536200, 1536225, 1636096, 1638269, 1639240, 1648207, 1678408, | |
| 1684447, 1717610, 1721656, 1776657, 1995180, 2113517, 2113535, 2113561, | |
| 2113601, 2113772, 2113799, 2113823, 2214093, 2251622, 2281594, 2326743, | |
| 2331156, 2444860, 2458420, 2459231, 2556363 | |
| ] | |
| empty_json = {} | |
| owner = User.first | |
| if owner.nil? | |
| puts "No users in database — cannot create contacts without an owner." | |
| exit 1 | |
| end | |
| existing_ids = Contact.where(id: contact_ids).pluck(:id) | |
| missing_ids = contact_ids - existing_ids | |
| puts "#{existing_ids.size} contacts already exist, #{missing_ids.size} to create" | |
| Contact.no_touching do | |
| missing_ids.each do |cid| | |
| Contact.create!( | |
| id: cid, | |
| first_name: "Test", | |
| last_name: "Contact#{cid}", | |
| contact_type: "traveler", | |
| owner: owner | |
| ) | |
| end | |
| end | |
| puts "Created #{missing_ids.size} contacts" | |
| # Reset sequence so future inserts don't collide | |
| max_id = Contact.maximum(:id) | |
| ActiveRecord::Base.connection.execute("SELECT setval('contacts_id_seq', #{max_id})") | |
| # Create signature_person for any contact that doesn't have one | |
| contacts_without_person = Contact.where(id: contact_ids) | |
| .left_joins(:signature_person) | |
| .where(signature_people: {id: nil}) | |
| puts "#{contacts_without_person.count} contacts need a signature_person" | |
| contacts_without_person.find_each do |contact| | |
| Signature::Person.create!( | |
| contact: contact, | |
| anniversary: empty_json, | |
| birthday: empty_json, | |
| other_addresses: empty_json, | |
| other_emails: empty_json, | |
| other_phones: empty_json, | |
| primary_address: empty_json, | |
| primary_email: empty_json, | |
| primary_fax: empty_json, | |
| primary_phone: empty_json, | |
| relationships: empty_json | |
| ) | |
| end | |
| # Set crm_id on signature_people so outbox events get created during the migration | |
| updated_crm = Signature::Person | |
| .joins(:contact) | |
| .where(contacts: {id: contact_ids}) | |
| .where(crm_id: [nil, ""]) | |
| .update_all(crm_id: "test-crm-id") | |
| puts "Set crm_id on #{updated_crm} signature_people" | |
| # Seed the marketing codes if they don't exist | |
| [24965, 27227].each do |sig_id| | |
| Signature::MarketingCode.find_or_create_by!(signature_id: sig_id) do |mc| | |
| mc.name = "Test #{sig_id}" | |
| mc.category = "backfill" | |
| mc.status = "active" | |
| mc.show_consumer = false | |
| end | |
| end | |
| puts "Marketing codes present: #{Signature::MarketingCode.where(signature_id: [24965, 27227]).pluck(:signature_id).inspect}" | |
| puts "Done. #{Contact.where(id: contact_ids).joins(:signature_person).count} contacts ready with signature_person + crm_id" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment