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
Way to ignore built in columns #20
Comments
I wasn't aware of this, could you expand on it with an example so that I understand? |
When you have a migration with renameColumn, this code gets called https://github.com/knex/knex/blob/master/lib/dialects/mysql/schema/tablecompiler.js#L81 Which calls https://github.com/knex/knex/blob/master/lib/dialects/mysql/schema/tablecompiler.js#L133. You can see in here https://github.com/knex/knex/blob/master/lib/dialects/mysql/schema/tablecompiler.js#L161 try to use TABLE_NAME column |
Could you give an example of what you're doing, what's happening and how you expect it to work? I'm trying to figure out what's going on and how I can fix it. I haven't ever run into the problem you are experiencing. |
Create a // knexfile.js
const knexStringcase = require('knex-stringcase');
module.exports = {
development: knexStringcase({
client: 'mysql2',
asyncStackTraces: true,
connection: {
host: process.env.MYSQL_HOST,
database: process.env.MYSQL_DBNAME,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
typeCast: (field, next) => {
if (field.type === 'TINY' && field.length === 1) {
return field.string() === '1'; // 1 = true, 0 = false
}
return next();
},
},
pool: {
min: 2,
max: 10,
},
migrations: {
directory: './db/migrations',
tableName: '__knex_migrations',
},
seeds: {
directory: './db/seeds',
},
}),
}; Run in the terminal export async function up(knex) {
await knex.schema.alterTable('someTableName', t => {
t.renameColumn('old_column_name', 'new_column_name');
});
}
export async function down(knex: Knex) {
await knex.schema.alterTable('someTableName', t => {
t.renameColumn('new_column_name', 'old_column_name');
});
} Then run in the terminal The migration will fail on |
That's kinda interesting. The only thing my library is doing is using the post process response and wrap identifier methods provided by knex as I think they are supposed to be used. I don't have any access to knex internals nor any control over when or how knex uses these methods. It seems like there was a similar issue posted to their repository regarding a different string mapping library. It says it was resolved but maybe this is a new issue? One thing that does stand out to me a little is that you're using camel case in your table names. I think this shouldn't be a problem though, I'm curious whether or not on your database your table names are snake case. The way knex handles using these functions is a bit of a mystery to me. On the way to the database it uses wrap identifier in order to convert strings one at a time. Then on the way back it passes the entire result as a single object. But on the way to the database for example I don't know when it's being used. I could add an additional option for ignoring certain strings but would that be helpful? |
Thank you for the quick answer! All of my tables & columns are snake case. Actually I don't know why it surfaced now, cause sometime ago I've used I think that adding ignore list will allow me to ignore columns by name. |
Thanks I think that's the right place to ask for now. Please re-open if it comes back to me. |
Hi,
Knex internally has some times (at migrations) usage of internal tables (such as
information_schema
).Those builtin tables has special cases (CONST_CASE), and because of the casting, knex fails on migrations. (trying to access
TABLE_NAME
) but the object is camelCased.There is any why to ignore those built in tables?
The text was updated successfully, but these errors were encountered: