Postgres: Add path to schema_migrations insert statement (#49)

Since Postgres 9.6.8, at the top of the output of `pg_dump` it adds the line:

```sql
SELECT pg_catalog.set_config('search_path', '', false);
```

We must provide an absolute table reference to avoid errors when importing schema.sql.
This commit is contained in:
Adam Sven Johnson 2018-08-26 12:24:40 +12:00 committed by Adrian Macneil
parent 4710a35da1
commit 7603e83f0e
2 changed files with 3 additions and 3 deletions

View file

@ -79,7 +79,7 @@ func postgresSchemaMigrationsDump(db *sql.DB) ([]byte, error) {
buf.WriteString("\n--\n-- Dbmate schema migrations\n--\n\n")
if len(migrations) > 0 {
buf.WriteString("INSERT INTO schema_migrations (version) VALUES\n (" +
buf.WriteString("INSERT INTO public.schema_migrations (version) VALUES\n (" +
strings.Join(migrations, "),\n (") +
");\n")
}

View file

@ -91,14 +91,14 @@ func TestPostgresDumpSchema(t *testing.T) {
// DumpSchema should return schema
schema, err := drv.DumpSchema(u, db)
require.NoError(t, err)
require.Contains(t, string(schema), "CREATE TABLE schema_migrations")
require.Contains(t, string(schema), "CREATE TABLE public.schema_migrations")
require.Contains(t, string(schema), "\n--\n"+
"-- PostgreSQL database dump complete\n"+
"--\n\n\n"+
"--\n"+
"-- Dbmate schema migrations\n"+
"--\n\n"+
"INSERT INTO schema_migrations (version) VALUES\n"+
"INSERT INTO public.schema_migrations (version) VALUES\n"+
" ('abc1'),\n"+
" ('abc2');\n")