Chapter 18 making usernames unique

I’ve been struggling with this for far too long. Not sure exactly what is going wrong here tbh.

when re-writing the Migration extension for adding unique User property I get an error saying that SchemaCreator has no member ‘addIndex’

extension User: Migration { static func prepare(on connection: PostgreSQLConnection) -> Future<Void> { return Database.create(self, on: connection) { builder in try addProperties(to: builder) try builder.addIndex(to: \.username, isUnique: true) } } }

It changed slightly a while ago, see:

awesome thanks! hopefully this is changed in the final version fo the book.

Incidentally right after this section in the book where you revert your db in Xcode, I did so then launched RESTed to add a new user and password but RESTed was not able to connect to the localhost server. Somehow my postgres db in docker was stopped and not restarted so the app would crash and I got an error that had something to do with NIO not being able to communicate with postgres. I’m no docker expert so I ended up removing the docker image of the postgres and configuring the image again in order to have the db connect again which resolved my issue and I was able to continue.

@beefycode yep it’s been updated and pending release. Did you laptop restart in that time? If you run docker ps -a you can see all containers, including stopped ones, so you can then just do docker start postgres if it’s stopped

@0xtim I may have shutdown my computer overnight, honestly I don’t recall. Either way, I did read up more on docker’s commands and I’m sure re-starting the container like you suggested would probably have been easier, but both methods had the same result and I was able to keep going.

Basically the only difference is you’d keep the existing data. Glad it’s working though!