# Databases

A Project database gives related Services one private data store without a separate provisioning workflow. When Tokay detects a supported database connection in the code, we create the resource, generate its credentials, and deliver the connection through the environment variable the application already reads.

Tokay supports Postgres, MySQL, MongoDB, and Redis.

## The database is created with the first deployment

A connection such as `DATABASE_URL` or a Redis client appears on the Service's Environment tab before deployment. Review the detected resource and variable name, then deploy the Service.

Tokay creates the database inside the Project and supplies credentials in the format expected by the application's database library. The value is managed as infrastructure rather than copied into source or entered by hand.

## Services in one Project share the resource

A Project can have one database of each supported kind. This lets a web app, background worker, and scheduled job use the same data and credentials because they are parts of the same application.

SQL resources can contain separate logical databases when Services need distinct namespaces. Each Service declares which logical database it uses.

See [How Tokay is organized](how-tokay-is-organized.md) for deciding which Services should share a Project.

## The Resources tab is the database workspace

Open the Project's **Resources** tab to inspect and manage its databases. Postgres and MySQL provide a SQL console, Redis accepts commands, and MongoDB accepts queries in the browser.

Password rotation happens from the same page. Tokay keeps the previous version so you can revert if a Service still depends on it.

## Exports keep the data portable

A native export creates a standard engine specific dump for each logical database. Postgres, MySQL, and MongoDB also support a ZIP of per table or per collection CSV files. Redis uses native export because its data does not have a table shape.

These formats can be downloaded from the Resources tab and used outside Tokay.

## Project databases are private by design

Only Services in the Project can reach its databases over the private network. There is no public database port for outside clients to scan or connect to.

Use the query console or an export when you need the data locally. For ongoing external access, deploy an authenticated API or admin Service in the Project. Direct connections from tools such as `psql` or TablePlus are not available.

## An external database can supply the same variable

Store an existing managed database URL as a Project secret using the name the code reads, such as `DATABASE_URL`. When that name conflicts with the built in database connection, Tokay shows both sources and asks which one the Service should use.

## Schema changes follow the deployment safety model

Migrations are rehearsed against a copy before they reach production, and destructive changes can require approval and a snapshot. See [Database migrations](database-migrations.md) for the full workflow.
