Skip to content

Commit ffe8c85

Browse files
committed
feat(db): add migrations for storing api keys and implement CRUD
1 parent 949e751 commit ffe8c85

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- Add migration script here
2+
CREATE TABLE IF NOT EXISTS api_keys (
3+
id INTEGER PRIMARY KEY AUTOINCREMENT,
4+
key_hash TEXT NOT NULL UNIQUE,
5+
name TEXT NOT NULL,
6+
permissions TEXT NOT NULL,
7+
created_at INTEGER NOT NULL,
8+
expires_at INTEGER,
9+
last_used_at INTEGER,
10+
is_active INTEGER NOT NULL DEFAULT 1
11+
);
12+
13+
-- Index for faster lookups by hash (used on every API request)
14+
CREATE INDEX IF NOT EXISTS idx_api_keys_hash ON api_keys(key_hash);
15+
16+
-- Index for active keys only
17+
CREATE INDEX IF NOT EXISTS idx_api_keys_active ON api_keys(is_active);

rustmail/src/db/operations/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod api_keys;
12
pub mod features;
23
pub mod init;
34
pub mod logs;
@@ -6,6 +7,7 @@ pub mod reminders;
67
pub mod scheduled;
78
pub mod threads;
89

10+
pub use api_keys::*;
911
pub use features::*;
1012
pub use init::*;
1113
pub use logs::*;

0 commit comments

Comments
 (0)