Project automation for internal affairs

023b04c98f39cc041293d780352432ff?s=47 Koichi ITO
November 03, 2019

Project automation for internal affairs

023b04c98f39cc041293d780352432ff?s=128

Koichi ITO

November 03, 2019
Tweet

Transcript

  1. 3.
  2. 4.
  3. 6.
  4. 9.
  5. 22.
  6. 27.

    $47ੜ੒εΫϦϓτΛ࡞Δ w 3FWJFXBCMF ϨϏϡʔՄೳ  w 3VOOBCMF ࣮ߦՄೳ  w

    3FQFBUBCMF ࠶࣮ߦՄೳ  w 3FQSPEVDJCMF ࠶ݱՄೳ  w 'SPN(VUTUP'VO
  7. 30.
  8. 35.
  9. 39.
  10. 54.
  11. 55.

    ECTDIFNBSC ActiveRecord::Schema.define( version: 2018_11_23_153926 ) do create_table "articles", force: :cascade

    do |t| t.integer "author_id", null: false t.string "title", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end end
  12. 56.

    ECTDIFNBSCͷ"45 s(:block, s(:send, s(:const, s(:const, nil, :ActiveRecord), :Schema), :define, s(:hash,

    s(:pair, s(:sym, :version), s(:int, 20181123153926)))), s(:args), s(:block, s(:send, nil, :create_table, s(:str, "articles"), s(:hash, s(:pair, s(:sym, :force), s(:sym, :cascade)))), s(:args, s(:arg, :t)), s(:begin, s(:send, s(:lvar, :t), :integer, s(:str, "author_id"), s(:hash, s(:pair, s(:sym, :null), s(:false)))), s(:send, s(:lvar, :t), :string, s(:str, "title"), s(:hash, s(:pair, s(:sym, :null), s(:false)))), s(:send, s(:lvar, :t), :datetime, s(:str, "created_at"), s(:hash, s(:pair, s(:sym, :null), s(:false)))), s(:send, s(:lvar, :t), :datetime, s(:str, "updated_at"), s(:hash, s(:pair, s(:sym, :null), s(:false)))))))
  13. 57.
  14. 58.

    "DUJWF3FDPSE4DIFNBEFpOF WFSTJPO@@@ s(:block, s(:send, s(:const, s(:const, nil, :ActiveRecord), :Schema ),

    :define, s(:hash, s(:pair, s(:sym, :version), s(:int, 20181123153926)))), s(:args),
  15. 59.

    DSFBUF@UBCMFBSUJDMFT  GPSDFDBTDBEFEPcUc s(:block, s(:send, nil, :create_table, s(:str, "articles"), s(:hash,

    s(:pair, s(:sym, :force), s(:sym, :cascade)))), s(:args, s(:arg, :t)), CMPDLΛϒϩοΫҾ਺Uͱ Ұॹʹड͚औΔ DSFBUF@UBCMFϝιουΛ ఆٛͨ͠CMPDLϊʔυ )FSF
  16. 60.

    UJOUFHFSBVUIPS@JE OVMM GBMTF s(:begin, s(:send, s(:lvar, :t), :integer, s(:str, "author_id"),

    s(:hash, s(:pair, s(:sym, :null), s(:false)))), UJOUFHFS UTUSJOH ͱ͍ͬͨΧϥϜఆٛͷTFOE ϊʔυΛଋͶͨCFHJOϊʔυ )FSF
  17. 61.

    UTUSJOHUJUMF OVMMGBMTF s(:send, s(:lvar, :t), :string, s(:str, "title"), s(:hash, s(:pair,

    s(:sym, :null), s(:false)))), ͜ΕΒϩʔΧϧม਺U΁ͷ ϝιουݺͼग़͠Λද͢ TFOEϊʔυ͕ଓ͘
  18. 62.

    ECTDIFNBSC ࠶ܝ ActiveRecord::Schema.define( version: 2018_11_23_153926 ) do create_table "articles", force:

    :cascade do |t| t.integer "author_id", null: false t.string "title", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end end
  19. 68.

    $PQΫϥεΛܧঝ͢Δ module RuboCop module Cop module InternalAffairs class SchemaToCsv <

    Cop end end end end HFNSVCPDPQ
 ͳͲͰ3VCP$PQΠϯεί ͞ΕͯΕ͹࢖͑Δ"1*
  20. 74.

    ΧϥϜϊʔυΛऔಘ͢Δ def on_block(node) table = node.children.first return unless table.method_name ==

    :create_table table_name = table.first_argument.str_content columns = node.children.detect(&:begin_type?)
  21. 75.

    ΧϥϜϊʔυΛऔಘ͢Δ def on_block(node) table = node.children.first return unless table.method_name ==

    :create_table table_name = table.first_argument.str_content columns = node.children.detect(&:begin_type?) UJOUFHFS UTUSJOH ͱ͍ͬͨΧϥϜఆٛͷTFOE ϊʔυΛଋͶͨCFHJOϊʔυ )FSF
  22. 79.

    ΧϥϜ໊ΛಘΔ columns = node.children.detect(&:begin_type?) CSV.open('tmp/schema.csv', 'a') do |csv| columns.child_nodes.each do

    |column| next if column.method_name == :index column_name = column.first_argument.str_content end end
  23. 80.

    ͋ͱ͸$47ʹ͍͍ײ͡ʹग़ྗ͢Δ columns = node.children.detect(&:begin_type?) CSV.open('tmp/schema.csv', 'a') do |csv| columns.child_nodes.each do

    |column| next if column.method_name == :index column_name = column.first_argument.str_content write_csv_row(csv, table_name, column_name) end end
  24. 82.

    w SFRVJSFͱPOMZΦϓγϣϯ % bundle exec rubocop \ --cache false --require

    ./lib/rubocop/cop/ internal_affairs \ --only InternalAffairs/ SchemaToCsv \ db/schema.rb > /dev/null ͓·͚ ࣮ߦͷ౾஌ࣝ
  25. 83.

    w ීஈ͸ࢦఆෆཁͳDBDIFΦϓγϣϯ % bundle exec rubocop \ --cache false --require

    ./lib/rubocop/cop/ internal_affairs \ --only InternalAffairs/ SchemaToCsv \ db/schema.rb > /dev/null ͓·͚ ࣮ߦͷ౾஌ࣝ --cache falseʹ͠ͳ͍ͱҰ౓ ղੳͨ͠db/schema.rbʹ͍ͭͯ ͸Ωϟογϡ͞Εͯॲཧ͞Εͳ͍ (΍͍ͬͯΔ͜ͱ͕अಓͳূ͔΋)