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
Feature request: an alias for creating postgre indexes CONCURRENTLY in a migration #3913
Comments
Having |
That would be. Problem is you can't have it in transaction so you'd have to always explicitly specify this like so: import Knex from 'knex'
const tableName = 'scheduled_campaign_actions'
exports.up = async (db: Knex) => {
await db.schema.alterTable(tableName, (table) => {
table.index('notification_id', {concurrently: true})
})
}
exports.down = async (db: Knex) => {
await db.schema.alterTable(tableName, (table) => {
table.dropIndex('notification_id', {concurrently: true})
})
}
exports.config = {
transaction: false
} which for me would be okay too, just a little more verbose. |
@capaj I think it would work out fine. Knex does not execute those schema operations until the function returns. It then orders those operations: table creation, constraint creation, index creation - they have to occur in this order even when inside a transaction because you cannot create an index on a column that does not exist. When creating these types of indexes, the first transaction would create the table, etc., but not those "concurrent" indexes. It would then not use a transaction for those. Side note:
This makes it impossible for SQL injection attacks to occur as the bindings are properly escaped. Reference: http://knexjs.org/#Raw-Bindings Sorry if that seems preachy and you already know... but I've seen too many security vulnerabilities in software to overlook it. |
@raijinsetsu migrations don't deal with user input at all. There's no possibility of SQL injection there. Right, knex schema builder could skip the |
@raijinsetsu actually identifier bindings are not correctly escaped by knex, but knex just adds siple quoting. Knex also may try to escape it to be safe, but doesn’t guarantee anything. I wouldn’t trust it being safe. So one must always do manual validation for identifiers read from user input. |
currently if I want to create an index in postgre CONCURRENTLY it requires some config and using the db.raw, like this:
it sure would be nice, if this could be achievable with some config alias, for example like this:
The text was updated successfully, but these errors were encountered: