感情的ドリル

Ruby県から飛び出して関東にきたオタク

Dockerで動くGitLabのpostgresからsnippetsの一覧を取得する

なにがしたいの

  1. Dockerで動かしてるGitLabのsnippetの一覧が欲しい
  2. Where are the snippets stored? (#21946) · Issues · GitLab.org / GitLab Community Edition · GitLab
    「snippetsどこにあるの?」「DBのsnippetsテーブルにあるよ!」
  3. SQLを叩いてサッと取得したい

どうするのか

# host
docker exec -it <name> /bin/bash

# docker (root)
su - gitlab-psql

# docker(gitlab-psql)
psql -h /var/opt/gitlab/postgresql/ gitlabhq_production

# postgres
\d snippets

SELECT 
  users.name, 
  snippets.id,
  snippets.title
FROM
  snippets
LEFT JOIN
  users
  ON users.id = snippets.author_id
;
gitlabhq_production-# ;
   name   | id |                                            title
----------+----+----------------------------------------------------------------------------------------------
 hogehoge |  1 | vimrc
 hogehoge |  2 | vagrantfile
 hogehoge |  3 | vagrantfile
 hogehoge |  4 | zshrc

おわり

参考