mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-11 23:50:04 +01:00
postgres: Support custom schema for schema_migrations table (#167)
Instead of hardcoding `schema_migrations` table to the `public` schema, add support for specifying a schema via the `search_path` URL parameter. **Backwards compatibility note**: If anyone was using the previously undocumented `search_path` behavior (affecting migrations themselves, but always storing the `schema_migrations` table in `public`), you will need to either prepend `public` to your `search_path`, or migrate your `schema_migrations` table to your primary schema: ```sql ALTER TABLE public.schema_migrations SET SCHEMA myschema; ``` Closes #110
This commit is contained in:
parent
d4ecd0b259
commit
55a8065efe
5 changed files with 141 additions and 20 deletions
11
README.md
11
README.md
|
|
@ -139,6 +139,17 @@ A `socket` or `host` parameter can be specified to connect through a unix socket
|
|||
DATABASE_URL="postgres://username:password@/database_name?socket=/var/run/postgresql"
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
```sh
|
||||
DATABASE_URL="postgres://username:password@127.0.0.1:5432/database_name?search_path=myschema"
|
||||
```
|
||||
|
||||
```sh
|
||||
DATABASE_URL="postgres://username:password@127.0.0.1:5432/database_name?search_path=myschema,public"
|
||||
```
|
||||
|
||||
**SQLite**
|
||||
|
||||
SQLite databases are stored on the filesystem, so you do not need to specify a host. By default, files are relative to the current directory. For example, the following will create a database at `./db/database_name.sqlite3`:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue