# DATABASE_MIGRATION_SCHEMA_DENIED

<!-- Generated by docs/modules/diagnostics from the package catalogs. Write a guide in docs/diagnostics/<CODE>.md instead of editing this file. -->

The Postgres role cannot use the schema of Drizzle's migrations table. ViteHub checks this before it reads the table, and stops before any change, on start, in `vitehub database migrate`, and in `--dry-run`. `error.why` names the role and the missing privilege:

- No `USAGE` on the schema, so the role cannot read the table.
- The schema `drizzle` is missing, and the role has no `CREATE` on the database to create it.
- The table is missing, and the role has no `CREATE` on its schema to create it.

Run the `GRANT` in the fix in a SQL client. `GRANT CREATE ON DATABASE` needs a role that owns the database. `GRANT USAGE` or `GRANT CREATE` on a schema needs the owner of that schema, or a role with the grant option on it. Or run it with `vitehub database sql --remote --database default 'GRANT CREATE ON DATABASE "app" TO "app_user"'`, with that role in `connection.url`. Or set [`migrationsSchema`](https://vitehub.dev/docs/database/configure#keep-the-migrations-table-in-a-schema) to an existing schema where the role has `USAGE` and `CREATE`.

A runtime role that only reads an existing table needs `USAGE` on its schema and `SELECT` on the table. It needs no `CREATE`. See [Several instances on Postgres](https://vitehub.dev/docs/database/configure#several-instances-on-postgres).

## Source

`DATABASE_MIGRATION_SCHEMA_DENIED` belongs to the `database` package. Its catalog entry is in [`src/error-diagnostics.ts`](https://github.com/vite-hub/vitehub/blob/main/packages/database/src/error-diagnostics.ts#L291). It is raised in [`src/runtime/migrate-on-start.ts`](https://github.com/vite-hub/vitehub/blob/main/packages/database/src/runtime/migrate-on-start.ts#L600).

See [all Database diagnostics](https://vitehub.dev/docs/database/diagnostics).

<!-- vitehub-docs:section-links -->
## In this section

- [Overview](https://vitehub.dev/raw/docs/database.md)
- [Get started](https://vitehub.dev/raw/docs/database/get-started.md)
- [Configure](https://vitehub.dev/raw/docs/database/configure.md)
- [Server API](https://vitehub.dev/raw/docs/database/server-api.md)
- [Agent capability](https://vitehub.dev/raw/docs/database/agent-capability.md)
- [Hosts](https://vitehub.dev/raw/docs/database/hosts.md)
- [Limits and errors](https://vitehub.dev/raw/docs/database/limits-and-errors.md)

Next: [DATABASE_MIGRATION_SCHEMA_MISSING](https://vitehub.dev/raw/docs/database/diagnostics/database_migration_schema_missing.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
