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

Please bring back `addIndex` #515

Closed
MihaelIsaev opened this Issue Jun 18, 2018 · 4 comments

Comments

2 participants
@MihaelIsaev
Copy link
Member

MihaelIsaev commented Jun 18, 2018

@tanner0101 why addIndex was deprecated and now it suggest to use unique instead?
Unique adds UNIQUE INDEX, but I need to add just INDEX. I understand that now I can do that only by calling raw query, but it's inconvenient..
Could you please bring it back at least for FluentPostgreSQL?

@MihaelIsaev

This comment has been minimized.

Copy link
Member Author

MihaelIsaev commented Jun 18, 2018

workaround code

extension CarModel: Migration {
    public static func prepare(on connection: Database.Connection) -> Future<Void> {
        return Database.create(self, on: connection) { builder in
            try addProperties(to: builder)
            //builder.addIndex(to: \.idBrand) // deprecated! 😭
        }.flatMap { _ -> EventLoopFuture<Void> in
            return connection.query("CREATE INDEX idx_brand ON \"CarModels\" (\"idBrand\")").transform(to: ())
        }
    }
}

maybe it will help someone who faced with the same problem

@tanner0101 tanner0101 self-assigned this Jun 22, 2018

@tanner0101 tanner0101 added this to the 3.0.0-rc.4.1 milestone Jun 22, 2018

@tanner0101

This comment has been minimized.

Copy link
Member

tanner0101 commented Jun 22, 2018

Sorry for the inconvenience caused by addIndex going away. The problem is that adding just an INDEX column constraint during CREATE TABLE is not standard SQL. All SQL dialects do support UNIQUE column constraint.

The standard for creating indexes is to issue a CREATE INDEX query. I will add support for building these queries to vapor/sql so that you can easily create and drop indexes using a SQL db. 👍

@MihaelIsaev

This comment has been minimized.

Copy link
Member Author

MihaelIsaev commented Jun 22, 2018

@tanner0101 Thank you! 😊

@tanner0101

This comment has been minimized.

Copy link
Member

tanner0101 commented Jun 22, 2018

Added :) Check the release for a preview of the syntax @MihaelIsaev https://github.com/vapor/postgresql/releases/tag/1.0.0-rc.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment