`dbmate` package was starting to get a bit polluted. This PR migrates each driver into a separate package, with clean separation between each.
In addition:
* Drivers are now initialized with a URL, avoiding the need to pass `*url.URL` to every method
* Sqlite supports a cleaner syntax for relative paths
* Driver tests now load their test URL from environment variables
Public API of `dbmate` package has not changed (no changes to `main` package).
Supported via `--migrations-table` CLI flag or `DBMATE_MIGRATIONS_TABLE` environment variable.
Specified table name is quoted when necessary.
For PostgreSQL specifically, it's also possible to specify a custom schema (for example: `--migrations-table=foo.migrations`).
Closes#168
Force the `schema_migrations` table to be created with `latin1` character set, to fix the behavior of dbmate in MariaDB 10.1 and older (or MySQL 5.6 and older) when the system charset has more than 1 byte per character (e.g. utf8mb4)
Closes#85
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.
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
* adding verbose output for statement execution
* fixing lint and redefined v flag
* changing name due to inherited verbose flag and updating README
* linting
* moving verbose flag to subcommand, removing driver verbose, adding tests
* fixing README, cleaning up spacing
Extending the `dbmate status` command with the ability to set an exit code or quiet output, for use in scripts.
Flag names were copied from `git diff` command.
✨ When using dbmate as a container, since the base image is distroless, we can't do `dbmate up && dbmate wait`, which makes config a bit more cumbersome (e.g. in kubernetes an extra initContainer).
Closes#111Closes#112
Currently the `dbmate wait` command fails if the `postgres` system database does not exist (which is common on DigitalOcean, and perhaps other hosting providers).
This command is intended to verify that the postgres server is available, and not whether or not the user's database exists. Therefore, we will update this command to simply ignore the `database "foo" does not exist` error and treat this as the server being ready.
Fixes#78
When MySQL password included special chars such as exclamation point or @ (at), MySQL backend errored out (invalid password).
url.userinfo.String() (which gets called inside url.String()) returns %-encoded strings and MySQL interprets it as an actual password. Now the function percent-decodes it first before returning.
Closes#57
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.
Adds `dbmate dump` command to write the database schema to a file.
The intent is for this file to be checked in to the codebase, similar to Rails' `schema.rb` (or `structure.sql`) file. This allows developers to share a single file documenting the database schema, and makes it considerably easier to review PRs which add (or change) migrations.
The existing `up`, `migrate`, and `rollback` commands will automatically trigger a schema dump, unless `--no-dump-schema` is passed.
Closes https://github.com/amacneil/dbmate/issues/5