# Write or append this content to db/schema.rb in some way
File.open("db/schema.rb", "a") do |file|
  file.puts(content) if content.present?
end
```

By taking these steps to define foreign keys, you can produce an ER diagram closer to your expectations.

You can find sample implementations for this case on GitHub:

- GitHub Actions: [.github/workflows/rails-add-association-foreign-key.yml](https://github.com/liam-hq/liam-erd-samples/blob/main/.github/workflows/rails-add-association-foreign-key.yml)
- Rails App: [samples/rails-add-association-foreign-key](https://github.com/liam-hq/liam-erd-samples/tree/main/samples/rails-add-association-foreign-key)

## Pro Tips: Using `Schemafile` Instead of `db/schema.rb`

<Callout title="warn" type="warn">Please note that this approach can be somewhat complicated or may not work as expected.</Callout>

If your project uses a tool called [Ridgepole](https://github.com/ridgepole/ridgepole), you might have a `Schemafile` instead of a `db/schema.rb`.

A `Schemafile` uses a DSL similar to what appears in `db/schema.rb`, so handing `Schemafile` directly to Liam CLI might work in some cases.

However, because users can write arbitrary Ruby code in a `Schemafile`, there may be scenarios where it isn’t fully compatible. If the output is not what you expect, consider generating a `db/schema.rb` using the methods described above (e.g., `rails db:schema:dump`) and then parsing that file.


---
title: Amazon Redshift
---

TBD


---
title: Snowflake
---

TBD


---
title: SQLite
---

Currently, SQLite is supported through the tbls integration. While direct SQLite support is not yet implemented, you can use tbls as a workaround to generate schema documentation for your SQLite database.

## Using tbls with SQLite

1. First, install tbls by following the [installation instructions](https://github.com/k1LoW/tbls?tab=readme-ov-file#install)

2. Use tbls to generate a schema.json file from your SQLite database:

```bash
tbls out -t json -o schema.json "sqlite:///path/to/dbname.db"
```

Replace `/path/to/dbname.db` with the path to your SQLite database file.

3. Use the generated schema.json with Liam:

```bash
npx @liam-hq/cli erd build --format=tbls --input schema.json
```

For more details about using tbls format, see the [tbls documentation](/docs/parser/supported-formats/tbls#using-tbls-json-output).

## Direct SQLite Support

Direct SQLite support is planned but not yet implemented. If you're interested in this feature, please follow or contribute to the discussion on [GitHub](https://github.com/liam-hq/liam/discussions/364).


---
title: tbls
---

import { Tab, Tabs } from "fumadocs-ui/components/tabs";

[tbls](https://github.com/k1LoW/tbls) is a CI-friendly tool for documenting a database schema.
If you're using tbls, in most cases you can automatically generate a useful ER diagram with Liam ERD. This page provides instructions and tips for generating an ER diagram in a tbls project.

## Using tbls JSON Output

First, generate a JSON schema file using tbls:

```bash
tbls out -t json schema.json
```

Then use Liam CLI to build an ER diagram from the JSON file:

```npm
npx @liam-hq/cli erd build --format tbls --input schema.json
```

If the command runs successfully, an ER diagram will be generated in the `dist` directory.

## Integration with CI/CD

You can integrate tbls and Liam ERD in your CI/CD pipeline to automatically generate and deploy ER diagrams. Here's an example GitHub Actions workflow:

```yaml
name: Generate ERD from tbls

