Skip to main content

Managing Databases

A Database in Ductape is a data store (such as MongoDB, PostgreSQL, or MySQL) that your product can connect to and use for queries, transactions, and workflows. Each database can be configured for different environments and supports reusable actions and migrations.

Database Structure

FieldTypeRequiredDescriptionExample
namestringYesName of the databaseMongo database
tagstringYesUnique identifier for this databasemongo
typestringYesDatabase type (mongodb, postgresql, mysql)mongodb
envsarrayYesList of environment configs (see below)[{"slug": "dev", ...}]
descriptionstringNoDescription of the databaseMain DB for app
actionsarrayNoReusable database actions
migrationsarrayNoDatabase migrations

Environment Config Structure

FieldTypeRequiredDescriptionExample
slugstringYesEnvironment slugdev
connection_urlstringYesDatabase connection stringmongodb://localhost:27017/dev
descriptionstringNoDescription of this environmentDev DB

Creating a Database

To create a database, use the create function of the product's databases interface.

Example:

const database = await ductape.product.databases.create({
type: "mongodb",
tag: "mongo",
envs: [
{ slug: "dev", connection_url: "mongodb://localhost:27017/dev" },
{ slug: "prd", connection_url: "mongodb://localhost:27017/prod" }
],
name: "Mongo database"
});

Updating a Database

To update a database, use the update function with the database tag and update payload.

Example:

const updated = await ductape.product.databases.update("mongo", {
name: "Mongo database details",
envs: [
{ slug: "dev", connection_url: "mongodb://localhost:27017/dev-updated" }
]
});

Fetching Databases

Fetch all databases for a product:

const databases = ductape.product.databases.fetchAll();

Fetch a single database by tag:

const database = ductape.product.databases.fetch("mongo");

Why Use Databases?

  • Centralize and manage your product's data
  • Support multiple environments with different configs
  • Define reusable actions and migrations for automation

Next Steps