Skip to content

Instantly share code, notes, and snippets.

@mustmodify
Last active October 14, 2019 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustmodify/c58414cb98dce848c768581767183438 to your computer and use it in GitHub Desktop.
Save mustmodify/c58414cb98dce848c768581767183438 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def last_line
`wc -l db/schema.rb`.to_i
end
table_lines = `grep create_table db/schema.rb -n`.split("\n").map{|l| l.gsub(/\:.*/, '').to_i}
term = ARGV[0]
table_starts = `grep "create_table.*#{term}" db/schema.rb -n`.split("\n")
table_starts.each do |ts|
table_info = ts.match(/(\d*): create_table "([^"]*)"/)
start_line = table_info[1].to_i
table_name = table_info[2]
end_line=(table_lines.select{|l| l > start_line}.min || last_line)- 3
puts "\n\n\n ====== [ #{table_name} ] ============================="
puts `head db/schema.rb -n #{end_line} | tail -n #{end_line - start_line}`
end
puts
puts
jw@logopolis:/projects/client_name/project_name $ script/dt user
====== [ users ] =============================
t.string "email", default: "", null: false
t.string "password_digest", collation: "utf8mb4_unicode_ci"
t.string "persistence_token", collation: "utf8mb4_unicode_ci"
t.string "perishable_token", collation: "utf8mb4_unicode_ci"
t.string "single_access_token", collation: "utf8mb4_unicode_ci"
t.integer "login_count", default: 0
t.datetime "last_request_at"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
jw@logopolis:/projects/client_name/project_name $ script/dt user
====== [ users ] =============================
t.string "email", default: "", null: false
t.string "password_digest", collation: "utf8mb4_unicode_ci"
t.string "persistence_token", collation: "utf8mb4_unicode_ci"
t.string "perishable_token", collation: "utf8mb4_unicode_ci"
t.string "single_access_token", collation: "utf8mb4_unicode_ci"
t.integer "login_count", default: 0
t.datetime "last_request_at"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment