PeerTube Database Schema?

@Chocobozzz, Can you tell me where can i find the entire database schema for PeerTube. I was hoping to update some fields.

I don’t know where in the installation the database is created, but when your instance is running you should be able to find it on PostgreSQL. I don’t know whether the database got a default name, in my case it’s called peertube_peertube:

# sudo -u postgres psql
postgres=# \l
                                       List of databases
       Name        |  Owner   | Encoding |   Collate   |    Ctype    |    Access privileges     
-------------------+----------+----------+-------------+-------------+--------------------------
 peertube_peertube | peertube | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/peertube            +
                   |          |          |             |             | peertube=C*T*c*/peertubee
....
....
postgres-# \c

 peertube_peertube 
You are now connected to database "peertube_peertube" as user "postgres".
peertube_peertube-# \dt
                  List of relations
 Schema |          Name           | Type  |  Owner   
--------+-------------------------+-------+----------
 public | abuse                   | table | peertube
 public | abuseMessage            | table | peertube
 public | account                 | table | peertube
.... 
 public | videoTracker            | table | peertube
 public | videoView               | table | peertube
(43 rows)

peertube_peertube=# select * from abuse;
 id | reason | state | moderationComment | predefinedReasons | reporterAccountId | flaggedAccountId | createdAt | updatedAt 
----+--------+-------+-------------------+-------------------+-------------------+------------------+-----------+-----------
(0 rows)

peertube_peertube=#  \d abuse
                                          Table "public.abuse"
      Column       |           Type           | Collation | Nullable |              Default              
-------------------+--------------------------+-----------+----------+-----------------------------------
 id                | integer                  |           | not null | nextval('abuse_id_seq'::regclass)
 reason            | character varying(3000)  |           | not null | NULL::character varying
 state             | integer                  |           | not null | 
 moderationComment | character varying(3000)  |           |          | NULL::character varying
 predefinedReasons | integer[]                |           |          | 
 reporterAccountId | integer                  |           |          | 
 flaggedAccountId  | integer                  |           |          | 
 createdAt         | timestamp with time zone |           | not null | 
 updatedAt         | timestamp with time zone |           | not null | 
Indexes:
    "abuse_pkey" PRIMARY KEY, btree (id)
    "abuse_flagged_account_id" btree ("flaggedAccountId")
    "abuse_reporter_account_id" btree ("reporterAccountId")
Foreign-key constraints:
    "abuse_flaggedAccountId_fkey" FOREIGN KEY ("flaggedAccountId") REFERENCES account(id) ON UPDATE CASCADE ON DELETE SET NULL
    "abuse_reporterAccountId_fkey" FOREIGN KEY ("reporterAccountId") REFERENCES account(id) ON UPDATE CASCADE ON DELETE SET NULL
Referenced by:
    TABLE ""abuseMessage"" CONSTRAINT "abuseMessage_abuseId_fkey" FOREIGN KEY ("abuseId") REFERENCES abuse(id) ON UPDATE CASCADE ON DELETE CASCADE
    TABLE ""commentAbuse"" CONSTRAINT "commentAbuse_abuseId_fkey" FOREIGN KEY ("abuseId") REFERENCES abuse(id) ON UPDATE CASCADE ON DELETE CASCADE
    TABLE ""userNotification"" CONSTRAINT "userNotification_abuseId_fkey" FOREIGN KEY ("abuseId") REFERENCES abuse(id) ON UPDATE CASCADE ON DELETE CASCADE
    TABLE ""videoAbuse"" CONSTRAINT "videoAbuse_abuseId_fkey" FOREIGN KEY ("abuseId") REFERENCES abuse(id) ON UPDATE CASCADE ON DELETE CASCADE


peertube_peertube-# 

This way you should be able to find the information you are looking for. In short:

  • connect with the databasemanager as user postgres
  • list databases with \l
  • connect with the peertube database using \c <peertubedatabase>
  • list tables using \dt
  • to get the general gist of a table, just select the whole table, select * from video
  • to find details on the table definition use \d <tablename>

Without knowing more about the logic on the database, be careful updating fields in the database directly. If integrity of data is enforced on a level above the database, you can create inconsistencies in your data when you do not use the logic layer to access the data. (I also don’t know, so can’t give a pointer here :stuck_out_tongue: )

Thank you for your help. Actually, i solved this issue. I installed PgAdmin and then connect the database to PgAdmin so, in this way i can see the database schema as well as the relation among the different tables :slight_smile: .

Ah, great! Good luck with the updates :slight_smile:

Consider ticking the ‹ solution ›-box on your answer and/or changing the topic title to indicate the problem is solved!

If you are updating some fields from a plugin, please be carefull to not break migration scripts. Plugins should not change the database structure.

If you miss some features in plugin helpers, it would be better to ask for «new features» on the issue tracker, explain why, and discuss for a solution.