easy_seeds 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/README.md +101 -0
  4. data/demo/db/.DS_Store +0 -0
  5. data/demo/db/.gitignore +1 -0
  6. data/demo/db/migrate/20221220031557_create_users.rb +16 -0
  7. data/demo/db/migrate/20221229181317_create_restaurants.rb +15 -0
  8. data/demo/db/migrate/20221230024550_create_menus.rb +9 -0
  9. data/demo/db/migrate/20221230161702_create_menu_items.rb +11 -0
  10. data/demo/db/migrate/20230105193341_create_active_storage_tables.active_storage.rb +57 -0
  11. data/demo/db/migrate/20230107051041_create_reviews.rb +10 -0
  12. data/demo/db/migrate/20230107053024_create_carts.rb +10 -0
  13. data/demo/db/migrate/20230107161239_create_transactions.rb +10 -0
  14. data/demo/db/migrate/20230111045953_edit_restaurants.rb +5 -0
  15. data/demo/db/migrate/20230111051203_edit_restaurants_desc.rb +5 -0
  16. data/demo/db/migrate/20230111052037_add_descto_menu_items.rb +5 -0
  17. data/demo/db/migrate/20230111052640_add_header_to_menu_items.rb +5 -0
  18. data/demo/db/migrate/20230111053049_add_fk_carts.rb +5 -0
  19. data/demo/db/migrate/20230111170524_edit_transaction.rb +5 -0
  20. data/demo/db/migrate/20230112184231_create_locations.rb +10 -0
  21. data/demo/db/migrate/20230127004056_drop_carts.rb +5 -0
  22. data/demo/db/migrate/20230127004504_create_carts2.rb +9 -0
  23. data/demo/db/migrate/20230127004817_create_cart_items.rb +10 -0
  24. data/demo/db/migrate/20230129230534_remove_cart_index.rb +6 -0
  25. data/demo/db/migrate/20230129231213_edit_carts_index.rb +5 -0
  26. data/demo/db/migrate/20230201235823_remove_cart_item_index.rb +6 -0
  27. data/demo/db/migrate/20230201235957_edit_cart_items_index.rb +5 -0
  28. data/demo/db/migrate/20230203015313_remove_username.rb +5 -0
  29. data/demo/db/migrate/20230204005331_add_rest_avg_price.rb +5 -0
  30. data/demo/db/schema.rb +149 -0
  31. data/demo/db/seed_files/1_users_seeds.csv +6 -0
  32. data/demo/db/seed_files/2_restaurants_seeds.csv +45 -0
  33. data/demo/db/seed_files/3_menus_seeds.csv +45 -0
  34. data/demo/db/seed_files/4_menu_items_seeds.csv +2085 -0
  35. data/demo/db/seed_files/5_reviews_seeds.csv +80 -0
  36. data/demo/db/seed_files/6_carts_seeds.csv +3 -0
  37. data/demo/db/seed_files/7_cart_items_seeds.csv +5 -0
  38. data/demo/db/seed_files/8_transactions_seeds.csv +4 -0
  39. data/demo/db/seed_files/9_locations_seeds.csv +2 -0
  40. data/demo/db/seed_image_files/1_restaurant_image_seeds.csv +45 -0
  41. data/demo/db/seeds.rb +45 -0
  42. data/demo/seed_files/1_user_seeds_sample.csv +5 -0
  43. data/demo/seed_files/2_resturaunts_seeds_sample.csv +6 -0
  44. data/demo/seed_files/3_menu_seeds_sample.csv +6 -0
  45. data/demo/seed_files/4_menu_items_seed_sample.csv +6 -0
  46. data/demo/seed_image_files/.DS_Store +0 -0
  47. data/demo/seed_image_files/1_image_seed_sample.csv +17 -0
  48. data/demo/seed_image_files/2_image_seed_sample.csv +18 -0
  49. data/easy_seeds.gemspec +28 -0
  50. data/lib/easy_seeds/csv_methods.rb +72 -0
  51. data/lib/easy_seeds/destroy.rb +16 -0
  52. data/lib/easy_seeds/easy_seeds.rb +24 -0
  53. data/lib/easy_seeds/images.rb +36 -0
  54. data/lib/easy_seeds/seeder.rb +28 -0
  55. metadata +130 -0
