Comments (4)
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:
- 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.
- 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. - Elevated permissions - Generally creating DBs and Tables require different permission levels
- For postgres, the user needs to be a superuser or have the
CREATEDB
privilege: https://www.postgresql.org/docs/10/static/sql-createdatabase.html - For MySQL, the user needs a high
priv_level
and theCREATE
privilege
- For postgres, the user needs to be a superuser or have the
The value I see is:
- Makes setting up a DB environment slightly easier
- There are better tools like docker and terraform to do this for you
from migrate.
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
.
from migrate.
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.
from migrate.
@murphybytes Do your up migrations which add the functions and triggers have corresponding down migrations which drop the functions and triggers?
from migrate.
Related Issues (20)
- Migrations that begin with the year 2024 fail during the 'up' migration process HOT 7
- How to run up/down migration before service starts?
- pgx not following intended import behaviour HOT 1
- Unable to change delimiter in mysql migrations HOT 1
- Support for libsql and Turso HOT 1
- "unexpected EOF" when connecting to MySQL DB via cloud-sql-proxy in github actions
- clickhouse TLS support is missing fir https://github.com/golang-migrate/migrate/blob/master/database/clickhouse/clickhouse.go
- Maintainer support for PR Backlog
- Allow users to fail when there are bad migration paths in their source HOT 3
- Expensive SQL query inside ensureVersionTable & ensureLockTable
- imported mongo official driver is out of date
- `Dirty database version 1. Fix and force version` and `error: can't read limit argument N` HOT 2
- SQLite3 accepts file URL with prefix `file:///`, but golang-migrate requires prefix `sqlite3:///`. Not flexible. HOT 1
- Do not return an error when no change. Communicate error conditions using errors.
- golang-migrate ignores PostgresSQL message reporting
- error: no migration found for version X (some numbers) HOT 1
- Cassandra multiple hosts cluster migrations failed HOT 1
- Install on Ubuntu with apt HOT 1
- Postgres / SQL multistatement support
- first .: file does not exist HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from migrate.