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 1 year has passed since last update.

Dockerで実装しているテーブルの内容をターミナルで確認する方法(rails)

Posted at

備忘録として

Dockerを使ってrailsのアプリケーション実装をしている時に、
テーブルの更新内容を確認したくなったので調べた内容を記録しています。

#方法

% docker-compose run web rails db  

上記のコマンドを入力すると
ターミナルに下記内容が表示されます

psql (13.5 (Debian 13.5-0+deb11u1), server 14.1 (Debian 14.1-1.pgdg110+1))
WARNING: psql major version 13, server major version 14.
         Some psql features might not work.
Type "help" for help.

○○_development=#

#の後に

\d テーブル名;

と打てばテーブル詳細が表示されます。
ex: \d users;
と入力すれば

                                                Table "public.users"
         Column         |              Type              | Collation | Nullable |              Default              
------------------------+--------------------------------+-----------+----------+-----------------------------------
 id                     | bigint                         |           | not null | nextval('users_id_seq'::regclass)
 first_name             | character varying              |           | not null | ''::character varying
 last_name              | character varying              |           | not null | ''::character varying
 first_name_kana        | character varying              |           | not null | ''::character varying
 last_name_kana         | character varying              |           | not null | ''::character varying
 email                  | character varying              |           | not null | ''::character varying
 encrypted_password     | character varying              |           | not null | ''::character varying
Indexes:
    "users_pkey" PRIMARY KEY, btree (id)
    "index_users_on_email" UNIQUE, btree (email)
    "index_users_on_reset_password_token" UNIQUE, btree (reset_password_token)
Referenced by:
    TABLE "orders" CONSTRAINT "fk_rails_f868b47f6a" FOREIGN KEY (user_id) REFERENCES users(id)

みたいな感じで表示されて確認できます。

# 終了方法

○○_development=# \q

で抜けることができます!!

#最後に
調べていた記事には
PostgreSQL利用時の操作になる
と記載がありました!!Mysqlではできないのかもしれません。

備忘録として書きましたが誰かの為になることがあれば幸いです!!

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?