Budibase Internal DB
Relevant source files
The following files were used as context for generating this wiki page:
The Budibase Internal DB provides a built-in, self-contained database solution, allowing users to create applications from scratch without needing to connect to external data sources. It is designed to be a seamless part of the Budibase ecosystem, offering a quick way to store and manage application data directly within the platform.
Under the hood, the Budibase Internal DB is powered by Apache CouchDB. This provides a robust, scalable, and developer-friendly NoSQL database that integrates with the Budibase server. When users create "Budibase DB" tables in the builder, they are interacting with this internal CouchDB instance.
Sources: README.md, charts/budibase/README.md
Architecture
The Internal DB is not a separate service but an integrated part of the Budibase backend architecture. It relies on a CouchDB instance that the main Budibase services (apps, worker, proxy) communicate with. In a typical Kubernetes deployment using the official Helm chart, Budibase deploys its own custom-build of CouchDB.
This diagram illustrates the high-level architecture of Budibase services interacting with the internal CouchDB.
The key architectural points are:
- CouchDB Instance: The Helm chart can spin up a CouchDB instance within the cluster. By default, it uses a custom Budibase CouchDB image.
- Persistence: Data persistence is achieved through Kubernetes PersistentVolumeClaims (PVCs), which can be configured to use a specific
storageClass. - Service Communication: The Budibase
app-serviceandworker-serviceinteract with CouchDB for all data operations related to internal tables.
Sources: charts/budibase/README.md
Data Model
Each table created in the Budibase Internal DB is stored as a document in CouchDB. The structure of this document is defined by the Table interface.
Sources: packages/types/src/documents/workspace/table/table.ts
Table Document Structure
The core attributes of a table are defined in the Table interface.
| Property | Type | Description |
|---|---|---|
_id | string | The unique identifier for the table document, prefixed with ta_. |
_rev | string | The revision ID, managed by CouchDB. |
name | string | The user-defined name of the table. |
type | string | Always table for table documents. |
sourceId | string | Identifier for the data source. For internal tables, this is budibase. |
schema | TableSchema | An object defining the columns of the table. Keys are column names. |
primaryDisplay | string | The name of the column to be used as the primary display value. |
Sources: packages/types/src/documents/workspace/table/table.ts:16-43
Schema Definition
The schema property defines the columns of the table. Each key in the schema object is a column name, and its value is an object describing the column's properties.
// Example from packages/types/src/documents/workspace/table/table.ts
export interface Column {
name: string;
type: FieldType;
constraints: Constraints;
// ... other properties
}
export interface TableSchema {
[key: string]: Column;
}
Sources: packages/types/src/documents/workspace/table/table.ts:5-14
This entity-relationship diagram shows the conceptual model of a Table and its Columns.
Backend SDK
The packages/server/src/sdk/workspace/tables/internal/index.ts file provides a server-side SDK for managing internal tables. This SDK abstracts the direct CouchDB interactions into a set of business logic functions.
Key functions include:
create(ctx): Creates a new internal table.patch(ctx): Updates an existing internal table (e.g., renaming, changing schema).destroy(ctx): Deletes an internal table and all its associated rows.get(tableId): Retrieves a single table definition.
Sources: packages/server/src/sdk/workspace/tables/internal/index.ts
Table Creation Flow
The create function handles the logic for creating a new table document and its corresponding database in CouchDB.
This diagram shows the process of creating an internal table via the SDK.
Sources: packages/server/src/sdk/workspace/tables/internal/index.ts:19-41
A basic table structure is often used in tests, which reveals the default schema for a new table. It typically includes a default text column.
// Example from packages/server/src/tests/utilities/structures.ts
export function basicTable(name: string, extra?: Partial<Table>): Table {
return {
_id: `ta_${name}`,
name: name,
type: "table",
sourceId: "budibase",
schema: {
name: {
type: FieldType.STRING,
name: "name",
constraints: {
type: "string",
presence: false,
},
},
},
// ... other properties
};
}
Sources: packages/server/src/tests/utilities/structures.ts:10-28
API Endpoints
The functionality of the internal table SDK is exposed via a REST API, defined in packages/server/src/api/controllers/table/internal.ts. These endpoints are what the Budibase builder frontend calls to manage internal tables.
| Method | Endpoint | Description |
|---|---|---|
POST | /api/tables | Creates a new internal table. |
PATCH | /api/tables/:tableId | Updates an existing internal table. |
DELETE | /api/tables/:tableId | Deletes an internal table. |
Sources: packages/server/src/api/controllers/table/internal.ts:12-20
API Request Sequence
This sequence diagram shows the flow of a "Create Table" request from the client to the database.
Deployment & Configuration
When deploying Budibase via the official Helm chart, the internal CouchDB instance can be configured through the values.yaml file.
| Helm Chart Key | Description | Default |
|---|---|---|
couchdb.enabled | Whether to spin up a CouchDB instance in the cluster. | true |
couchdb.clusterSize | The number of replicas in the CouchDB cluster. Set to 3 for high availability. | 1 |
couchdb.persistentVolume.enabled | Enables persistent storage for CouchDB data. | true |
couchdb.persistentVolume.storageClass | The Kubernetes storage class to use for the persistent volume. | "" (uses default) |
couchdb.image | The custom CouchDB image to use. Not recommended to change. | {} (uses chart default) |
services.couchdb.backup.enabled | Enables periodic backups to another CouchDB instance. | false |
These settings allow administrators to control the resilience, scalability, and data persistence of the Budibase Internal DB. For production environments, it is recommended to use a clusterSize of 3 and a reliable storageClass for persistence.
Sources: charts/budibase/README.md
Conclusion
The Budibase Internal DB is a powerful, integrated feature that lowers the barrier to entry for creating data-driven applications. By leveraging an embedded CouchDB instance, it provides a reliable and scalable data store that is managed seamlessly through the Budibase server's SDK and API. Its configuration options in the official Helm chart also provide flexibility for administrators to tailor its deployment for different environments, from simple development setups to highly available production systems.