Have a way to run migrations on an arbitrary database.

Issue #28 resolved
Shuhao created an issue

I have a :memory: sqlite3 database for tests. I want to be able to run migrations on that database without essentially copying RunMigrations in my code base.

Comments (8)

  1. Liam Staskawicz repo owner

    Is it possible to create a DBConf that describes your test database, and use that for testing?

  2. Shuhao reporter

    I suppose.. After looking into exposing that API and not having too many success, I setup a test db file.

  3. Shuhao reporter

    Where is the db path relative to? Where you run the command? Where the package is? I'm having trouble with that.

  4. Liam Staskawicz repo owner

    I believe the path should be relative to the executable - it's probably simplest to pass an absolute path if you're having trouble. That should be the path to the directory containing your dbconf.yml and migrations dir.

  5. Liam Staskawicz repo owner

    Were you able to get this working? If so, I'd like to close out the issue & pull request. Thanks.

  6. Shuhao reporter

    Sorry for the long delayed response: I still think it is necessary to be able to run migrations on arbitrary database as a dbconf may not be sufficient.

    Unittests are supposed to be independent of each other. If I have multiple packages that depend on the same database, I might get some weird global state issues when I run go test ./... as they tend to run in parallel.

    In each test suite's setup I can create a new database connection to a different databse (in sqlite3 it would be :memory:) to avoid any issues with global state, but I cannot run migrations to an arbitrary connection.

    Also things like :memory: is just a lot faster, and I must hold on to that connection (specifying :memory: in dbconf just won't work).

  7. Shuhao reporter

    Any updates on this? I still would like to do this as it will speed up and simplify my unittesting code...

  8. Log in to comment