drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: skip schema check in migrator
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Feature hasn't been suggested before.
- [X] I have verified this feature I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
**Feature**:
Provide a way to bypass the check `CREATE SCHEMA IF NOT EXISTS ${sql.identifier(migrationsSchema)}`
when the default "public" schema is used in Postgres with
```ts
await migrate(db, {
migrationsSchema: 'public',
migrationsFolder,
});
```
**Reason**:
It is possible that in high regulated environments the user executing the migration doesn't have the permissions for any operation on the schema, even checking if it exists (this is the reason why we use "public" in the first place).
The above statement will trigger an error "permission denied" and abort the entire migration.
It should be quite easy just changing https://github.com/drizzle-team/drizzle-orm/blob/30e5347c5b363e4ae5e30be78ac0bf64feaf98d4/drizzle-orm/src/pg-core/dialect.ts#L85
with
```ts
if(migrationsSchema !=='public') {
await session.execute(sql`CREATE SCHEMA IF NOT EXISTS ${sql.identifier(migrationsSchema)}`);
}
```
The `public` schema should exists by default in Postgres https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PUBLIC
I can create a PR for it if you're happy with the approach.
Contributor guide
Assessment
This issue has not been assessed yet.