0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

メモ: Railsで全テーブルと全カラムのテーブル定義書風のTSVを出力

Posted at

この記事は

  • 完全なる個人メモです
  • RailsのDBからテーブル定義書ちっくなtsvを出力するスニペットを書いたので貼っておきます

スニペット

lib/tasks/export_table_tsv.rake
namespace :export_table_tsv do
  task run: :environment do
    ActiveRecord::Base.connection.tables.each do |table|
      table_ja = I18n.t("activerecord.models.#{table.singularize}")
      eval(table.singularize.camelize + ".column_names").each do |column|
        column_ja = I18n.t("activerecord.attributes.#{table.singularize}.#{column}") 
        puts "#{table}\t#{table_ja}\t#{column}\t#{column_ja}"
      end rescue nil
    end
  end
end

出力イメージ

  • これをExcelにはって活用します(雑)
users	ユーザー	id	translation missing: ja.activerecord.attributes.user.id
users	ユーザー	email	メールアドレス
users	ユーザー	first_name	名
users	ユーザー	last_name	姓

終わりに

  • one offスクリプトなのでtranslation missingは放置してしまったけど許してください
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?