-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add starting work on multiple mfa devices
- Loading branch information
Showing
10 changed files
with
346 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
internal/data/migrations/20230703205540_move_mfa_to_own_table_enable_foreign_keys.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
-- version 10 | ||
|
||
|
||
-- Create temp table so the CASCADE DELETE is not triggered on table drop | ||
CREATE TABLE IF NOT EXISTS temp ( | ||
id INTEGER primary key, | ||
username string NOT NULL, | ||
mfa_type string NOT NULL, | ||
mfa string NOT NULL | ||
); | ||
|
||
INSERT INTO temp (username, mfa_type, mfa) SELECT username, mfa_type, mfa FROM Users; | ||
|
||
-- Move MFA data to new table rather than keeping the field in the users table | ||
ALTER TABLE Users RENAME TO Users_old; | ||
CREATE TABLE Users ( username string primary key, enforcing string, locked BOOLEAN DEFAULT FALSE NOT NULL); | ||
INSERT INTO Users (username, enforcing, locked) SELECT username, enforcing, locked FROM Users_old; | ||
DROP TABLE Users_old; | ||
|
||
|
||
CREATE TABLE IF NOT EXISTS MFA ( | ||
id INTEGER primary key, | ||
username string NOT NULL, | ||
mfa_type string NOT NULL, | ||
mfa string NOT NULL, | ||
|
||
FOREIGN KEY (username) references Users(username) ON DELETE CASCADE, | ||
|
||
UNIQUE (username, mfa_type) | ||
); | ||
|
||
INSERT INTO MFA (username, mfa_type, mfa) SELECT username, mfa_type, mfa FROM temp; | ||
DROP TABLE temp; | ||
|
||
|
||
|
||
-- Start using foreign keys for devices too | ||
ALTER TABLE Devices RENAME TO Devices_old; | ||
CREATE TABLE Devices( | ||
address string primary key, | ||
username string not null, | ||
publickey string not null unique, | ||
endpoint string, | ||
attempts integer DEFAULT 0 not null, | ||
|
||
FOREIGN KEY (username) references Users(username) ON DELETE CASCADE | ||
); | ||
|
||
INSERT INTO Devices (address,username, publickey, endpoint, attempts) SELECT address, username, publickey, endpoint, attempts FROM Devices_old; | ||
DROP TABLE Devices_old; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.