knex-db-manager
knex-db-manager copied to clipboard
truncateDb does not work on macOS
Apologies for the barrage of truncateDb
bugs!
After applying my workaround, I was able to bypass #83. I ran the command in Ubuntu and I was able to get the truncation to work!
I ran the same command on macOS, and it does not do the truncation 😱
I started doing some debugging, and I logged out the result of tableNames
from https://github.com/Vincit/knex-db-manager/blob/master/lib/MySqlDatabaseManager.js#L133
[
RowDataPacket { TABLE_NAME: 'article' },
RowDataPacket { TABLE_NAME: 'article_history' },
RowDataPacket { TABLE_NAME: 'knex_migrations' },
RowDataPacket { TABLE_NAME: 'knex_migrations_lock' },
RowDataPacket { TABLE_NAME: 'topic' },
RowDataPacket { TABLE_NAME: 'user' }
]
The output returned seems to an object array with upper case TABLE_NAME
as the key name, while the map
is looking for the lowercase table_name
, which causes tableNames
to be an empty array.
Currently, the only workaround I can see for this is to do add an alias as
to the select query:
this._cachedTableNames = knex('information_schema.tables')
// 👋👋 Force knex to return lowercase `table_name`
.select('table_name AS table_name')
.where('table_schema', config.knex.connection.database)
// .. other stuff
Can you think of any other workarounds? Do you think something could be wrong with the MySQL macOS installation on my Mac?
I haven't ran mysql server natively on mac for a very long time. I always run it in docker... So there might be a bug or mysql on mac might work somehow different manner.
Can you add reproduction code for this and also tell how have you installed mysql on mac?
I'll get more info about this over the weekend. But for now...
Can you add reproduction code for this
I use it in my db test suite. This is where the code existed, which I've replaced with my workaround. https://github.com/Matterwiki/Matterwiki/blob/refactor-inception/packages/api/src/common/test-utils/db-test-utils.js#L53
how have you installed mysql on mac?
I believe I followed these instructions: https://dev.mysql.com/doc/mysql-osx-excerpt/5.7/en/osx-installation-pkg.html
I always run it in docker
I should probably do this as well...