Rob Bonner
Rob Bonner

Reputation: 9424

How do you default a column to the current date in GRDB

We use GRDB for our iOS application and am adding the following migration:

 migrator.registerMigration("v7") { db in
        try db.alter(table: "DocAlertThirdPartyTrackingUrl") { t in
            t.add(column: DocAlertThirdPartyTrackingUrl.CodingKeys.initialDate.rawValue, .date).defaults(to: ?????)
        }
    }

Not sure how to set this up so it uses the current date as the default?

Upvotes: 1

Views: 243

Answers (1)

Joakim Danielson
Joakim Danielson

Reputation: 51973

If you want a default value that is always the current date you need to do it at a database level so use the sql variant of the defaults function

.defaults(sql: "CURRENT_TIMESTAMP")

Upvotes: 1

Related Questions