# Database's Data Model?

**URL:** https://meta.discourse.org/t/databases-data-model/93668
**Category:** Support
**Created:** [August 1, 2018, 6:02pm UTC](https://meta.discourse.org/t/databases-data-model/93668 "2018-08-01T18:02:54Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![zapata\_36](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zapata_36/32/83866_2.png) [@zapata\_36](https://meta.discourse.org/u/zapata_36)
#### Post date: [August 1, 2018, 6:02pm UTC](https://meta.discourse.org/t/databases-data-model/93668/1 "2018-08-01T18:02:54Z")

</div>

If we want to export the database and run certain queries against it, say in Tableau, would it just be guess work or can someone point to a community resource on the database’s data model?

I’ve found an older post with a diagram/schema of the database’s tables, but does anyone know if there’s a data dictionary that explains each of the individual items and what they do?

I’m not an expert on this sort of stuff, so apologies in advance if I’m using the wrong language. Hopefully my question makes sense!

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [August 1, 2018, 8:39pm UTC](https://meta.discourse.org/t/databases-data-model/93668/2 "2018-08-01T20:39:13Z")

</div>

I don’t think something like that exists as such diagrams tend to get outdated quite fast.

But the table and column names are quite self explanatory. I recommend you take a look at the database with the [Discourse Data Explorer](https://meta.discourse.org/t/data-explorer-plugin/32566) or your favorite database tool. You can always come back with specific questions if you don’t find the data you are looking for.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [August 2, 2018, 6:02am UTC](https://meta.discourse.org/t/databases-data-model/93668/3 "2018-08-02T06:02:34Z")

</div>

And if you have any questions that the column name / [Data Explorer](https://meta.discourse.org/t/32566?silent=true) enum explanation doesn’t resolve, check out `app/model/table_name.rb` in the Discourse source code!

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [August 2, 2018, 7:01am UTC](https://meta.discourse.org/t/databases-data-model/93668/4 "2018-08-02T07:01:44Z")

</div>

I often prefer the command line.

```plaintext
cd /var/discourse 
sudo ./launcher enter app

```

enter password, then  
`sudo -u postgres psql discourse`

Then, _being very careful_ I run queries like

```plaintext
SELECT table_name, table_type 
FROM INFORMATION_SCHEMA.TABLES 
WHERE table_catalog = 'discourse' 
AND table_schema = 'public'; 

```

\* currently 138 rows

```plaintext
SELECT table_name, column_name, data_type, column_default, character_maximum_length 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE table_catalog = 'discourse' 
AND table_schema = 'public' 
ORDER BY table_name;

```

\* currently 1258 rows, a good idea to have a `WHERE table_name = '{{some table name here}}'` or a `LIMIT` in that query.

---

<div class="post-metadata">

### Author: ![Bas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bas/32/294929_2.png) [@Bas](https://meta.discourse.org/u/Bas)
#### Post date: [August 2, 2018, 8:39am UTC](https://meta.discourse.org/t/databases-data-model/93668/5 "2018-08-02T08:39:45Z")

</div>

I can’t find this file here?  
[discourse/app/models at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/tree/master/app/models)

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [August 2, 2018, 8:59am UTC](https://meta.discourse.org/t/databases-data-model/93668/6 "2018-08-02T08:59:18Z")

</div>

The “table\_name” is a place holder for an actual file name. The file names are the singular of the table names. eg. user.rb - the users table, group.rb - the groups table.

at the bottom of each is similar to

```plaintext
# == Schema Information
#
# Table name: drafts
#
# id :integer not null, primary key
# user_id :integer not null
# draft_key :string not null
# data :text not null
# created_at :datetime not null
# updated_at :datetime not null
# sequence :integer default(0), not null
# revisions :integer default(1), not null
#
# Indexes
#
# index_drafts_on_user_id_and_draft_key (user_id,draft_key)
#

```

---

<div class="post-metadata">

### Author: ![Bas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bas/32/294929_2.png) [@Bas](https://meta.discourse.org/u/Bas)
#### Post date: [August 2, 2018, 9:01am UTC](https://meta.discourse.org/t/databases-data-model/93668/7 "2018-08-02T09:01:16Z")

</div>

Ah got it, sorry, was a bit confused 😴

Hoped there was a table\_names overview 🙂

---

<div class="post-metadata">

### Author: ![Konrad\_Sopala](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/konrad_sopala/32/167014_2.png) [@Konrad\_Sopala](https://meta.discourse.org/u/Konrad_Sopala)
#### Post date: [August 6, 2020, 12:54pm UTC](https://meta.discourse.org/t/databases-data-model/93668/8 "2020-08-06T12:54:59Z")

</div>

Hey there!

Thanks for creating that thread. Got one more core question how to connect to that as a data source in Tableau?
