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

truncateDb does not work on macOS #84

Open
krishnagopinath opened this issue Mar 17, 2020 · 2 comments
Open

truncateDb does not work on macOS #84

krishnagopinath opened this issue Mar 17, 2020 · 2 comments

Comments

@krishnagopinath
Copy link
Contributor

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?

@elhigu
Copy link

elhigu commented Mar 17, 2020

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?

@krishnagopinath
Copy link
Contributor Author

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants