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

73 Views Asked by At

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?

1

There are 1 best solutions below

0
Joakim Danielson On

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")