大規模 Padrino アプリケーション Rails 移行 / Migrating to Rails from Padrino

大規模 Padrino アプリケーション Rails 移行 / Migrating to Rails from Padrino

Cc81dc2acad7b0d070a2f2d3f10eef7d?s=128

Tsukuru Tanimichi

April 26, 2016
Tweet

Transcript

  1. େن໛ Padrino ΞϓϦέʔγϣϯ Rails Ҡߦ 2016/04/27 @ttanimichi (C) Tsukuru Tanimichi,

    2016 1
  2. ࣗݾ঺հ • @ttanimichi • 2014೥6݄ʙ גࣜձࣾ Aiming • ڞ௨ج൫ͷ։ൃΛ͍ͯͨ͠ •

    ࠷ۙήʔϜλΠτϧʹҟಈ • https://github.com/ttanimichi • info@ttanimichi.com (C) Tsukuru Tanimichi, 2016 2
  3. ݬౝઓهάϦϑΥϯ (C) Tsukuru Tanimichi, 2016 3

  4. ؀ڥ • Ruby 2.0 • Padrino 0.11 • MySQL 5.5

    • nginx • Redis (C) Tsukuru Tanimichi, 2016 4
  5. rake stats % bin/rake stats +----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines

    | LOC | Classes | Methods | M/C | LOC/M | +----------------------+-------+-------+---------+---------+-----+-------+ | Controllers | 2984 | 2566 | 50 | 302 | 6 | 6 | | Helpers | 86 | 86 | 0 | 1 | 0 | 84 | | Models | 15810 | 13029 | 422 | 1513 | 3 | 6 | | Mailers | 0 | 0 | 0 | 0 | 0 | 0 | | Javascripts | 11577 | 7916 | 1 | 809 | 809 | 7 | | Libraries | 19329 | 13621 | 693 | 1754 | 2 | 5 | | Controller specs | 223 | 181 | 0 | 2 | 0 | 88 | | Lib specs | 4404 | 3603 | 6 | 6 | 1 | 598 | | Model specs | 31852 | 26255 | 0 | 19 | 0 | 1379 | | Request specs | 15 | 13 | 0 | 0 | 0 | 0 | | Service specs | 24027 | 19808 | 3 | 37 | 12 | 533 | +----------------------+-------+-------+---------+---------+-----+-------+ | Total | 110307 | 87078 | 1175 | 4443 | 3 | 17 | +----------------------+-------+-------+---------+---------+-----+-------+ Code LOC: 37218 Test LOC: 49860 Code to Test Ratio: 1:1.3 (C) Tsukuru Tanimichi, 2016 5
  6. rake stats % bin/rake stats +----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines

    | LOC | Classes | Methods | M/C | LOC/M | ... | Models | 15810 | 13029 | 422 | 1513 | 3 | 6 | ... +----------------------+-------+-------+---------+---------+-----+-------+ 400 Models (C) Tsukuru Tanimichi, 2016 6
  7. (C) Tsukuru Tanimichi, 2016 7

  8. rake stats • COOKPAD Ͱ 1500 Models • lib/ ҎԼʹ΋

    Model ͬΆ͍Ϋϥε͕100ݸ͘ Β͍͋ͬͨ • ͋ΘͤΔͱ 500 Models ͘Β͍ • COOKPAD ͷ 1/3 ͘Β͍ʁʁ (C) Tsukuru Tanimichi, 2016 8
  9. ੈք࠷େͷ Padrino ΞϓϦέʔγϣϯʁʁ (C) Tsukuru Tanimichi, 2016 9

  10. ͭΒΈ • rake spec ʹ1͔͔࣌ؒΔ • autoload ࢖ͬͯͳ͔ͬͨ • ىಈʹ2෼͘Β͍͔͔Δ

    • spec Ұ࣮݅ߦ͢Δ͚ͩͰ΋2෼ • AR ͷΩϟογϡ͕ޮ͍ͯͳ͍ͬΆ͍ʁʁ (C) Tsukuru Tanimichi, 2016 10
  11. ґଘϥΠϒϥϦ • activerecord 3.2 • activesupport 3.2 ͭ·Γɺ΄ͱΜͲ Rails3 (C)

    Tsukuru Tanimichi, 2016 11
  12. ͜Ε Rails ʹҠߦͰ͖ΔΜ͡ΌͶʁ (C) Tsukuru Tanimichi, 2016 12

  13. ͍ͭΧοͱͳͬͯ... (C) Tsukuru Tanimichi, 2016 13

  14. (C) Tsukuru Tanimichi, 2016 14

  15. Ҡߦίετ • Padrino ͔Β Rails ΁ͷҠߦ • activerecord ͷόʔδϣϯΛ্͛Δ •

    activesupport ͷόʔδϣϯΛ্͛Δ • ͍ͭͰʹ Ruby ͷόʔδϣϯ΋্͛Δ (C) Tsukuru Tanimichi, 2016 15
  16. ํ਑ • ·ͣ͸ Rails4 Ͱಈ͔͢͜ͱ͚ͩߟ͑Δ • ʮ͍ͭͰʹϦϑΝΫλϦϯάʯ͸ೝΊͳ͍ • ػցతʹҠߦ࡞ۀ͚ͩ͢Δ •

    ϦϑΝΫλϦϯά΍ࡉ͔͍վળ͸Ҡߦޙʹ͍͘ ΒͰ΋Ͱ͖Δ (C) Tsukuru Tanimichi, 2016 16
  17. ํ਑ • Rails΁ͷҠߦͱ͍͏ʮେ͖͍໰୊ʯ • ಉ࣌ʹϦϑΝΫλϦϯά΋͠͸͡ΊΔͱӬ ԕʹҠߦ࡞ۀ͕׬ྃ͠ͳ͍ • Ϗδωεଆ͕ΩϨΔ → Ҡߦ͕ࣦഊ

    • ͱʹ͔͘ػցతʹҠߦ͢Δ • Կ΋ߟ͑ͣʹ spec ͕ίέ͍ͯΔॴΛ௚͢ (C) Tsukuru Tanimichi, 2016 17
  18. Ҡߦखॱ • ͱʹ͔͘·ͣ͸σΟϨΫτϦߏ଄Λ࡞Δ • Padrino ଆ͔Β Models ͳͲΛҠ͍ͯ͘͠ • bundle

    exec rspec ͕ಈ͘ͱ͜Ζ·Ͱ͸Ұਓ Ͱ΋ͬͯ͘ • rails new • rails generate rspec:install • database.yml ͷઃఆͱ͔ (C) Tsukuru Tanimichi, 2016 18
  19. (C) Tsukuru Tanimichi, 2016 19

  20. (C) Tsukuru Tanimichi, 2016 20

  21. bundle exec rspec ಈ͍ͨ • ͔͜͜Βઌ͸ϝϯόʔʹ࡞ۀΛৼΔ • ͱʹ͔͘ spec ͑͞ಈ͚͹෼ۀͰ͖Δ

    • ෼୲ͯ͠ spec ͕ίέ͍ͯΔ෦෼Λमਖ਼ (C) Tsukuru Tanimichi, 2016 21
  22. ੝େʹίέΔ spec (C) Tsukuru Tanimichi, 2016 22

  23. (C) Tsukuru Tanimichi, 2016 23

  24. ੝େʹίέΔ spec • ͲΜ͚ͩίέͯͯ΋ spec ͕ಈ͖͑͢͞Ε͹म ਖ਼͸ϝϯόʔʹ෼୲Ͱ͖Δ • Active Record

    3 ͱ 4 ͷඇޓ׵ͱ͔ • ઃఆ·ΘΓͷ໰୊ • padrino helper ΁ͷґଘ • ಉ໊͡લͷϝιουΛఆٛͯ͠ rails ͷ helper ΁ΞΫηε͢ΔΑ͏मਖ਼ (C) Tsukuru Tanimichi, 2016 24
  25. Ͱ͖·ͨ͠ % rails -v Rails 4.2.4 % ruby -v ruby

    2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin14] ຊ൪؀ڥͰطʹಈ͍ͯ·͢ (C) Tsukuru Tanimichi, 2016 25
  26. ৼΓฦΓ (C) Tsukuru Tanimichi, 2016 26

  27. (C) Tsukuru Tanimichi, 2016 27

  28. ৼΓฦΓ • Ҡߦίετʹݟ߹͏͚ͩͷϝϦοτ͕͋ͬͨͷ ͔ͳ͔ͬͨͷ͔͸ʮ෼͔Βͳ͍ʯ • ϝϯόʔͷ։ൃʹର͢ΔϞνϕʔγϣϯΞοϓ • େֻ͔ΓͳҠߦʹ͸༐ؾͱܾஅྗ͕ඞཁ • Padrino

    ͷ··࠷௿ݶͷվળ͚ͩ͢Δͬͯબ୒ ࢶ΋ΞϦ͔ͩͬͨ΋ (C) Tsukuru Tanimichi, 2016 28
  29. ͓·͚ (C) Tsukuru Tanimichi, 2016 29

  30. ؅ཧը໘ • ຊମͱ؅ཧը໘͸ผΞϓϦέʔγϣϯ • ؅ཧπʔϧଆ͸ຊମଆͷ Model Λࢀর • ؅ཧπʔϧଆ͸Ұ୴ Padrino

    ͷ··࢒ͨ͠ • Ұ෦ͷ Model ͕ Rails.env ʹґଘʢྑ͘ͳ͍ʣ • Padrino ͷ৔߹͸ Padrino.env Λࢀর͍ͨ͠ (C) Tsukuru Tanimichi, 2016 30
  31. Rails = Padrino ΩλίϨ Rails = Padrino Rails.env #=> "development"

    ॳظԽ࣌ʹ Rails ͱ͍͏ఆ਺Λఆٛ ※ ωλͰ͢ ※ ؅ཧը໘΋ Rails ΁ͷҠߦ࡞ۀΛࠓ͍ͯ͠ΔΑ ※ ؅ཧը໘ͷ Rails Ҡߦ΋΄ͱΜͲ׬ྃ (C) Tsukuru Tanimichi, 2016 31
  32. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ (C) Tsukuru Tanimichi, 2016 32