postgres: Automatically create search_path schema when needed (#169)

In #167 we added support for specifying a postgres `search_path`, which is used to store the `schema_migrations` table. However, if the schema does not already exist it will cause an error.

In this PR we automatically create the first schema in the `search_path` if it does not exist.
This commit is contained in:
Adrian Macneil 2020-11-01 15:09:13 +13:00 committed by GitHub
parent 55a8065efe
commit ac718a23dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 146 additions and 67 deletions

View file

@ -140,7 +140,7 @@ DATABASE_URL="postgres://username:password@/database_name?socket=/var/run/postgr
```
A `search_path` parameter can be used to specify the [current schema](https://www.postgresql.org/docs/13/ddl-schemas.html#DDL-SCHEMAS-PATH) while applying migrations, as well as for dbmate's `schema_migrations` table.
If multiple comma-separated schemas are passed, the first will be used for the `schema_migrations` table.
If the schema does not exist, it will be created automatically. If multiple comma-separated schemas are passed, the first will be used for the `schema_migrations` table.
```sh
DATABASE_URL="postgres://username:password@127.0.0.1:5432/database_name?search_path=myschema"