Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Project automation for internal affairs

Koichi ITO
November 03, 2019

Project automation for internal affairs

Koichi ITO

November 03, 2019
Tweet

More Decks by Koichi ITO

Other Decks in Programming

Transcript

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

    3FQFBUBCMF ࠶࣮ߦՄೳ  w 3FQSPEVDJCMF ࠶ݱՄೳ  w 'SPN(VUTUP'VO
  2. 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
  3. 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)))))))
  4. "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),
  5. 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
  6. 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
  7. UTUSJOHUJUMF OVMMGBMTF s(:send, s(:lvar, :t), :string, s(:str, "title"), s(:hash, s(:pair,

    s(:sym, :null), s(:false)))), ͜ΕΒϩʔΧϧม਺U΁ͷ ϝιουݺͼग़͠Λද͢ TFOEϊʔυ͕ଓ͘
  8. 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
  9. $PQΫϥεΛܧঝ͢Δ module RuboCop module Cop module InternalAffairs class SchemaToCsv <

    Cop end end end end HFNSVCPDPQ
 ͳͲͰ3VCP$PQΠϯεί ͞ΕͯΕ͹࢖͑Δ"1*
  10. ΧϥϜϊʔυΛऔಘ͢Δ 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?)
  11. ΧϥϜϊʔυΛऔಘ͢Δ 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
  12. ΧϥϜ໊ΛಘΔ 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
  13. ͋ͱ͸$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
  14. w SFRVJSFͱPOMZΦϓγϣϯ % bundle exec rubocop \ --cache false --require

    ./lib/rubocop/cop/ internal_affairs \ --only InternalAffairs/ SchemaToCsv \ db/schema.rb > /dev/null ͓·͚ ࣮ߦͷ౾஌ࣝ
  15. 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ʹ͍ͭͯ ͸Ωϟογϡ͞Εͯॲཧ͞Εͳ͍ (΍͍ͬͯΔ͜ͱ͕अಓͳূ͔΋)