on:
  push:
    branches:
      - main

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup tbls
        uses: k1low/setup-tbls@v1

      - name: Generate tbls JSON
        run: tbls out -t json schema.json

      - name: Generate ER Diagram
        run: npx @liam-hq/cli erd build --input schema.json --format tbls

      # Deploy (example using GitHub Pages)
      - name: Deploy to GitHub Pages
        uses: actions-gh-pages/action@v2
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: dist
```

For more information about CI/CD integration, see [CI/CD Integration](/docs/cli/ci-cd).

## Under the Hood

Liam ERD utilizes tbls's JSON schema output format ([schema definition](https://github.com/k1LoW/tbls/blob/main/spec/tbls.schema.json_schema.json)) to convert schemas into Liam's internal format.


---
title: Troubleshooting Parser
---

TBD


---
title: Browsing Your Schema
description: >
  Explore your database schema with ease using intuitive navigation tools like panning, zooming, filtering, and highlighting. 
  Liam ERD helps you interact with complex structures efficiently and clearly.
---

## Pan and Zoom

The diagram interface supports smooth pan and zoom operations, allowing you to understand the overall structure while focusing on specific areas.

![Pan and Zoom](/images/content/docs/ui-features/browsing-your-schema/pan-and-zoom.gif)

You can control diagram movement and zoom in the following ways:

- **Pan (Move) Operations**:
  - Press space key + drag to move the view

- **Zoom Operations**:
  - `Ctrl` + scroll up to zoom in, scroll down to zoom out
  - Pinch in/out on trackpad for smooth zooming
  - Use `+`/`-` buttons in the toolbar to zoom in/out

## Tidy Up

The auto-layout feature helps optimize table placement.

![Tidy Up](/images/content/docs/ui-features/browsing-your-schema/tidy-up.gif)

- Automatically align tables with one click
- Optimal placement considering relationships
- Manual layout adjustments also possible

## Zoom to Fit

Display the entire diagram to fit within the screen.

![Zoom to Fit](/images/content/docs/ui-features/browsing-your-schema/zoom-to-fit.gif)

- Automatically adjust to show all tables
- Set optimal zoom level based on visible tables

## Filtering Related Tables

Make complex relationships easier to understand by displaying only tables related to specific ones.

![Filtering Related Tables](/images/content/docs/ui-features/browsing-your-schema/filtering-related-tables.gif)

- Select a table and switch to related tables view from the right panel when highlighted

## Relation Highlights

Visually confirm and emphasize relationships between tables in your schema.

![Relation Highlights](/images/content/docs/ui-features/browsing-your-schema/relation-highlights.gif)

- Highlight related relations when hovering or clicking on tables
- Visual distinction through color highlighting

## Show Hide Each Table

Simplify complex schemas by showing only necessary tables.

![Show Hide Each Table](/images/content/docs/ui-features/browsing-your-schema/show-hide-each-table.gif)

- Toggle visibility of individual tables
- Toggle individual table visibility using the show/hide icon button in the left panel



---
title: Command Palette
description: >
  Quickly navigate to any table in your schema using the Command Palette. 
  Search and jump to tables instantly with keyboard shortcuts and real-time preview.
---

## Overview

The Command Palette is a powerful search interface that allows you to quickly find and navigate to any table in your database schema. It's especially useful when working with large schemas containing many tables, providing instant access without manual scrolling or browsing.

## Opening the Command Palette

You can open the Command Palette in two ways:

- **Keyboard shortcut**: Press `Cmd+K` (Mac) or `Ctrl+K` (Windows/Linux)
- **Click**: Use the search icon in the top-right corner of the interface

![Command Palette Opening](/images/content/docs/ui-features/command-palette/opening.gif)

## Basic Usage

### Searching for Tables

1. **Open the Command Palette** using one of the methods above
2. **Type the table name** or part of it in the search field
3. **Browse results** as they appear in real-time
4. **Select a table** using keyboard navigation or mouse clicks

The search supports fuzzy matching, so you don't need to type the exact table name. For example, typing "user" will find tables like "users", "user_roles", "user_profiles", etc.

### Keyboard Navigation

- **Arrow Keys**: Use `↑` and `↓` to navigate through search results
- **Enter**: Navigate to the selected table in the current view
- **Cmd/Ctrl + Enter**: Open the selected table in a new tab
- **Escape**: Close the Command Palette

### Mouse Navigation

- **Click**: Navigate to the table in the current view
- **Cmd/Ctrl + Click**: Open the table in a new tab

## Table Preview

When you select a table in the search results, the Command Palette displays a real-time preview of the table structure on the right side. This preview shows:

- Table name and structure
- Column names and types
- Primary keys and constraints
- Visual representation identical to the main ERD view

This preview helps you confirm you're selecting the correct table before navigating, especially when dealing with similarly named tables.

## Features

### Fuzzy Search

The Command Palette uses fuzzy search powered by [Fuse.js](https://fusejs.io/), which means:

- **Partial matches**: Type any part of the table name
- **Case insensitive**: Works regardless of capitalization
- **Typo tolerance**: Handles minor spelling mistakes
- **Real-time results**: Updates as you type

### URL Integration

When you navigate to a table using the Command Palette, the URL is updated with the appropriate query parameters. This means:

- **Shareable links**: The URL reflects the current table selection
- **Browser history**: You can use back/forward buttons
- **Bookmarkable**: Save direct links to specific tables

## Use Cases

The Command Palette is particularly useful for:

- **Large schemas**: Quickly finding tables in databases with hundreds of tables
- **Partial recall**: When you remember only part of a table name
- **Efficient navigation**: Avoiding manual scrolling through long table lists
- **Presentation mode**: Quickly jumping between tables during demos or reviews
- **Development workflow**: Fast access to relevant tables during code reviews

## Tips and Best Practices

- **Use partial names**: You don't need to type the full table name
- **Try different keywords**: Search for functional terms that might appear in table names
- **Use keyboard shortcuts**: `Cmd/Ctrl+K` is faster than clicking the search icon
- **Preview before navigating**: Use the preview pane to confirm the correct table
- **Open in new tabs**: Use `Cmd/Ctrl+Enter` when comparing multiple tables


---
title: UI Features
description: Overview of user interface features in Liam ERD
---

import { source } from "../../../lib/source"
import { DocsCategory } from "fumadocs-ui/page"

<DocsCategory page={source.getPage(["ui-features"])} from={source} />


---
title: Sharing & Query Parameters
---

## The Importance of Sharing

ER diagrams are most valuable when used collaboratively within a team. They serve as essential tools for:
- Aligning understanding across team members
- Onboarding new team members
- Documenting and discussing database design decisions

## URL-Based Sharing in Liam ERD

Liam ERD makes sharing specific views of your database schema seamless by reflecting almost all UI configurations in URL query parameters. This means you can share:

- Filtered views showing only relevant tables
- Specific table details
- Custom visualization settings

![Share](/images/content/docs/ui-features/sharing-and-query-params/share.gif)

## Available URL Parameters

| Parameter | Values | Description |
|-----------|--------|-------------|
| showMode | 'ALL_FIELDS' / 'TABLE_NAME' / 'KEY_ONLY' | Controls the level of detail shown in the ER diagram |
| active | string | The currently selected table name (opens detail pane) |
| hidden | string | Compressed array of hidden table names |


---
title: Liam ERD Web
---

Liam ERD Web is an online tool hosted by [@liam-hq](https://github.com/liam-hq) that allows you to explore real-world ER diagrams without needing to install a CLI! 🛸💫

It enables you to view ER diagrams generated from publicly available schema files, such as `db/schema.rb`, `prisma.schema`, or SQL files derived from `pg_dump`.

## How to Explore

Inserting `liambx.com/erd/p/` into your browser's address bar will generate an ER diagram for your schema file.

![Inserting Animation](/images/content/docs/web.gif)

For example, if the schema file you want to explore is hosted at the following URL:

```