From f3f3b31b12a87586770c5cfaf646a9e85a724089 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Thu, 2 Dec 2021 12:24:10 +1100 Subject: [PATCH] refactor(storage): totp_configurations table (#2657) Rename column totp_period to period. --- internal/models/totp_configuration.go | 2 +- .../migrations/V0001.Initial_Schema.mysql.up.sql | 2 +- .../migrations/V0001.Initial_Schema.postgres.up.sql | 2 +- .../migrations/V0001.Initial_Schema.sqlite.up.sql | 2 +- internal/storage/sql_provider_queries.go | 10 +++++----- internal/storage/sql_provider_queries_special.go | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/models/totp_configuration.go b/internal/models/totp_configuration.go index 674bc43e6..758a47c7c 100644 --- a/internal/models/totp_configuration.go +++ b/internal/models/totp_configuration.go @@ -12,7 +12,7 @@ type TOTPConfiguration struct { Issuer string `db:"issuer" json:"-"` Algorithm string `db:"algorithm" json:"-"` Digits uint `db:"digits" json:"digits"` - Period uint `db:"totp_period" json:"period"` + Period uint `db:"period" json:"period"` Secret []byte `db:"secret" json:"-"` } diff --git a/internal/storage/migrations/V0001.Initial_Schema.mysql.up.sql b/internal/storage/migrations/V0001.Initial_Schema.mysql.up.sql index 93102a506..44ab514ba 100644 --- a/internal/storage/migrations/V0001.Initial_Schema.mysql.up.sql +++ b/internal/storage/migrations/V0001.Initial_Schema.mysql.up.sql @@ -32,7 +32,7 @@ CREATE TABLE IF NOT EXISTS totp_configurations ( issuer VARCHAR(100), algorithm VARCHAR(6) NOT NULL DEFAULT 'SHA1', digits INTEGER NOT NULL DEFAULT 6, - totp_period INTEGER NOT NULL DEFAULT 30, + period INTEGER NOT NULL DEFAULT 30, secret BLOB NOT NULL, PRIMARY KEY (id), UNIQUE KEY (username) diff --git a/internal/storage/migrations/V0001.Initial_Schema.postgres.up.sql b/internal/storage/migrations/V0001.Initial_Schema.postgres.up.sql index 4cf1f0756..800330b03 100644 --- a/internal/storage/migrations/V0001.Initial_Schema.postgres.up.sql +++ b/internal/storage/migrations/V0001.Initial_Schema.postgres.up.sql @@ -32,7 +32,7 @@ CREATE TABLE IF NOT EXISTS totp_configurations ( issuer VARCHAR(100), algorithm VARCHAR(6) NOT NULL DEFAULT 'SHA1', digits INTEGER NOT NULL DEFAULT 6, - totp_period INTEGER NOT NULL DEFAULT 30, + period INTEGER NOT NULL DEFAULT 30, secret BYTEA NOT NULL, PRIMARY KEY (id), UNIQUE (username) diff --git a/internal/storage/migrations/V0001.Initial_Schema.sqlite.up.sql b/internal/storage/migrations/V0001.Initial_Schema.sqlite.up.sql index a731aacc7..f5876e251 100644 --- a/internal/storage/migrations/V0001.Initial_Schema.sqlite.up.sql +++ b/internal/storage/migrations/V0001.Initial_Schema.sqlite.up.sql @@ -32,7 +32,7 @@ CREATE TABLE IF NOT EXISTS totp_configurations ( issuer VARCHAR(100), algorithm VARCHAR(6) NOT NULL DEFAULT 'SHA1', digits INTEGER NOT NULL DEFAULT 6, - totp_period INTEGER NOT NULL DEFAULT 30, + period INTEGER NOT NULL DEFAULT 30, secret BLOB NOT NULL, PRIMARY KEY (id), UNIQUE (username) diff --git a/internal/storage/sql_provider_queries.go b/internal/storage/sql_provider_queries.go index fbe7a0d48..1bf1a0b30 100644 --- a/internal/storage/sql_provider_queries.go +++ b/internal/storage/sql_provider_queries.go @@ -75,12 +75,12 @@ const ( const ( queryFmtSelectTOTPConfiguration = ` - SELECT id, username, issuer, algorithm, digits, totp_period, secret + SELECT id, username, issuer, algorithm, digits, period, secret FROM %s WHERE username = ?;` queryFmtSelectTOTPConfigurations = ` - SELECT id, username, issuer, algorithm, digits, totp_period, secret + SELECT id, username, issuer, algorithm, digits, period, secret FROM %s LIMIT ? OFFSET ?;` @@ -98,14 +98,14 @@ const ( WHERE username = ?;` queryFmtUpsertTOTPConfiguration = ` - REPLACE INTO %s (username, issuer, algorithm, digits, totp_period, secret) + REPLACE INTO %s (username, issuer, algorithm, digits, period, secret) VALUES (?, ?, ?, ?, ?, ?);` queryFmtPostgresUpsertTOTPConfiguration = ` - INSERT INTO %s (username, issuer, algorithm, digits, totp_period, secret) + INSERT INTO %s (username, issuer, algorithm, digits, period, secret) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (username) - DO UPDATE SET issuer = $2, algorithm = $3, digits = $4, totp_period = $5, secret = $6;` + DO UPDATE SET issuer = $2, algorithm = $3, digits = $4, period = $5, secret = $6;` queryFmtDeleteTOTPConfiguration = ` DELETE FROM %s diff --git a/internal/storage/sql_provider_queries_special.go b/internal/storage/sql_provider_queries_special.go index a7887c21d..3023191ad 100644 --- a/internal/storage/sql_provider_queries_special.go +++ b/internal/storage/sql_provider_queries_special.go @@ -36,7 +36,7 @@ const ( ORDER BY username ASC;` queryFmtPre1To1InsertTOTPConfiguration = ` - INSERT INTO %s (username, issuer, totp_period, secret) + INSERT INTO %s (username, issuer, period, secret) VALUES (?, ?, ?, ?);` queryFmt1ToPre1InsertTOTPConfiguration = `