<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Truong-Phat Nguyen - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Truong-Phat Nguyen - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 01 Jun 2026 05:27:59 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/patrickphatng/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Create Database Documentation Using dbdocs with DBML ]]>
                </title>
                <description>
                    <![CDATA[ Database documentation plays a crucial role in maintaining and scaling systems. Clear and well-organized documentation can significantly improve communication between team members and enhance project longevity. One of the most efficient ways to docum... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/create-database-documentation-using-dbdocs-with-dbml/</link>
                <guid isPermaLink="false">670d3f2e7e2c70da5a203bba</guid>
                
                    <category>
                        <![CDATA[ Databases ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Devops ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ci-cd ]]>
                    </category>
                
                    <category>
                        <![CDATA[ data ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Truong-Phat Nguyen ]]>
                </dc:creator>
                <pubDate>Mon, 14 Oct 2024 15:56:30 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1728620241328/79515009-0fa3-4fcd-a4ce-e1ec2d5609f8.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Database documentation plays a crucial role in maintaining and scaling systems. Clear and well-organized documentation can significantly improve communication between team members and enhance project longevity.</p>
<p>One of the most efficient ways to document a database is through <a target="_blank" href="https://dbdocs.io/"><strong>dbdocs</strong></a> and <a target="_blank" href="https://dbml.dbdiagram.io/home"><strong>DBML</strong></a> - an open sourced Database Markup Language.</p>
<p>In this guide, I’ll show you how to create database documentation using these tools, step by step.</p>
<h1 id="heading-what-is-dbdocs"><strong>What is dbdocs?</strong></h1>
<p><a target="_blank" href="https://dbdocs.io/"><strong>dbdocs</strong></a> is a platform that generates database documentation from your schema, easily shareable via a link. Using <a target="_blank" href="https://dbml.dbdiagram.io/home"><strong>DBML</strong></a> <strong>(Database Markup Language)</strong>, you can create clear, shareable, and updatable documentation of your database structure.</p>
<h2 id="heading-prerequisites"><strong>Prerequisites</strong></h2>
<p>Before we begin, ensure you have the following:</p>
<ul>
<li><p>Basic knowledge of databases and SQL.</p>
</li>
<li><p>A database schema to document (we’ll use a PostgreSQL example in this guide).</p>
</li>
</ul>
<h2 id="heading-step-1-install-dbml-cli-and-dbdocs"><strong>Step 1: Install DBML CLI and dbdocs</strong></h2>
<p>Start by installing the <strong>DBML CLI</strong>, which helps convert your database schema into a DBML format. You also need the <strong>dbdocs CLI</strong> to generate and publish your documentation.</p>
<pre><code class="lang-bash">npm install -g dbdocs
</code></pre>
<h2 id="heading-step-2-export-your-database-schema-to-dbml"><strong>Step 2: Export Your Database Schema to DBML</strong></h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728615902517/20974a9d-729e-4b3a-997c-0b89e944a6cd.png" alt="DB diagram" class="image--center mx-auto" width="1818" height="514" loading="lazy"></p>
<p>If you’re working with an existing database, you can export the schema into DBML using the DBML CLI tool.</p>
<p>For PostgreSQL, run the following command:</p>
<pre><code class="lang-bash">$ dbdocs db2dbml postgres &lt;connection-string&gt; -o database.dbml

✔ Connecting to database &lt;db-name&gt;... <span class="hljs-keyword">done</span>.
✔ Generating DBML... <span class="hljs-keyword">done</span>.
✔ Wrote to database.dbml
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728615885904/9f68f18b-fa14-4e88-b58b-bd90d292ef31.gif" alt="Extract DBML code from database connection" class="image--center mx-auto" width="700" height="400" loading="lazy"></p>
<p>This command will export your database schema and save it into a file called <code>database.dbml</code>.</p>
<p>Here’s an example of how a generated DBML file might look:</p>
<pre><code class="lang-bash">Table users {
  id int [pk, increment]
  username varchar(50) [not null]
  email varchar(100) [not null, unique]
  created_at timestamp [not null]
}

Table orders {
  id int [pk, increment]
  user_id int [not null, ref: &gt; users.id]
  total decimal [not null]
  created_at timestamp [not null]
}
</code></pre>
<p><strong>In this example:</strong></p>
<p>• The users and orders tables are defined.</p>
<p>• Fields are annotated with types and constraints.</p>
<p>• The relationship between <code>orders.user_id</code> and <code>users.id</code> is established using <code>ref</code>.</p>
<h2 id="heading-step-3-edit-and-add-notes-to-the-dbml-file"><strong>Step 3: Edit and Add Notes to the DBML File</strong></h2>
<p>You may want to clean it up or add extra documentation like table descriptions and field descriptions to communicate with other members in the team.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728615980279/8e1851a8-2e38-4ded-8b6a-c873d6b395b8.gif" alt="Add notes to generated DBML Code" class="image--center mx-auto" width="800" height="501" loading="lazy"></p>
<h2 id="heading-step-4-generate-documentation-with-dbdocs"><strong>Step 4: Generate Documentation with dbdocs</strong></h2>
<p>Once your DBML file is ready, the next step is to generate the documentation using dbdocs. First, you need to login to dbdocs:</p>
<pre><code class="lang-bash">dbdocs login
</code></pre>
<p>After logging in, publish the DBML file:</p>
<pre><code class="lang-bash">dbdocs build database.dbml
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728616039961/0ef67db3-8a86-495a-b42f-3fad0fead933.gif" alt="Generate database documentation from DBML file" class="image--center mx-auto" width="800" height="499" loading="lazy"></p>
<p>This command will generate a shareable documentation link that you can access via the dbdocs platform. You can also set access permissions and collaborate with your team.</p>
<p>This seamless workflow ensures that your documentation always reflects the latest state of your database.</p>
<h1 id="heading-benefits-of-using-dbdocs-with-dbml"><strong>Benefits of Using dbdocs with DBML</strong></h1>
<ul>
<li><p><strong>Simplicity</strong>: The <a target="_blank" href="https://dbml.dbdiagram.io/home">DBML</a> syntax is simple and easy to learn, making it a perfect fit for teams.</p>
</li>
<li><p><strong>Automation</strong>: You can <a target="_blank" href="https://docs.dbdocs.io/features/generate-dbml-from-db">automate your database documentation updates</a> as part of your <a target="_blank" href="https://docs.dbdocs.io/features/ci-integration">CI/CD pipeline</a>.</p>
</li>
<li><p><strong>Collaboration</strong>: Easily <a target="_blank" href="https://docs.dbdocs.io/features/project-access-control">share documentation links</a> with your team or stakeholders for easy access and discussion.</p>
</li>
<li><p><strong>Version Control:</strong> Use <a target="_blank" href="https://docs.dbdocs.io/features/schema-changelog">schema changelog</a> to track database schema changes over time.</p>
</li>
<li><p><strong>Visualization</strong>: dbdocs provides a clean interface to visualize your database schema, relationships, and annotations. <a target="_blank" href="https://dbdocs.io/Holistics/Ecommerce">Try this demo</a> to learn more.</p>
</li>
</ul>
<h1 id="heading-conclusion"><strong>Conclusion</strong></h1>
<p>In this tutorial, we explored how to export a database schema, customize it, and generate shareable documentation using dbdocs.</p>
<p>By incorporating this workflow into your development process, you’ll improve your team’s collaboration, enhance your project’s scalability, and ensure that everyone stays on the same page. Happy documenting!</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
