storage: fix postgres timezone handling
Dex's Postgres client currently uses the `timestamp` datatype for storing times. This lops of timezones with no conversion, causing times to lose locality information. We could convert all times to UTC before storing them, but this is a backward incompatible change for upgrades, since the new version of dex would still be reading times from the database with no locality. Because of this intrinsic issue that current Postgres users don't save any timezone data, we chose to treat any existing installation as corrupted and change the datatype used for times to `timestamptz`. This is a breaking change, but it seems hard to offer an alternative that's both correct and backward compatible. Additionally, an internal flag has been added to SQL flavors, `supportsTimezones`. This allows us to handle SQLite3, which doesn't support timezones, while still storing timezones in other flavors. Flavors that don't support timezones are explicitly converted to UTC.
This commit is contained in:
@@ -9,7 +9,7 @@ func (c *conn) migrate() (int, error) {
|
||||
_, err := c.Exec(`
|
||||
create table if not exists migrations (
|
||||
num integer not null,
|
||||
at timestamp not null
|
||||
at timestamptz not null
|
||||
);
|
||||
`)
|
||||
if err != nil {
|
||||
@@ -100,7 +100,7 @@ var migrations = []migration{
|
||||
connector_id text not null,
|
||||
connector_data bytea,
|
||||
|
||||
expiry timestamp not null
|
||||
expiry timestamptz not null
|
||||
);
|
||||
|
||||
create table auth_code (
|
||||
@@ -119,7 +119,7 @@ var migrations = []migration{
|
||||
connector_id text not null,
|
||||
connector_data bytea,
|
||||
|
||||
expiry timestamp not null
|
||||
expiry timestamptz not null
|
||||
);
|
||||
|
||||
create table refresh_token (
|
||||
@@ -151,7 +151,7 @@ var migrations = []migration{
|
||||
verification_keys bytea not null, -- JSON array
|
||||
signing_key bytea not null, -- JSON object
|
||||
signing_key_pub bytea not null, -- JSON object
|
||||
next_rotation timestamp not null
|
||||
next_rotation timestamptz not null
|
||||
);
|
||||
`,
|
||||
},
|
||||
|
Reference in New Issue
Block a user