# Update Diagram Source: https://docs.chartdb.io/docs/api/diagram/update-diagram POST /api/update_diagram/{diagram_id} Update an existing database diagram The Update Diagram endpoint allows you to modify an existing database diagram's properties. ## Authorizations Bearer authentication header of the form `Bearer `, where `` is your auth token from ChartDB starts with `ch_`. ## Path Parameters The unique identifier of the diagram. ## Request Body New name for the diagram. Updated diagram settings in JSON format. (See [Examples](/docs/api/examples/postgresql) for more information) ```bash cURL theme={null} curl -X POST https://api.chartdb.io/api/update_diagram/123456789 \ -H "Authorization: Bearer ch_123456789" \ -H "Content-Type: application/json" \ -d '{ "diagram_name": "Updated E-commerce Diagram", "json_metadata": { "fk_info": [], "pk_info": [], "columns": [], "indexes": [], "tables": [], "views": [], "database_name": "postgres" } }' ``` ```json Response theme={null} { "status": "success", "message": "Diagram updated successfully" } ``` # Embeded Diagrams Source: https://docs.chartdb.io/docs/api/embeded-diagrams API endpoints for managing database diagrams ## Private Access with API Keys You can access private diagrams without authentication by using an API key in the diagram's URL. This is particularly useful for: * Embedding private diagrams in documentation * Sharing diagrams with specific users without requiring them to log in * Integrating diagrams in internal tools ### Getting the Embedded Link 1. Go to your API Keys settings in ChartDB 2. Find the API key associated with your diagram 3. Click the three dots menu (⋮) and select "Copy Embedded Link" ### Usage Simply append your API key as a query parameter to the diagram URL: ``` https://app.chartdb.io/diagram/{diagram_id}?api_key={your_api_key} ``` Example: ``` https://app.chartdb.io/diagram/9df7f9d1e30c442c94bd04?api_key=ch_529b512d_4bcd79e15f8ef1b1019f5317 ``` ### Benefits * **No Authentication Required**: Users can view private diagrams directly through the URL * **Granular Access Control**: Each API key can be scoped to specific diagrams * **Secure Sharing**: Share diagrams privately without exposing them publicly * **Easy Integration**: Perfect for embedding in documentation, wikis, or internal tools ### Security Considerations * Keep your API keys secure and rotate them periodically * Each API key should only have access to the diagrams it needs * Monitor API key usage through your ChartDB dashboard # Import Cloudflare D1 Source: https://docs.chartdb.io/docs/api/examples/cloudflare-d1 Import your Cloudflare D1 database schema into ChartDB ## Download Import Script Download our Cloudflare D1 import script: ```bash theme={null} curl -O https://app.chartdb.io/bash-scripts/cloudflare-d1-import.sh chmod +x cloudflare-d1-import.sh ``` ## Usage Run the script with your Cloudflare D1 database name and ChartDB information: ```bash theme={null} ./cloudflare-d1-import.sh \ -d your-database-name \ -a your-chartdb-api-key \ -t your-diagram-id ``` For remote databases, add the `-r` flag: ```bash theme={null} ./cloudflare-d1-import.sh \ -d your-database-name \ -a your-chartdb-api-key \ -t your-diagram-id \ -r ``` ### Required Parameters * `-d` Cloudflare D1 database name * `-a` ChartDB API key * `-t` Target diagram ID ### Optional Parameters * `-r` Use remote database (if not specified, uses local database) The script will connect to your Cloudflare D1 database, extract the schema, and automatically import it into your ChartDB diagram. ## Automated Daily Updates To automatically update your diagram daily using cron, add the following line to your crontab: ```bash theme={null} # Run at 2 AM every day 0 2 * * * /path/to/cloudflare-d1-import.sh -d database_name -a api_key -t diagram_id >> /path/to/d1-import.log 2>&1 ``` To edit your crontab: ```bash theme={null} crontab -e ``` **Note:** Replace `/path/to/cloudflare-d1-import.sh` with the absolute path to the script and adjust the database name accordingly. The log file path (`/path/to/d1-import.log`) should be in a directory where your user has write permissions. # Import MySQL Source: https://docs.chartdb.io/docs/api/examples/mysql Import your MySQL database schema into ChartDB ## Download Import Script Download our MySQL import script: ```bash theme={null} curl -O https://app.chartdb.io/bash-scripts/mysql-import.sh chmod +x mysql-import.sh ``` ## Usage Run the script with your database credentials and ChartDB information: ```bash theme={null} ./mysql-import.sh \ -h your-database-host \ -P 3306 \ -u your-database-user \ -p your-database-password \ -d your-database-name \ -a your-chartdb-api-key \ -t your-diagram-id ``` ### Required Parameters * `-h` Database hostname * `-P` Database port (default: 3306) * `-u` Database username * `-p` Database password * `-d` Database name * `-a` ChartDB API key * `-t` Target diagram ID The script will connect to your database, extract the schema, and automatically import it into your ChartDB diagram. ## Automated Daily Updates To automatically update your diagram daily using cron, add the following line to your crontab: ```bash theme={null} # Run at 2 AM every day 0 2 * * * /path/to/mysql-import.sh -h host -P 3306 -u user -p pass -d dbname -a api_key -t diagram_id >> /path/to/mysql-import.log 2>&1 ``` To edit your crontab: ```bash theme={null} crontab -e ``` **Note:** Replace `/path/to/mysql-import.sh` with the absolute path to the script and adjust the credentials accordingly. The log file path (`/path/to/mysql-import.log`) should be in a directory where your user has write permissions. # Import PostgreSQL Source: https://docs.chartdb.io/docs/api/examples/postgresql Import your PostgreSQL database schema into ChartDB using a single query ## Download Import Script Download our PostgreSQL import script: ```bash theme={null} curl -O https://app.chartdb.io/bash-scripts/psql-import.sh chmod +x psql-import.sh ``` ## Usage Run the script with your database credentials and ChartDB information: ```bash theme={null} ./psql-import.sh \ -h your-database-host \ -p 5432 \ -U your-database-user \ -d your-database-name \ -W your-database-password \ -a your-chartdb-api-key \ -t your-diagram-id ``` ### Required Parameters * `-h` Database hostname * `-p` Database port (default: 5432) * `-U` Database username * `-d` Database name * `-W` Database password * `-a` ChartDB API key * `-t` Target diagram ID The script will connect to your database, extract the schema, and automatically import it into your ChartDB diagram. ## Automated Daily Updates To automatically update your diagram daily using cron, add the following line to your crontab: ```bash theme={null} # Run at 2 AM every day 0 2 * * * /path/to/psql-import.sh -h host -p 5432 -U user -W pass -d dbname -a api_key -t diagram_id >> /path/to/psql-import.log 2>&1 ``` To edit your crontab: ```bash theme={null} crontab -e ``` **Note:** Replace `/path/to/psql-import.sh` with the absolute path to the script and adjust the credentials accordingly. The log file path (`/path/to/psql-import.log`) should be in a directory where your user has write permissions. # Import SQLite Source: https://docs.chartdb.io/docs/api/examples/sqlite Import your SQLite database schema into ChartDB ## Download Import Script Download our SQLite import script: ```bash theme={null} curl -O https://app.chartdb.io/bash-scripts/sqlite-import.sh chmod +x sqlite-import.sh ``` ## Usage Run the script with your database file path and ChartDB information: ```bash theme={null} ./sqlite-import.sh \ -f your-database-file.sqlite \ -a your-chartdb-api-key \ -t your-diagram-id ``` ### Required Parameters * `-f` SQLite database file path * `-a` ChartDB API key * `-t` Target diagram ID The script will connect to your database file, extract the schema, and automatically import it into your ChartDB diagram. ## Automated Daily Updates To automatically update your diagram daily using cron, add the following line to your crontab: ```bash theme={null} # Run at 2 AM every day 0 2 * * * /path/to/sqlite-import.sh -f /path/to/database.sqlite -a api_key -t diagram_id >> /path/to/sqlite-import.log 2>&1 ``` To edit your crontab: ```bash theme={null} crontab -e ``` **Note:** Replace `/path/to/sqlite-import.sh` with the absolute path to the script and adjust the file path accordingly. The log file path (`/path/to/sqlite-import.log`) should be in a directory where your user has write permissions. # ChartDB API – Programmatically Manage & Auto‑Update Diagrams Source: https://docs.chartdb.io/docs/api/introduction Use the ChartDB API to automate ER‑diagram creation and updates. Authenticated via API key, JSON‑formatted, ideal for CI/CD workflows and internal tools. ## Introduction The ChartDB API enables programmatic access to manage and auto-update your database diagrams. It supports authenticated requests using API keys, follows standard HTTP methods and response codes, and accepts JSON-formatted request and response bodies. Use the API to sync your schema changes, automate diagram generation, and integrate ChartDB into your CI/CD workflows or internal tools. ## Base URL All API requests should be made to the following base URL: ```bash theme={null} https://api.chartdb.io/api ``` ## Authentication To authenticate your requests, include an API key in the Authorization header: ```bash theme={null} Authorization: Bearer ch_123456789 ``` Your API key can be found in your ChartDB dashboard settings. Keep it secure and never share it publicly. ## Response Format All responses are returned in JSON format. Successful responses will include `status` & `message` fields: ```json theme={null} { "status": "success", "message": "Diagram updated successfully" } ``` Error responses will include `status` & `message` fields: ```json theme={null} { "status": "error", "message": "Invalid API key" } ``` ## Request Format For POST and PUT requests, send data in JSON format with the appropriate `Content-Type` header: ```bash theme={null} Content-Type: application/json ``` ## API Versioning The current version is `api`. We include versioning in the URL path: ```bash theme={null} https://api.chartdb.ioo/api/update_diagram ``` Future versions will be announced with appropriate migration guides and deprecation notices. # Cloud vs. Self-Hosted Source: https://docs.chartdb.io/docs/cloud-vs-self-hosted Understand the differences between ChartDB Cloud and Self-Hosted options ChartDB is an open-source tool that offers flexible deployment options to suit your workflow and security requirements. Whether you choose the convenience of ChartDB Cloud or the control of self-hosting ChartDB, you gain powerful database visualization features. Visualize databases instantly in your browser. Best for ease of use and team accessibility. Maintain complete control over your data and setup. Ideal for security and customization. ## Feature Comparison | Feature | ChartDB Cloud | ChartDB Self-Hosted | | ------------------- | -------------------------------------------------------------------------------------------- | --------------------------------------------------------- | | **Deployment** | Hosted by ChartDB ([app.chartdb.io](https://app.chartdb.io)) | Host it yourself (Docker, npm) | | **Data Control** | Private cloud diagrams | Full control over your data and server | | **Collaboration** | Team features (private diagrams, user sharing, versioning) | Share diagrams manually via export/import | | **User Management** | 1 user (Free/Pro), 3-25+ users (Teams plans) | No built-in user accounts | | **Support** | Community Discord (Free), Email support (Pro), Priority support (Teams+) | Community | | **AI Features** | AI Assistant included in Teams plans; optional with OpenAI API key on other plans | Optional, OpenAI API key required | | **Privacy** | Secure cloud storage | Host within your secure environment | | **Customization** | Basic UI settings within the app | Modify source code for deep customization | | **Automated Sync** | Programmatically sync database changes to diagrams via API (no credentials required) | N/A | | **Embedding** | Embed interactive diagrams in documentation, websites, or applications | N/A | | **Table Limits** | 10 tables (Free), up to 100 (Pro), up to 200 (Teams) [Pricing →](https://chartdb.io/pricing) | No table limits - visualize as many tables as you need | | **Cost** | Free tier available; paid plans for Pro and Teams [Pricing →](https://chartdb.io/pricing) | Free (open-source), infrastructure costs for self-hosting | Some features like embedding, automated sync, and team collaboration are exclusive to ChartDB Cloud. Supporting these features locally comes with a lot of additional complexity, syncing, and maintaining a consistent experience across different environments. For now, we've prioritized making the cloud version as seamless as possible so we can move fast, iterate, and offer the best experience. ## Making the Right Choice **Choose ChartDB Cloud if:** * You need a quick and easy way to visualize databases. * You prefer a managed solution without server setup. * Team collaboration and private diagrams are important. * You want to get started right away with minimal hassle. * [Learn more about pricing →](https://chartdb.io/pricing) **Choose ChartDB Self-Hosted if:** * You need unlimited tables with no caps or restrictions. * Data security and compliance are critical requirements. * You require complete control over your data and infrastructure. * Offline access is necessary. * You need extensive customization or integration capabilities. * Note: Cloud features like team collaboration and private diagrams are not directly available in the self-hosted version. Start with ChartDB Cloud to experience its benefits immediately with team collaboration and private diagrams, or consider self-hosting for full control. [Learn more about pricing →](https://chartdb.io/pricing) # Visualize Dependencies Source: https://docs.chartdb.io/docs/diagrams/dependencies Explore and understand database relationships between Views and Tables in ChartDB In ChartDB, dependencies focus on database Views and their underlying Tables. ChartDB automatically detects and displays dependencies based on the imported database schema, specifically from View definitions. You cannot manually create or edit dependencies directly within ChartDB at this time. ## View Dependencies ChartDB provides a dedicated "Dependencies" section in the sidebar to easily explore these relationships. Navigate to the **Dependencies** section in the ChartDB sidebar. Select a View from the Dependencies list. ChartDB will highlight the selected View and the Tables it depends on directly on your database diagram canvas. # Editing Layouts, Modifying Colors, and Filtering Tables Source: https://docs.chartdb.io/docs/diagrams/layouts-colors-filters Organize diagram layouts, apply visual styling, and implement filtering to create create and insightful database diagrams. Automatically reorganize your diagram for optimal readability. Align tables precisely to a grid for a cleaner diagram. Instantly identify and resolve table overlaps. Navigate your diagram with zoom in, zoom out, show all, and 100% zoom options. Show or hide the sidebar to maximize your canvas workspace. Customize table colors to visually group and highlight elements in your diagram. Filter the table list in the sidebar to easily find specific tables. ## Reorder Diagram The **Reorder Diagram** button helps you automatically arrange tables in your diagram based on their relationships, optimizing for visibility. Use this feature to quickly structure your diagram after adding or moving tables. Click the **Reorder Diagram** button in the top-left toolbar of the canvas. In the confirmation dialog, click **Reorder** to proceed. ChartDB will intelligently rearrange your tables. ## Snap to Grid The **Snap to Grid** feature ensures tables align to a grid, creating a more organized and visually consistent diagram. Click the **Snap to Grid** button in the toolbar to enable or disable grid snapping. When enabled, the button is highlighted, and dragging tables will automatically snap them to the grid. To temporarily snap tables to the grid while the feature is disabled, hold down the `Shift` key while dragging. ## Overlap Highlighting **Overlap Highlighting** helps you identify tables that are overlapping in your diagram. The button will automatically appear when at least two tables are overlapping. Clicking the **Overlap Highlighting** button will navigate you to the area of the diagram where the overlap occurs, allowing you to manually resolve the overlap or use the **Reorder Diagram** feature. ## Zoom Controls ChartDB provides intuitive zoom controls at the bottom center of the canvas to navigate your diagram effectively. Click the **Show All** button to fit the entire diagram within the viewport. **Shortcut:** Use **`Command + 0`**. Use the **Zoom In** and **Zoom Out** buttons for incremental zoom adjustments. Click the zoom level indicator (e.g., `66%`) to reset the zoom level to 100%. ## Sidebar Visibility Maximize your canvas workspace by showing or hiding the sidebar as needed. 1. Click **View** in the top menu bar. 2. Select **Hide Sidebar** or **Show Sidebar** to toggle visibility. Use the shortcut **`Command + B`** to quickly toggle the sidebar's visibility. ## Table Colors Customize table colors to visually organize and highlight elements within your database diagram. Click on the table on the canvas or select it from the sidebar. In the sidebar, within the table details, locate and open the color picker control. Select your desired color from the color picker. The table color will update in real-time. Use color to visually group related tables or highlight key entities for better diagram comprehension. ## Sidebar Filters Filter the table list in the sidebar to quickly locate and manage specific tables, especially in large database schemas. Filtering in ChartDB currently only affects the table list in the sidebar. It does not filter tables directly on the canvas diagram. Click into the **Filter tables** input field at the top of the sidebar. Shortcut: **Command + F** Type your filter term into the input field. The sidebar table list will dynamically update to show matching tables. **Delete the text in the filter input to clear the filter** and show all tables again. # Creating Relationships with Foreign Keys Source: https://docs.chartdb.io/docs/diagrams/relationships Learn how to create database relationships in ChartDB using foreign keys. In ChartDB, relationships between tables are established through **foreign keys**. This means a column in one table (the **primary table**) points to a column in another table (the **referencing table**), linking records that belong together. For a relationship to be valid, the [field types](/diagrams/tables-fields#data-type) of the columns you choose in both the primary and referencing tables **must match**. ## Create Relationships ChartDB offers three user-friendly ways to create relationships between your database tables: This is the most straightforward and visually intuitive method for creating relationships. To create a relationship, simply click and drag from a connection dot on your primary table to a column in your target table. ChartDB will highlight compatible columns as you drag. This method provides an alternative, especially useful when tables are positioned far apart on the canvas, making drag and drop less convenient. Right-click on any table and select "Create Relationship" from the menu. In the sidebar that appears, select your primary and referencing tables, choose the columns to connect, and click Save to create the relationship. ChartDB also provides a dedicated "Relationship" menu within its interface, offering a structured approach to relationship management. Navigate to the "Relationship" menu and click "Add Relationship". In the configuration sidebar, select your primary and referencing tables, choose the columns to connect, and click Save to create the relationship. ## View Relationship Cardinality By default, cardinality indicators are not visible on the diagram. To display the cardinality of relationships: * In the top menu bar of ChartDB, click on the **View** dropdown menu and click on the **Show Cardinality** option from the dropdown. Once enabled, ChartDB will display cardinality indicators (e.g., 1, N) on the relationship lines in your diagram, visually representing the type of relationship (one-to-many, many-to-many, etc.). ## Modify Relationship Cardinality ChartDB supports 4 relationship cardinalities, including **One-to-One**, **One-to-Many**, **Many-to-One**, and **Many-to-Many**. To adjust the **cardinality** of a relationship: 1. **Select the Relationship:** Click on the relationship line connecting the two tables in your diagram. This will typically open the relationship details in the sidebar. 2. **Modify Cardinality:** In the sidebar, you will find a dropdown menu labeled "Cardinality" or similar. Use this menu to select the new cardinality for the relationship. Once you've created a relationship, ChartDB immediately visualizes it on your diagram. You'll see a line connecting the related tables, clearly indicating the established link. # Adding Tables and Fields Source: https://docs.chartdb.io/docs/diagrams/tables-fields Learn how to add and manage tables and fields in ChartDB to visualize your database schema effectively. ChartDB provides a visual and intuitive way to add tables and fields to your database diagram. ## Add New Tables To add new tables, you can use the sidebar or interact directly with the canvas. First, **navigate to the *Tables* section** in the ChartDB sidebar and click the 'Add Table' icon. This instantly creates a new table in your diagram with a randomly generated name and a single default field. 1. **Access table actions** by clicking the settings icon next to the table name in the sidebar. 2. **Select 'Duplicate Table'** from the table actions menu. You can also quickly add or duplicate tables directly on the canvas using the right-click context menu. 1. **Right-click anywhere on the canvas.** 2. **Select 'New Table'** to add a brand new table, or **'Duplicate Table'** after selecting an existing table to clone it. You can also **edit table names directly on the canvas** by double-clicking the table name. This provides a quick and intuitive way to rename tables as you are visualizing your diagram. ## Managing Schemas In ChartDB, tables are organized within **Schemas**. Schemas act like folders, providing a way to structure and group your tables, especially in databases like PostgreSQL and MSSQL that support them. Schemas will only be displayed in the sidebar if your imported database is configured with schemas. By default, only the `public` schema is displayed when schemas are present in your database. New tables added using the **Add Table** functionality will be placed within the currently active schema, which defaults to the `public` schema if not otherwise specified. ## Add New Fields Whether you're refining your schema or adding new attributes, here’s how to add fields to your tables in ChartDB. 1. **Scroll to the bottom** of the specific table's details section in the sidebar. 2. **Click the 'Add Field' button**. 1. **Expand the 'Fields' section** for the specific table in the sidebar. 2. **Click the '+' icon** next to the 'Fields' header. Similar to tables, you can **edit field names directly on the canvas** by double-clicking the field name within a table. This allows for in-place editing of field names directly in your diagram. This will instantly add a new field to your selected table with a default name (e.g., `field_4`) and a default data type. ## Configure Field Attributes Once you've added a new field or need to modify an existing one, ChartDB provides configurable field attributes. To rename a field, simply click on the current field name in the sidebar and type in the new desired name. To change a field's data type, click the dropdown menu next to the current data type. This will display a list of available data types supported by your imported database. Available data types are determined by the database you imported into ChartDB. By default, new fields are often set as nullable. To toggle a field's nullability, click the 'N' icon next to the field. To designate a field as a primary key, click the 'P' icon next to the field. Click the three dots icon next to the field to access additional attributes. Check the 'Unique' checkbox to enforce a unique constraint. Use the 'Comments' text area to add field-level comments. Field-level comments are distinct from table-level comments, which can be added in the table's top-level settings. # Export DBML Source: https://docs.chartdb.io/docs/export/dbml Export your diagram as a DBML script in ChartDB