@@ -0,0 +1,80 @@
1
+ restaurant_id:int,user_id:int,body:text
2
+ 1,1,Great food and service! Highly recommend.
3
+ 3,1,Not enough chicken in my ramen.
4
+ 3,3,"Nice atmosphere, friendly staff."
5
+ 4,4,Best sushi I've had in a long time.
6
+ 5,5,Good value for the price.
7
+ 3,1,"Like I said, not enough chicken."
8
+ 7,2,"Good Thai food, reasonable prices."
9
+ 8,3,Nice selection of craft beers.
10
+ 9,4,Wonderful French cuisine.
11
+ 10,5,"Excellent service, great ambiance."
12
+ 11,1,"Delicious sandwiches, fast service."
13
+ 12,2,Great selection of vegetarian options.
14
+ 13,3,Nice outdoor seating area.
15
+ 14,4,"Lovely Italian food, reasonable prices."
16
+ 15,5,"Good Chinese food, prompt service."
17
+ 16,1,"Tasty Mexican food, friendly staff."
18
+ 17,2,"Delicious Greek food, great atmosphere."
19
+ 18,3,"Great seafood, friendly service."
20
+ 19,4,"Lovely ambiance, excellent service."
21
+ 20,5,Good value for the price.
22
+ 21,1,"Delicious pizzas, great atmosphere."
23
+ 22,2,Good value for the price.
24
+ 23,3,Nice outdoor seating area.
25
+ 24,4,"Tasty sandwiches, fast service."
26
+ 25,5,Great selection of vegetarian options.
27
+ 26,1,"Lovely Italian food, reasonable prices."
28
+ 27,2,"Good Thai food, reasonable prices."
29
+ 28,3,Nice selection of craft beers.
30
+ 29,4,Wonderful French cuisine.
31
+ 30,5,"Excellent service, great ambiance."
32
+ 31,1,"Delicious burgers, nice patio."
33
+ 32,2,"Great seafood, friendly service."
34
+ 33,3,"Lovely ambiance, excellent service."
35
+ 34,4,Best sushi I've had in a long time.
36
+ 35,5,"Good Chinese food, prompt service."
37
+ 36,1,"Tasty Mexican food, friendly staff."
38
+ 37,2,"Delicious Greek food, great atmosphere."
39
+ 38,3,Great food and service! Highly recommend.
40
+ 39,4,"Nice atmosphere, friendly staff."
41
+ 40,1,"Terrible service, rude staff."
42
+ 41,2,Overpriced and mediocre food.
43
+ 42,3,Would not recommend. Poor service.
44
+ 43,4,"Disgusting bathrooms, stay away."
45
+ 44,5,"Terrible food, don't waste your money."
46
+ 40,1,"Rude staff, wouldn't come back."
47
+ 41,2,"Terrible experience, stay away."
48
+ 42,3,"Vulgar staff, will not return."
49
+ 43,4,"Terrible service, avoid at all costs."
50
+ 44,5,"Horrible food, rude staff."
51
+ 40,1,Worst restaurant I've ever been to.
52
+ 41,2,"Rude staff, terrible food."
53
+ 42,3,Avoid this place at all costs.
54
+ 43,4,Vulgar and unprofessional staff.
55
+ 44,5,"Terrible experience, would not recommend."
56
+ 40,1,"Terrible service, rude staff."
57
+ 41,2,Overpriced and mediocre food.
58
+ 42,3,Would not recommend. Poor service.
59
+ 43,4,"Disgusting bathrooms, stay away."
60
+ 44,5,"Terrible food, don't waste your money."
61
+ 40,1,"Rude staff, wouldn't come back."
62
+ 41,2,"Terrible experience, stay away."
63
+ 42,3,"Vulgar staff, will not return."
64
+ 43,4,"Terrible service, avoid at all costs."
65
+ 44,5,"Horrible food, rude staff."
66
+ 40,1,Worst restaurant I've ever been to.
67
+ 41,2,"Rude staff, terrible food."
68
+ 42,3,Avoid this place at all costs.
69
+ 43,4,Vulgar and unprofessional staff.
70
+ 44,5,"Terrible experience, would not recommend."
71
+ 40,1,"Terrible service, rude staff."
72
+ 41,2,Overpriced and mediocre food.
73
+ 42,3,Would not recommend. Poor service.
74
+ 43,4,"Disgusting bathrooms, stay away."
75
+ 44,5,"Terrible food, don't waste your money."
76
+ 40,1,"Rude staff, wouldn't come back."
77
+ 41,2,"Terrible experience, stay away."
78
+ 42,3,"Vulgar staff, will not return."
79
+ 43,4,"Terrible service, avoid at all costs."
80
+ 44,5,"Horrible food, rude staff."
@@ -0,0 +1,3 @@
1
+ user_id:int,restaurant_id:int
2
+ 1,1
3
+ 1,2
@@ -0,0 +1,5 @@
1
+ cart_id:int,menu_item_id:int,quantity:int
2
+ 1,19,5
3
+ 1,20,5
4
+ 2,81,3
5
+ 2,84,5
@@ -0,0 +1,4 @@
1
+ user_id:int,restaurant_id:int,transaction_sum,review_left:boolean
2
+ 1,44,42.69,FALSE
3
+ 1,21,2123.23,FALSE
4
+ 1,18,299.95,FALSE
@@ -0,0 +1,2 @@
1
+ user_id:int,latitude:float,longitude:float
2
+ 1,37.747401957356246,-122.4456108834198
@@ -0,0 +1,45 @@
1
+ ID,URL,Filename
2
+ 1,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/21_taste_house.jpeg,21_taste_house.jpeg
3
+ 2,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/4505_burgers_bbq.jpeg,4505_burgers_bbq.jpeg
4
+ 3,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/absinthe_brasserie_and_bar.webp,absinthe_brasserie_and_bar.webp
5
+ 4,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/alices.jpg,alices.jpg
6
+ 5,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/als_super_cafe.jpg,als_super_cafe.jpg
7
+ 6,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/amami_sushi_bistro_sf.jpg,amami_sushi_bistro_sf.jpg
8
+ 7,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/ananda_fuara.jpeg,ananda_fuara.jpeg
9
+ 8,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/andersen_bakery.webp,andersen_bakery.webp
10
+ 9,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/an_chi_vietnamese_cuisine.jpg,an_chi_vietnamese_cuisine.jpg
11
+ 10,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/arts_cafe.jpeg,arts_cafe.jpeg
12
+ 11,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/atlas_cafe.webp,atlas_cafe.webp
13
+ 12,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/b.jpeg,b.jpeg
14
+ 13,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/bac_lieu_restaurant.jpg,bac_lieu_restaurant.jpg
15
+ 14,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/balboa_cafe.png,balboa_cafe.png
16
+ 15,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/balboa_ice_cream.jpeg,balboa_ice_cream.jpeg
17
+ 16,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/barbacco.jpeg,barbacco.jpeg
18
+ 17,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/bb_tea.jpg,bb_tea.jpg
19
+ 18,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/big_joes.jpeg,big_joes.jpeg
20
+ 19,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/bite.jpg,bite.jpg
21
+ 20,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/boba_gen.jpeg,boba_gen.jpeg
22
+ 21,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/boba_guys.jpeg,boba_guys.jpeg
23
+ 22,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/bottega.jpeg,bottega.jpeg
24
+ 23,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/boudin_bakery_cafe.jpeg,boudin_bakery_cafe.jpeg
25
+ 24,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/brew_cha.jpeg,brew_cha.jpeg
26
+ 25,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/bullshead_restaurant.jpg,bullshead_restaurant.jpg
27
+ 26,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/burger_joint.jpeg,burger_joint.jpeg
28
+ 27,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/burrito_loco.jpeg,burrito_loco.jpeg
29
+ 28,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/cafe_bakery_restaurant.jpeg,cafe_bakery_restaurant.jpeg
30
+ 29,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/cafe_de_casa.webp,cafe_de_casa.webp
31
+ 30,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/cafe_tiramisu.jpeg,cafe_tiramisu.jpeg
32
+ 31,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/casa_mexicana.jpg,casa_mexicana.jpg
33
+ 32,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/cesarios.jpeg,cesarios.jpeg
34
+ 33,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/casa_mexicana.jpg,casa_mexicana.jpg
35
+ 34,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/cesarios.jpeg,cesarios.jpeg
36
+ 35,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/chaiya_thai_restaurant.jpg,chaiya_thai_restaurant.jpg
37
+ 36,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/cinderella_baker_cafe.jpeg,cinderella_baker_cafe.jpeg
38
+ 37,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/cocos_ramen.jpeg,cocos_ramen.jpeg
39
+ 38,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/crossroad_pizzeria.jpeg,crossroad_pizzeria.jpeg
40
+ 39,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/deli_23.jpeg,deli_23.jpeg
41
+ 40,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/domo.jpg,domo.jpg
42
+ 41,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/doppio_zero_san_francisco.jpeg,doppio_zero_san_francisco.jpeg
43
+ 42,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/double_rainbow_ice_cream.jpeg,double_rainbow_ice_cream.jpeg
44
+ 43,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/dumpling_home.jpeg,dumpling_home.jpeg
45
+ 44,https://suber-eats-seeds.s3.us-west-1.amazonaws.com/pho_ha_tien.jpeg,pho_ha_tien.jpeg
data/demo/db/seeds.rb ADDED
@@ -0,0 +1,45 @@
1
+ require_relative './easy_seeds/easy_seeds.rb'
2
+ require "open-uri"
3
+
4
+ =begin
5
+
6
+ Example of what your seeds.rb file should look like. Full project at https://github.com/mfong4151/Suber-Eats
7
+
8
+ ___ CSV Seed_Files Setup ____
9
+
10
+ See the samples for how CSV's are set up. The headers need to match the database column names exactly.
11
+ Use the format -- column_name:data_type -- for the headers. Easy_Seeder will do type conversion for you. Default is "string" and does not need to be declared.
12
+ Accepted data types: string, integer, float, boolean, date.
13
+ If you need an additional data type ping Marcos or Max and we can update.
14
+
15
+ ___ CSV Seed_Files Setup ____
16
+
17
+ Seed image files Require a Id, URL and Filename. You can copy these last two straight from the AWS console.
18
+ the Id will attach the image path to that Id's object instance. See "Easy Seeder Setup" for information on file ordering.
19
+
20
+ ___ Easy Seeder Setup ___
21
+
22
+ File order matters!
23
+ Place your model names in class_names for each class you are making Seed Data for. Each class needs its own CSV.
24
+
25
+ The order of class_names and the order of files in seed_files should match your migration order (to prevent null database constraint failures).
26
+ EasySeeds.attach_images runs after all database instances are created. It uses the value in class_image_names
27
+ to attach images to an instance of that Class_Name and Id.
28
+
29
+ hit us up with questions.
30
+
31
+ =end
32
+
33
+
34
+
35
+ class_names = [User, Restaurant, Menu, MenuItem, Review, Cart, CartItem, Transaction, Location]
36
+ table_strings = ['users', 'restaurants', 'menus', 'menu_items', 'reviews', 'carts', 'cart_items', 'transactions', 'locations']
37
+
38
+ EasySeeds::Destroy.destroy_tables(class_names, table_strings)
39
+
40
+ puts 'Creating easy seeds data'
41
+ class_names.delete_at(-1)
42
+ EasySeeds::Seeder.create_easy_seed_data(class_names)
43
+
44
+ class_image_names = [Restaurant]
45
+ EasySeeds::Images.attach_images(class_image_names)
@@ -0,0 +1,5 @@
1
+ Username,Email,Password,name,phone_number
2
+ Demo-lition,demo@user.io,password,Demo Lition,123-456-7890
3
+ mfong,mfong415@gmail.com,password,Maxwell Fong,234-567-8901
4
+ nracherla,simpSupreme@gmail.com,password,Nishant Racherla,345-678-9821
5
+ dieggucio,dieggucio@aa.io,password,Dieggucio no Guccio,800-200-6000
@@ -0,0 +1,6 @@
1
+ name: string,description: text,rating: float,address: string,state_code: string,city: string,longitude: float,latitude: float
2
+ Pho Ha Tien,It's Phoneomenal!,4.5,"1900 Ocean Ave, San Francisco, CA",CA,San Francisco,37.72,-122.4622,
3
+ Marugame Udon,It's cheap and good!,4.9,"3251 20th Ave, San Francisco, CA",CA,San Francisco,37.72818,-122.47702,
4
+ Bodega SF,Pho Swag,4.7,"138 Mason St, San Francisco, CA 94102",CA,San Francisco,37.78473,-122.40934,
5
+ Monza Pizzeria,It's not Diogeornos!,4.4,"1934 Ocean Ave, San Francisco, CA 94127",CA,San Francisco,37.72584,-122.46332,
6
+ El Super Burrito,Best Burritio in Downtown SF!,4.2,"1200 Polk St, San Francisco, CA 94109",CA,San Francisco,37.7876691,-122.4221302,
@@ -0,0 +1,6 @@
1
+ restaurant_id,menu_items_id
2
+ 1,1
3
+ 1,2
4
+ 1,3
5
+ 1,4
6
+ 1,5
@@ -0,0 +1,6 @@
1
+ item_name,menu_id,item_price,item_image
2
+ Ha Tien Special Extra Large Combo Noodle Soup,1,19.25,
3
+ Combo Beef Noodle Soup,1,16.75,
4
+ Rare Beef,1,16.75,
5
+ Beef Meatball,1,16.75,
6
+ Rare Beef with Chicken,1,16.75,
Binary file
@@ -0,0 +1,17 @@
1
+ ID,URL,Filename
2
+ 1,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/DragonDen/DragonDen-Exterior.webp,Houses/DragonDen/DragonDen-Exterior.webp
3
+ 1,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/DragonDen/DragonDen-Living-Room.jpeg,Houses/DragonDen/DragonDen-Living-Room.jpeg
4
+ 1,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/DragonDen/DragonDen-Den.jpeg,Houses/DragonDen/DragonDen-Den.jpeg
5
+ 1,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/DragonDen/DragonDen-Library.jpeg,Houses/DragonDen/DragonDen-Library.jpeg
6
+ 2,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/HobbitHovel1/HobbitHovel1-Exterior.jpeg,Houses/HobbitHovel1/HobbitHovel1-Exterior.jpeg
7
+ 2,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/HobbitHovel1/HobbitHovel1-Living-Room.jpeg,Houses/HobbitHovel1/HobbitHovel1-Living-Room.jpeg
8
+ 2,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/HobbitHovel1/HobbitHovel1-Balcony.jpeg,Houses/HobbitHovel1/HobbitHovel1-Balcony.jpeg
9
+ 2,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/HobbitHovel1/HobbitHovel1-Den.jpeg,Houses/HobbitHovel1/HobbitHovel1-Den.jpeg
10
+ 3,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Kitchy1/Kitchy1-Exterior.jpeg,Houses/Kitchy1/Kitchy1-Exterior.jpeg
11
+ 3,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Kitchy1/Kitchy1-Living-Room.jpeg,Houses/Kitchy1/Kitchy1-Living-Room.jpeg
12
+ 3,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Kitchy1/Kitchy1-Bedroom.jpeg,Houses/Kitchy1/Kitchy1-Bedroom.jpeg
13
+ 4,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Nautilus/Nautilus-Exterior.jpeg,Houses/Nautilus/Nautilus-Exterior.jpeg
14
+ 4,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Nautilus/Nautilus-Entry.jpeg,Houses/Nautilus/Nautilus-Entry.jpeg
15
+ 4,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Nautilus/Nautilus-Living-Room.jpeg,Houses/Nautilus/Nautilus-Living-Room.jpeg
16
+ 4,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Nautilus/Nautilus-Bedroom.jpeg,Houses/Nautilus/Nautilus-Bedroom.jpeg
17
+ 4,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Nautilus/Nautilus-Door.jpeg,Houses/Nautilus/Nautilus-Door.jpeg
@@ -0,0 +1,18 @@
1
+ ID,URL,Filename
2
+ 5,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Rustic1/Rustic1-Exterior.jpeg,Houses/Rustic1/Rustic1-Exterior.jpeg
3
+ 5,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Rustic1/Rustic1-Dining-Room.jpeg,Houses/Rustic1/Rustic1-Dining-Room.jpeg
4
+ 5,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Rustic1/Rustic1-Den.jpeg,Houses/Rustic1/Rustic1-Den.jpeg
5
+ 5,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Rustic1/Rustic1-Cabinet.jpeg,Houses/Rustic1/Rustic1-Cabinet.jpeg
6
+ 6,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Rustic2/Rustic2-Exterior.jpeg,Houses/Rustic2/Rustic2-Exterior.jpeg
7
+ 6,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Rustic2/Rustic2-Kitchen.jpeg,Houses/Rustic2/Rustic2-Kitchen.jpeg
8
+ 6,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Rustic2/Rustic2-Bedroom.jpeg,Houses/Rustic2/Rustic2-Bedroom.jpeg
9
+ 6,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Rustic2/Rustic2-Den.jpeg,Houses/Rustic2/Rustic2-Den.jpeg
10
+ 7,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Seaside/Seaside-Exterior.webp,Houses/Seaside/Seaside-Exterior.webp
11
+ 7,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Seaside/Seaside-Living-Room.jpeg,Houses/Seaside/Seaside-Living-Room.jpeg
12
+ 7,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Seaside/Seaside-Bedroom.jpeg,Houses/Seaside/Seaside-Bedroom.jpeg
13
+ 7,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Seaside/Seaside-Sink.jpeg,Houses/Seaside/Seaside-Sink.jpeg
14
+ 7,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Seaside/Seaside-Sink2.jpeg,Houses/Seaside/Seaside-Sink2.jpeg
15
+ 8,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Treehouse/TreeHouse-Exterior.jpeg,Houses/Treehouse/TreeHouse-Exterior.jpeg
16
+ 8,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Treehouse/TreeHouse-Living-Room.jpeg,Houses/Treehouse/TreeHouse-Living-Room.jpeg
17
+ 8,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Treehouse/TreeHouse-Bedroom.jpeg,Houses/Treehouse/TreeHouse-Bedroom.jpeg
18
+ 8,https://willow-seeds.s3.us-west-2.amazonaws.com/Houses/Treehouse/TreeHouse-Alchemy.jpeg,Houses/Treehouse/TreeHouse-Alchemy.jpeg
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require_relative "lib/easy_seeds/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "easy_seeds"
8
+ spec.version = '1.0.0'
9
+ spec.authors = ["Maxwell Fong", "Marcos Henrich"]
10
+ spec.email = ["mfong415@gmail.com", "jmarcoshenrich@gmail.com"]
11
+ spec.description = "A library for easily generating seed data in Ruby on Rails from .CSV files"
12
+ spec.summary = "Seed files from .CSVs for your Ruby on Rails project"
13
+ spec.homepage = "https://github.com/mfong4151/easy-seeds"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "csv"
21
+ spec.add_dependency "aws-sdk-s3", "~> 1.105"
22
+ spec.required_ruby_version = ">= 2.7.0"
23
+ spec.metadata = {
24
+ "source_code_uri" => "https://github.com/mfong4151/easy-seeds",
25
+ "bug_tracker_uri" => "https://github.com/mfong4151/easy-seeds/issues",
26
+ "documentation_uri" => "https://github.com/mfong4151/easy-seeds/blob/main/README.md"
27
+ }
28
+ end
@@ -0,0 +1,72 @@
1
+ require 'csv'
2
+
3
+ module EasySeeds
4
+ class CSVLoader
5
+ def self.unpack_csvs(seed_file)
6
+ data = []
7
+ CSV.foreach(seed_file) {|row|data << row}
8
+ headers = data.shift
9
+ headers.map{|header| header.to_sym}
10
+ return headers, data
11
+ end
12
+
13
+ def self.tables_from_csvs
14
+ all_seed_data = []
15
+ table_strings = []
16
+ seed_folder = './db/seed_files'
17
+ Dir.chdir(seed_folder)
18
+
19
+ Dir.glob("*").each do |seed_file|
20
+ seed_res = []
21
+ headers, data = unpack_csvs(seed_file)
22
+
23
+ data.each_with_index do |row, j|
24
+ datum = {}
25
+ row.each_with_index do |col, i|
26
+ key = clean_headers(headers[i])
27
+ datum[key[0]] = type_conversion(row[i], key[1])
28
+ end
29
+ seed_res << datum
30
+ end
31
+
32
+ table_strings << seed_file[seed_file.index('_') + 1..-11]
33
+ all_seed_data << seed_res
34
+ end
35
+
36
+ return all_seed_data, table_strings
37
+ end
38
+
39
+ protected
40
+
41
+ def self.clean_headers(header)
42
+ if header.include?(":")
43
+ first, second, = header.split(":")
44
+ header_and_type = [first.downcase, second]
45
+ else
46
+ header_and_type = [header.downcase, 'string']
47
+ end
48
+ return header_and_type
49
+ end
50
+
51
+ #Used for converting your data to the relevant data types, all data from csvs comes in as string by default
52
+ #Its important to note that this isn't suppose to turn it into the datatype for your SQL table, but rather the format that ruby needs to understand the CSV item as, since all data from CSV comes in as a string by default.
53
+ #datum: string, refers to the actual piece of data you are using
54
+ #data_type, the type you wish to convert to, by default will return a string if none is given
55
+
56
+ def self.type_conversion(datum, data_type = 'string')
57
+ if ['text', 'string', 's'].include?(data_type)
58
+ return datum.to_s
59
+ elsif ['int', 'integer', 'i'].include?(data_type)
60
+ return datum.to_i
61
+ elsif ['float', 'f'].include?(data_type)
62
+ return datum.to_f
63
+ elsif ["bool", "boolean"].include?(data_type)
64
+ return ActiveModel::Type::Boolean.new.cast(datum)
65
+ elsif ["date"].include?(data_type)
66
+ return DateTime.parse(datum).to_date.to_s
67
+ else
68
+ return datum
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,16 @@
1
+ module EasySeeds
2
+ class Destroy
3
+ ###For manually destroying tables, useful for if you have many joins tables.
4
+ def self.destroy_table(class_name, table_string)
5
+ puts "Destroying the #{table_string} table"
6
+ class_name.destroy_all
7
+ ApplicationRecord.connection.reset_pk_sequence!(table_string)
8
+ end
9
+
10
+ ###Used in conjunction to destroy all of your tables
11
+ def self.destroy_tables(class_names, table_strings)
12
+ (class_names.length - 1).downto(0) {|i| Destroy.destroy_table(class_names[i], table_strings[i])}
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,24 @@
1
+ =begin
2
+ Common preconditions:
3
+ 1. table: Expects an array version of your table that corresponds to the name.
4
+ Your table MUST be formated as an array containing multiple hashes, see the example from my menu_items class on github.
5
+ Because of how this is set up, the variable name MUST be equivalent to the name of the table in migrations.
6
+
7
+ 2. class_name: Expects the actual class name created in models. Expects an actual class variable.
8
+
9
+ 3. table_string: Table name given as a string. Usually used for destroying tables ahead of import. Expects a string
10
+
11
+ Common Issues:
12
+
13
+ Deleting: The issue occurs if theres a directed graph cycle relation between tables, or if there are joins tables with multiple presence constraints on the foreign keys.
14
+ Tip: To avoid this you have to typically drop the entire database, although this is obviously not recommended in production.
15
+
16
+ =end
17
+
18
+ module EasySeeds
19
+ end
20
+
21
+
22
+ require_relative './seeder.rb'
23
+ require_relative './destroy.rb'
24
+ require_relative './images.rb'
@@ -0,0 +1,36 @@
1
+ require_relative './csv_methods'
2
+ require "open-uri"
3
+
4
+ module EasySeeds
5
+ class Images
6
+
7
+ def self.attach_images(class_image_names)
8
+ begin
9
+ Dir.chdir('../seed_image_files')
10
+ rescue
11
+ Dir.chdir(Dir.pwd + '/db/seed_image_files')
12
+ end
13
+
14
+ Dir.glob("*").each_with_index do |seed_file, i|
15
+ headers, data = CSVLoader.unpack_csvs(seed_file)
16
+ class_image_name = class_image_names[i]
17
+ puts "Attaching to #{class_image_name}..."
18
+
19
+ data.each_with_index do |row|
20
+ object_id, url, filename = row
21
+ class_instance = class_image_name.find_by_id(object_id)
22
+
23
+ begin
24
+ class_instance.image.attach(io: URI.open(url), filename: filename)
25
+ puts "Attached to #{filename}"
26
+ rescue OpenURI::HTTPError
27
+ puts('Waiting 30 seconds before seeding the next row of data, please be patient')
28
+ sleep(30.second)
29
+ class_instance.image.attach(io: URI.open(url), filename: filename)
30
+ puts "Attached to #{filename}"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ require_relative './csv_methods'
2
+
3
+ module EasySeeds
4
+ class Seeder
5
+
6
+ #Creates a single instance of seed data
7
+ def self.single_seeder(table, class_name, table_string)
8
+ ApplicationRecord.connection.reset_pk_sequence!(table_string)
9
+ puts "Creating #{table_string} seed data..."
10
+
11
+ table.each_with_index do |row, i|
12
+ puts "Finished Seeding the #{i.to_s}th #{table_string} item" if i % 100 == 0
13
+ class_name.create!(**row)
14
+ end
15
+
16
+ puts "DONE WITH #{table_string.upcase}, #{table_string.upcase} SEEDING SUCCESSFUL"
17
+ end
18
+
19
+ #Creates easy seed data for all classes that are passed in
20
+ def self.create_easy_seed_data(class_names)
21
+ tables, table_strings = EasySeeds::CSVLoader.tables_from_csvs
22
+
23
+ (0...tables.length).each do |i|
24
+ EasySeeds::Seeder.single_seeder(tables[i], class_names[i], table_strings[i])
25
+ end
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy_seeds
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Maxwell Fong
8
+ - Marcos Henrich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2023-04-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: csv
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: aws-sdk-s3
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.105'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.105'
42
+ description: A library for easily generating seed data in Ruby on Rails from .CSV
43
+ files
44
+ email:
45
+ - mfong415@gmail.com
46
+ - jmarcoshenrich@gmail.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".DS_Store"
52
+ - README.md
53
+ - demo/db/.DS_Store
54
+ - demo/db/.gitignore
55
+ - demo/db/migrate/20221220031557_create_users.rb
56
+ - demo/db/migrate/20221229181317_create_restaurants.rb
57
+ - demo/db/migrate/20221230024550_create_menus.rb
58
+ - demo/db/migrate/20221230161702_create_menu_items.rb
59
+ - demo/db/migrate/20230105193341_create_active_storage_tables.active_storage.rb
60
+ - demo/db/migrate/20230107051041_create_reviews.rb
61
+ - demo/db/migrate/20230107053024_create_carts.rb
62
+ - demo/db/migrate/20230107161239_create_transactions.rb
63
+ - demo/db/migrate/20230111045953_edit_restaurants.rb
64
+ - demo/db/migrate/20230111051203_edit_restaurants_desc.rb
65
+ - demo/db/migrate/20230111052037_add_descto_menu_items.rb
66
+ - demo/db/migrate/20230111052640_add_header_to_menu_items.rb
67
+ - demo/db/migrate/20230111053049_add_fk_carts.rb
68
+ - demo/db/migrate/20230111170524_edit_transaction.rb
69
+ - demo/db/migrate/20230112184231_create_locations.rb
70
+ - demo/db/migrate/20230127004056_drop_carts.rb
71
+ - demo/db/migrate/20230127004504_create_carts2.rb
72
+ - demo/db/migrate/20230127004817_create_cart_items.rb
73
+ - demo/db/migrate/20230129230534_remove_cart_index.rb
74
+ - demo/db/migrate/20230129231213_edit_carts_index.rb
75
+ - demo/db/migrate/20230201235823_remove_cart_item_index.rb
76
+ - demo/db/migrate/20230201235957_edit_cart_items_index.rb
77
+ - demo/db/migrate/20230203015313_remove_username.rb
78
+ - demo/db/migrate/20230204005331_add_rest_avg_price.rb
79
+ - demo/db/schema.rb
80
+ - demo/db/seed_files/1_users_seeds.csv
81
+ - demo/db/seed_files/2_restaurants_seeds.csv
82
+ - demo/db/seed_files/3_menus_seeds.csv
83
+ - demo/db/seed_files/4_menu_items_seeds.csv
84
+ - demo/db/seed_files/5_reviews_seeds.csv
85
+ - demo/db/seed_files/6_carts_seeds.csv
86
+ - demo/db/seed_files/7_cart_items_seeds.csv
87
+ - demo/db/seed_files/8_transactions_seeds.csv
88
+ - demo/db/seed_files/9_locations_seeds.csv
89
+ - demo/db/seed_image_files/1_restaurant_image_seeds.csv
90
+ - demo/db/seeds.rb
91
+ - demo/seed_files/1_user_seeds_sample.csv
92
+ - demo/seed_files/2_resturaunts_seeds_sample.csv
93
+ - demo/seed_files/3_menu_seeds_sample.csv
94
+ - demo/seed_files/4_menu_items_seed_sample.csv
95
+ - demo/seed_image_files/.DS_Store
96
+ - demo/seed_image_files/1_image_seed_sample.csv
97
+ - demo/seed_image_files/2_image_seed_sample.csv
98
+ - easy_seeds.gemspec
99
+ - lib/easy_seeds/csv_methods.rb
100
+ - lib/easy_seeds/destroy.rb
101
+ - lib/easy_seeds/easy_seeds.rb
102
+ - lib/easy_seeds/images.rb
103
+ - lib/easy_seeds/seeder.rb
104
+ homepage: https://github.com/mfong4151/easy-seeds
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ source_code_uri: https://github.com/mfong4151/easy-seeds
109
+ bug_tracker_uri: https://github.com/mfong4151/easy-seeds/issues
110
+ documentation_uri: https://github.com/mfong4151/easy-seeds/blob/main/README.md
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.7.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.3.7
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Seed files from .CSVs for your Ruby on Rails project
130
+ test_files: []