Ruby on RailsでDBをマイグレーションした際にテーブルの更新内容確認のため使用した。手軽な確認操作のため忘備録として残しておく。
注)PostgreSQL利用時の操作になる。
1. DBコンソールを起動
$ rails db
2.テーブルの詳細確認
コンソールが起動したら、「\d [テーブル名];」でテーブル詳細を確認。(下記例はusersテーブル)
db_development=# \d users;
Table "public.users"
Column | Type | Collation | Nullable | Default
-----------------+-----------------------------+-----------+----------+-----------------------------------
id | bigint | | not null | nextval('users_id_seq'::regclass)
name | character varying | | not null |
email | character varying | | not null |
password | character varying | | not null |
created_at | timestamp without time zone | | not null |
updated_at | timestamp without time zone | | not null |
admin | boolean | | not null | false
Indexes:
"users_pkey" PRIMARY KEY, btree (id)
"index_users_on_email" UNIQUE, btree (email)
型やNOT NULL制約の確認もできる。手軽なのでお試しあれ。