Sql comments and salts table
This commit is contained in:
parent
9b67a580da
commit
736cebe036
2 changed files with 20 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
-- Id is a surrogate key for in ternal use
|
||||
-- userId is what is used for external id
|
||||
-- username is what is used for login
|
||||
-- password is the hashed password
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY,
|
||||
userId TEXT DEFAULT (HEX(RANDOMBLOB(4))) NOT NULL UNIQUE,
|
||||
|
@ -5,5 +9,6 @@ CREATE TABLE IF NOT EXISTS users (
|
|||
password VARCHAR(255) NOT NULL
|
||||
);
|
||||
|
||||
-- Users are commonly searched by username and userId
|
||||
CREATE INDEX IF NOT EXISTS users_username_index ON users (username);
|
||||
CREATE INDEX IF NOT EXISTS users_userId_index ON users (userId);
|
15
backend/internal/database/migrations/0070_salts.sql
Normal file
15
backend/internal/database/migrations/0070_salts.sql
Normal file
|
@ -0,0 +1,15 @@
|
|||
-- It is unclear weather this table will be used
|
||||
|
||||
-- Create the table to store hash salts
|
||||
CREATE TABLE salts (
|
||||
id INTEGER PRIMARY KEY,
|
||||
salt TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- Create a trigger to automatically generate a salt when inserting a new user record
|
||||
CREATE TRIGGER generate_salt_trigger
|
||||
AFTER INSERT ON users
|
||||
BEGIN
|
||||
INSERT INTO salts (salt) VALUES (randomblob(16));
|
||||
UPDATE users SET salt_id = (SELECT last_insert_rowid()) WHERE id = new.id;
|
||||
END;
|
Loading…
Reference in a new issue