feat: next
This commit is contained in:
22
server/db/migrations/20250418055807_passkeys.sql
Normal file
22
server/db/migrations/20250418055807_passkeys.sql
Normal file
@ -0,0 +1,22 @@
|
||||
-- migrate:up
|
||||
CREATE TABLE credential (
|
||||
cred_id TEXT PRIMARY KEY NOT NULL,
|
||||
cred_public_key BLOB NOT NULL,
|
||||
sign_count INTEGER NOT NULL,
|
||||
transports TEXT,
|
||||
user_verified BOOLEAN,
|
||||
backup_eligible BOOLEAN,
|
||||
backup_state BOOLEAN,
|
||||
attestation_object BLOB,
|
||||
attestation_client_data BLOB,
|
||||
created_at DATETIME NOT NULL,
|
||||
last_used DATETIME NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
|
||||
FOREIGN KEY (user_id) REFERENCES user (id)
|
||||
);
|
||||
ALTER TABLE user ADD webauthn_id TEXT NOT NULL;
|
||||
|
||||
-- migrate:down
|
||||
DROP TABLE credential;
|
||||
ALTER TABLE user DROP COLUMN webauthn_id;
|
83
server/db/queries/credential.sql
Normal file
83
server/db/queries/credential.sql
Normal file
@ -0,0 +1,83 @@
|
||||
-- name: GetCredential :one
|
||||
SELECT
|
||||
cred_id,
|
||||
cred_public_key,
|
||||
sign_count,
|
||||
transports,
|
||||
user_verified,
|
||||
backup_eligible,
|
||||
backup_state,
|
||||
attestation_object,
|
||||
attestation_client_data,
|
||||
created_at,
|
||||
last_used,
|
||||
user_id
|
||||
FROM credential
|
||||
WHERE
|
||||
cred_id = @id
|
||||
AND
|
||||
user_id = @user_id
|
||||
LIMIT 1;
|
||||
|
||||
-- name: GetCredentials :many
|
||||
SELECT
|
||||
cred_id,
|
||||
cred_public_key,
|
||||
sign_count,
|
||||
transports,
|
||||
user_verified,
|
||||
backup_eligible,
|
||||
backup_state,
|
||||
attestation_object,
|
||||
attestation_client_data,
|
||||
created_at,
|
||||
last_used,
|
||||
user_id
|
||||
FROM credential
|
||||
WHERE user_id = @user_id;
|
||||
|
||||
-- name: InsertCredential :exec
|
||||
INSERT INTO credential (
|
||||
cred_id,
|
||||
cred_public_key,
|
||||
sign_count,
|
||||
transports,
|
||||
user_verified,
|
||||
backup_eligible,
|
||||
backup_state,
|
||||
attestation_object,
|
||||
attestation_client_data,
|
||||
created_at,
|
||||
last_used,
|
||||
user_id
|
||||
) VALUES (
|
||||
@cred_id,
|
||||
@cred_public_key,
|
||||
@sign_count,
|
||||
@transports,
|
||||
@user_verified,
|
||||
@backup_eligible,
|
||||
@backup_state,
|
||||
@attestation_object,
|
||||
@attestation_client_data,
|
||||
@created_at,
|
||||
@last_used,
|
||||
@user_id
|
||||
);
|
||||
|
||||
-- name: UpdateCredential :exec
|
||||
UPDATE credential
|
||||
SET
|
||||
last_used = COALESCE(sqlc.narg('last_used'), last_used),
|
||||
sign_count = COALESCE(sqlc.narg('sign_count'), sign_count)
|
||||
WHERE
|
||||
cred_id = @id
|
||||
AND
|
||||
user_id = @user_id;
|
||||
|
||||
-- name: DeleteCredential :exec
|
||||
DELETE FROM credential
|
||||
WHERE
|
||||
cred_id = @id
|
||||
AND
|
||||
user_id = @user_id;
|
@ -34,6 +34,7 @@ WHERE
|
||||
AND
|
||||
(added <= sqlc.narg('end') OR sqlc.narg('end') IS NULL)
|
||||
)
|
||||
ORDER BY added DESC
|
||||
LIMIT
|
||||
@limit
|
||||
OFFSET
|
||||
|
@ -3,7 +3,8 @@ SELECT
|
||||
id,
|
||||
username,
|
||||
password,
|
||||
profile_picture_id
|
||||
profile_picture_id,
|
||||
webauthn_id
|
||||
FROM user
|
||||
WHERE
|
||||
id = @id
|
||||
@ -14,7 +15,8 @@ SELECT
|
||||
id,
|
||||
username,
|
||||
password,
|
||||
profile_picture_id
|
||||
profile_picture_id,
|
||||
webauthn_id
|
||||
FROM user
|
||||
WHERE
|
||||
username = @username
|
||||
@ -23,10 +25,12 @@ LIMIT 1;
|
||||
-- name: InsertUser :one
|
||||
INSERT INTO user (
|
||||
username,
|
||||
password
|
||||
password,
|
||||
webauthn_id
|
||||
) VALUES (
|
||||
@username,
|
||||
@password
|
||||
@password,
|
||||
@webauthn_id
|
||||
)
|
||||
RETURNING id;
|
||||
|
||||
|
@ -3,7 +3,7 @@ CREATE TABLE user (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
username TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
profile_picture_id INTEGER,
|
||||
profile_picture_id INTEGER, webauthn_id TEXT NOT NULL,
|
||||
|
||||
FOREIGN KEY (profile_picture_id) REFERENCES file (id)
|
||||
);
|
||||
@ -26,6 +26,23 @@ CREATE TABLE item (
|
||||
|
||||
FOREIGN KEY (user_id) REFERENCES user (id)
|
||||
);
|
||||
CREATE TABLE credential (
|
||||
cred_id TEXT PRIMARY KEY NOT NULL,
|
||||
cred_public_key BLOB NOT NULL,
|
||||
sign_count INTEGER NOT NULL,
|
||||
transports TEXT,
|
||||
user_verified BOOLEAN,
|
||||
backup_eligible BOOLEAN,
|
||||
backup_state BOOLEAN,
|
||||
attestation_object BLOB,
|
||||
attestation_client_data BLOB,
|
||||
created_at DATETIME NOT NULL,
|
||||
last_used DATETIME NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
|
||||
FOREIGN KEY (user_id) REFERENCES user (id)
|
||||
);
|
||||
-- Dbmate schema migrations
|
||||
INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20250410195416');
|
||||
('20250410195416'),
|
||||
('20250418055807');
|
||||
|
Reference in New Issue
Block a user