-
Notifications
You must be signed in to change notification settings - Fork 642
Description
Hello,
I needed some clarification regarding the behavior of knexSnakeCaseMappers({ underscoreBeforeDigits: true }) introduced after this issue #1025.
We are using knex for migrations and objection as ORM in our codebase. When using Objection we use camelCase and in Knex migrations we use snake_case for table and column names. This is what our knex config looks like
const knexConfig: Knex.Config = {
client: 'postgresql',
connection: 'connection url string',
pool: {
min: 0,
max: 10
},
migrations: {
tableName: 'knex_migrations',
directory: '../migrations'
},
...knexSnakeCaseMappers({ underscoreBeforeDigits: true })
};
However, the problem is when we already pass a snake_case string and underscoreBeforeDigits is true, it adds an additional underscore before the number.
For example, we have a migration like this
export async function up(knex: Knex): Promise<void> {
await knex.schema.createTable('test_2_tables', (tb) => {
// create columns
});
When we run this migration, the table is created with name test__2_tables (notice the double underscore before 2).
Is this expected behavior of this function ?
Personally, I don't think so, because it does not add double underscore everywhere else.
I have created a draft PR with possible fix and added a test cases for that.