Database and migrations
Connecting your database makes Dev and your agents schema-aware: they write SQL, migrations and backend code against your real tables and columns instead of guessing them. For PostgreSQL databases, DevSpec also watches the migration files you commit and tells you which ones have reached each database.
You connect a database in Project settings → Integrations → Databases, or from Connect a database under Optional connections for later at the end of project setup. Connecting a database is optional, and a project can have several, for example one for staging and one for production.
Which databases you can connect
Choose the Database type when you connect:
| Database type | What DevSpec reads | What you get |
|---|---|---|
| Supabase | Your schema, migration history, and Supabase's security and performance advisors | Dev answers from your real tables, functions and row-level security policies, can report advisor findings, and the Migrations page shows what's applied. |
| PostgreSQL (Beta) | Your schema and migration history, over a direct read-only connection | Dev answers from your real tables and functions, and the Migrations page shows what's applied. Works with any PostgreSQL database, such as Neon, Amazon RDS, Railway, Fly, Timescale or your own server. |
| MongoDB (Atlas) (Beta) | Your cluster's details and the Atlas Performance Advisor's findings | Dev reads your data model from the models your code declares, and checks it against Atlas's advice. |
Types marked Beta show a Beta badge in the list. A Supabase database can also be connected as plain PostgreSQL, but the Supabase type is the one that adds Supabase's advisors.
Connect a database
Project Maintainers connect databases.
- Open Project settings → Integrations → Databases and click Connect database.
- Fill in the fields every database has:
- Database type: see "Which databases you can connect" above.
- Connection name: a label for you, such as "Staging" or "Production DB". It doesn't need to match anything in your database provider.
- Environment (optional): Production, Staging, Preview or Development, or Not tied to one environment. DevSpec shows it on the connection and records the database under that environment in the project's Inventory.
- Deploys from branch: the git branch whose changes deploy to this database, such as
stagingfor a staging database andmainfor production. Leave it on Tracking branch to follow the branch each repository tracks. This decides which migrations are tracked against the database (see "Map each database to a branch" below).
- Fill in the credentials for your database type, as described in the sections below.
- DevSpec checks the connection by itself once every field is filled in, or you can click Test connection. When it says Connection verified, click Connect database. The button stays disabled until the test passes, so broken credentials can't be saved.
DevSpec then reads your database. The connection shows Syncing…, then Synced with the time.
Connect a Supabase database
For a Supabase database, the form asks for:
- Project ID: your Supabase project's ID, found in Supabase under Settings → General → Project ID. The Open in Supabase link takes you there.
- Personal Access Token: a Supabase access token, which starts with
sbp_. Create one in the Supabase dashboard under your avatar (top right) → Account → Access Tokens, or use the Generate a token link. Read "Give DevSpec the least access" below before you create it.
Connect a PostgreSQL database
For a PostgreSQL database (Beta), choose how to enter the details:
- Connection string: paste the connection string from your provider, such as
postgresql://user:password@host:5432/database. Most providers give you one on a copy button. It contains your password, so DevSpec stores it encrypted and never shows it again. - Enter details: fill in Host, Port (5432 if you leave it blank), Database, User and Password.
Either way, choose a TLS mode:
- require encrypts the connection without verifying the certificate chain. Most managed providers expect this.
- verify-full encrypts and verifies the certificate and hostname; verify-ca encrypts and verifies the certificate.
- disable turns encryption off. Use it only if the server has no TLS.
If a pasted connection string asks for a different sslmode, the form tells you that the TLS mode you chose is the one DevSpec uses.
The database must accept connections from outside its own network. If the test times out, check the host and port, and whether a firewall or IP allow-list is blocking DevSpec. If it can't connect, the form says why, for example a wrong password, a database that doesn't exist, or a certificate problem.
Connect a MongoDB Atlas database
For MongoDB (Atlas) (Beta), DevSpec works through an Atlas service account, never a connection to your data. The form asks for:
- Project ID: your Atlas project ID, a 24-character code. Find it in your Atlas project's settings, or in the address bar:
cloud.mongodb.com/v2/<PROJECT_ID>. - Cluster Name: the cluster within that project, such as
Cluster0. - Service Account Client ID and Service Account Client Secret: in your Atlas project, open Project Identity & Access → Applications → Service Accounts, create a service account with only the Project Read Only role, and set a secret expiry. Note that Atlas lets project service accounts see your organization's member list. If your organization requires an API access list, manage it on the service account's API access list (which is separate from your database-user access list). The How to create a Service Account link opens MongoDB's guide. The secret is stored encrypted and never shown again.
Atlas can't show DevSpec the documents in your cluster, so DevSpec reads your data model from the models your code declares, with Mongoose, Typegoose or Zod, in your tracked repositories.
Give DevSpec the least access
DevSpec only ever reads your database, and reads its data only when its Live data is set to Everything. How you keep its access small depends on the database type.
Supabase. Give DevSpec a personal access token that reaches only what it uses. On the Supabase Access Tokens page, generate a new token and:
- Limit its resources to the one Supabase project you're connecting.
- Start from the No access preset, then give Read access to Database, Advisors, Migrations and Project Settings. Leave every other permission off, and give nothing Read-write.
- Set an expiry. When the token expires, the database shows Error until you connect it again with a new token, as described in Disconnect a database or replace its credentials.
A token made this way can reach only that project, and Supabase runs every query made with it read-only, so it can't change your database even if it leaks. Avoid a full-access token, which Supabase labels Legacy: it carries everything your Supabase account can do, in every project. The same four permissions cover Live data — keep in mind that Supabase's Database Read permission can read every row in the project, so Structure only stops DevSpec from querying your rows rather than restricting the token itself. If the person who created the token leaves the Supabase organization, it stops working and you'll need to replace it.
PostgreSQL. Open View permission guide on the connect form and pick the access level that matches your Live data setting. Structure only creates a dedicated login that can connect to the database and inspect schema structure without access to application rows; Everything also grants read-only access to current and future tables (repeat the default-privilege step for each schema and each role that creates tables). Neither setup grants write access.
If your migration history table lives outside public, also grant USAGE on its schema and SELECT on that table only. One PostgreSQL quirk to keep in mind: by default, every login can connect to other databases on the same server through PUBLIC (and may inherit grants from other roles). To restrict this login to a single database, first grant CONNECT explicitly to the apps and people who still need those other databases, then revoke CONNECT from PUBLIC on them — revoking it from the DevSpec login alone won't override a PUBLIC grant.
MongoDB Atlas. Give the service account the Project Read Only role and nothing more.
When you disconnect a database, delete its token, user or service account too.
What DevSpec reads from your database
From a Supabase or PostgreSQL database, DevSpec reads the structure of the public schema. Unless you set the database's Live data to Everything (see below), it never reads its contents:
- tables and columns, with their types and defaults
- relationships (foreign keys), indexes and enums
- functions and triggers
- row-level security policies
- approximate row counts, from PostgreSQL's own statistics
It also reads your migration history, the record of which migrations have been applied, so the Migrations page can show what's applied. For Supabase, it reads Supabase's security and performance advisors and your installed extensions too.
From MongoDB Atlas, DevSpec reads your cluster's tier, version and state, and the Performance Advisor's findings: suggested indexes, unused or redundant indexes, and schema anti-patterns. Dev can match those findings against your models, for example "Atlas suggests an index on orders.customerId, and your Order model doesn't declare one".
DevSpec never writes to your database, and it reads your application data only from a database whose Live data is set to Everything.
Dev reads what it needs when a conversation calls for it, and every member of the project can ask Dev about it. Your agents can read your schema from DevSpec too.
Let Dev and your agents read live data
Each Supabase or PostgreSQL database has a Live data setting with two choices:
- Structure only, the default. DevSpec reads the database's structure and health, as described above, and never reads a row.
- Everything. Dev, and the coding agents connected to the project, can run read-only SQL against the database to answer questions about its data, such as "how many customers signed up last week?" or "what does the order for invoice 1042 look like?". They can read any table.
Project Maintainers choose it when they connect a database, and change it later from the database in Project settings → Integrations → Databases. Everyone else on the project can see which choice each database has.
Before you choose Everything, know where the data goes once it is read:
- The rows appear in the conversation that asked for them, and every member of the project can read that conversation.
- The rows are sent to the AI model answering the question. For a connected coding agent, that is whichever model the agent runs, outside DevSpec.
Writes are never possible. Each query runs as one read-only statement, so the database itself refuses anything that would change data. A Supabase database is read through Supabase's read-only access. A PostgreSQL database is read inside a read-only transaction with the user you connected, so it can read only what that user can read.
A database can be set to Everything for some environments and not others. For example, a staging database with test data can be set to Everything while production stays on Structure only.
Each query returns at most 200 rows, and a very long value is shortened, with a note saying how to read the rest. A PostgreSQL query stops after 15 seconds. A Supabase query stops after 2 minutes, which is Supabase's own limit. For totals, Dev counts or groups in SQL instead of reading every row.
MongoDB Atlas databases are always Structure only, because Atlas gives DevSpec no route to the data in your cluster.
Keep the schema up to date
DevSpec keeps what it knows about your database up to date automatically as tracked migrations are applied and through regular background syncs.
To read it again now, a Maintainer clicks Re-sync schema (the refresh icon) beside the database in Project settings → Integrations → Databases. The list shows when each database was last synced. While a database is syncing, the database icon in the top header shows Syncing naming the database and noting that responses may have incomplete context until schema sync finishes.
Track migrations on the Migrations page
The Migrations page, under Ship → Migrations in the project sidebar, lists the SQL migration files (.sql) committed to your tracked repositories and whether each has been applied to each connected Supabase or PostgreSQL database. It needs at least one of those connected. MongoDB Atlas databases have no migrations to track.
- Scan repository finds migration files already in your repositories. New migrations are picked up as you push.
- Verify Now reads your databases again and checks every migration that isn't applied yet. It can take up to a minute; statuses update as results arrive.
- Manage databases opens Project settings → Integrations → Databases.
The counts at the top show how many migrations are applied, pending and not applied. Each migration shows one of these statuses:
| Status | Meaning |
|---|---|
| Applied | Found in the database. |
| Pending | Committed and waiting to be checked. |
| Not applied | Checked, and not found in the database. |
| Skipped | Someone marked it as not needed, with a reason, or it contains no lasting change (for example, it has no SQL statements). |
| Superseded | Migrations applied later dropped, renamed or replaced what this one creates, so it no longer needs applying. DevSpec marks this by itself and names the later migrations. |
You can filter by status, by database (All databases or one connection) and by date (7d, 30d, 90d or All). Click a migration to see what it does, when it was committed, when it was last verified and applied, its commit, the task it came from and, for a migration that isn't applied, why DevSpec concluded that. From there you can Verify it on its own, Describe it in plain words, Discuss it in a session, Create task to get it applied, or, for a pending or not-applied migration, Mark as applied or Skip it with an optional reason. Viewers can see the page and discuss a migration, but can't run checks or change a migration's status.
DevSpec re-checks pending and not-applied migrations periodically in the background, so a migration you apply by hand or from CI shows as applied without you doing anything.
If a migration stays not applied for much longer than your migrations normally take, DevSpec tells the owner of the task it came from, or the project's Maintainers when it has no task, so it can be applied or skipped. You're told once per migration.
How DevSpec knows a PostgreSQL migration is applied
DevSpec reads the history table that your migration tool keeps in the database. It recognizes the tables kept by the Supabase CLI, Prisma, Flyway, Knex and Drizzle, and reads every one it finds. If the history can't be read in full, for example because the connected user can't read the table, DevSpec doesn't call the migration not applied: it shows why it couldn't tell.
Map each database to a branch
Each connection's Deploys from branch decides which migrations are tracked against it. With a staging database mapped to staging and production mapped to main, a migration pushed to staging is tracked against the staging database, and a migration pushed to main against production. A connection left on Tracking branch tracks migrations from each repository's tracking branch. The Branch column in the database list shows the branch each connection follows.
Disconnect a database or replace its credentials
To disconnect a database, a Maintainer clicks Disconnect database (the icon beside it in Project settings → Integrations → Databases). Check the database named in the confirmation, then choose Disconnect. Dev stops seeing that database, and DevSpec stops checking migrations against it. You can connect it again later. Delete its token, user or service account afterwards.
If the credentials expire or are revoked, the database shows Error with a message such as "Database credentials need re-entering — reconnect the database in DevSpec", and an icon appears in the project header. To fix it, create new credentials, disconnect the database, and connect it again with them. Migrations tracked against the old connection are linked to the new one and checked again.
What a database connection costs
Work around your database is background work, charged to your organization's balance per piece of work. It doesn't count toward anyone's personal allowance, though it does count toward the project's limit if it has one. On Settings → Billing → Transactions it appears as Running your project: making your schema searchable, so Dev can find the right tables for a question, and checking a migration against your schema when the migration history alone can't settle whether it's applied.
When you press Describe on a migration, or Dev looks up your schema during a conversation, that's asking Dev: it appears as Asking Dev and counts toward your personal allowance. While the project is paused, for example because your organization's balance ran out, the background work waits, and catches up once the project starts again. See Billing, usage and limits.