Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mysql): try creating database if not exist #21

Open
thurt opened this issue May 1, 2018 · 4 comments
Open

feat(mysql): try creating database if not exist #21

thurt opened this issue May 1, 2018 · 4 comments
Labels
database Updates database drivers enhancement New feature or request

Comments

@thurt
Copy link
Contributor

thurt commented May 1, 2018

refer to: mattes/migrate#279

I created an issue for this because I'm interested in having this feature. Thoughts?

@dhui
Copy link
Member

dhui commented May 1, 2018

I'm not convinced of the value of migrate creating the DB is worth the cost but think this is an issue worth discussing.

I see the following issues with migrate creating the DB:

  1. Compatibility with other DB drivers. For consistency, every driver would also need to implement a similar setup and the referenced PR only implements the change for MySQL.
  2. What is the expected state of the DB for the first migration and what role does migrate play? Currently, migrate doesn't change the state of the DB so the first migration starts w/ a "clean slate" and any necessary DB configuration is done out of band.
  3. Elevated permissions - Generally creating DBs and Tables require different permission levels

The value I see is:

  1. Makes setting up a DB environment slightly easier
    • There are better tools like docker and terraform to do this for you

@thurt
Copy link
Contributor Author

thurt commented May 4, 2018

Thanks for your thoughts! The permissions point is something I hadn't thought about much as I am accustomed to thinking about access control defined by the application rather than in the database.

I think it's just an easier development process to have db schema changes (including db creation) organized around one tool. But I do see the fine line here about db creation being out of scope for migrate.

Currently, I create a database with a Dockerfile which just has a single COPY instruction to move /docker-entrypoint-initdb.d/createDatabase.sql into the mysql base image (see header Initializing a fresh instance). That is not as nice as just being able to always use the base mysql image and drive the schema changes in code with a tool like migrate.

@murphybytes
Copy link

murphybytes commented May 16, 2018

I'd be interested in having this feature for postgres as well. The reason is mig.Drop doesn't work for databases that have functions, triggers and the like. It only drops the tables and if you have interdependencies in your database code. It doesn't work. This makes it impossible to perform unit tests starting with a clean slate base for every unit test. With postgres, I've been forced to execute a query killing all open connections before the test, drop the test table if it exists, and then re-create it.

@dhui
Copy link
Member

dhui commented May 16, 2018

@murphybytes Do your up migrations which add the functions and triggers have corresponding down migrations which drop the functions and triggers?

@dhui dhui mentioned this issue Aug 29, 2018
@Fontinalis Fontinalis added database Updates database drivers enhancement New feature or request labels Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Updates database drivers enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants