detached b90f302

bootstrapdb create 3 tables user/account/session

commit
b90f3020ea3b501f144989ed6984f03b727a268a
author
Brice · · 2023-09-15 16:41 UTC
parent
aaa2ba9
signature
unsigned
2 files · +60 -5
M internal/app/sqliteinit.go +6 -0
@@ -83,6 +83,12 @@ func bootstrapDB(dbPath string) error {
8383 if err := migrate.CreateUserTable(db); err != nil {
8484 return err
8585 }
86+ if err := migrate.CreateAccountTable(db); err != nil {
87+ return err
88+ }
89+ if err := migrate.CreateSessionTable(db); err != nil {
90+ return err
91+ }
8692
8793 return nil
8894 }
@@ -83,6 +83,12 @@ func bootstrapDB(dbPath string) error {
83 if err := migrate.CreateUserTable(db); err != nil {83 if err := migrate.CreateUserTable(db); err != nil {
84 return err84 return err
85 }85 }
86+ if err := migrate.CreateAccountTable(db); err != nil {
87+ return err
88+ }
89+ if err := migrate.CreateSessionTable(db); err != nil {
90+ return err
91+ }
86 92
87 return nil93 return nil
88 }94 }
M internal/database/migrate/bootstrapdb.go +54 -5
@@ -5,14 +5,16 @@ import (
55 "fmt"
66 )
77
8-// createUserTable creates the 'user' table in the provided SQLite database.
8+// CreateUserTable creates the 'users' table.
99 func CreateUserTable(db *sql.DB) error {
1010 createTableSQL := `
1111 CREATE TABLE users (
12- id INTEGER PRIMARY KEY AUTOINCREMENT,
13- username TEXT NOT NULL,
14- password TEXT NOT NULL, -- This should be hashed and salted in a real-world scenario.
15- oauth_token TEXT
12+ id VARCHAR(255) PRIMARY KEY,
13+ name VARCHAR(255) UNIQUE NOT NULL,
14+ email VARCHAR(255) UNIQUE NOT NULL,
15+ email_verified DATETIME,
16+ image VARCHAR(255),
17+ is_admin BOOLEAN DEFAULT FALSE
1618 );`
1719
1820 _, err := db.Exec(createTableSQL)
@@ -22,3 +24,50 @@ func CreateUserTable(db *sql.DB) error {
2224
2325 return nil
2426 }
27+
28+// CreateAccountTable creates the 'accounts' table.
29+func CreateAccountTable(db *sql.DB) error {
30+ createTableSQL := `
31+ CREATE TABLE accounts (
32+ id VARCHAR(255) PRIMARY KEY,
33+ user_id VARCHAR(255) NOT NULL,
34+ type VARCHAR(50) NOT NULL,
35+ provider VARCHAR(50) NOT NULL,
36+ provider_account_id VARCHAR(255) NOT NULL,
37+ refresh_token VARCHAR(255),
38+ access_token VARCHAR(255),
39+ expires_at DATETIME,
40+ token_type VARCHAR(50),
41+ scope VARCHAR(255),
42+ id_token VARCHAR(255),
43+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
44+ );`
45+
46+ _, err := db.Exec(createTableSQL)
47+ if err != nil {
48+ return fmt.Errorf("failed to create account table: %v", err)
49+ }
50+
51+ return nil
52+}
53+
54+// CreateSessionTable creates the 'sessions' table.
55+func CreateSessionTable(db *sql.DB) error {
56+ createTableSQL := `
57+ CREATE TABLE sessions (
58+ id VARCHAR(255) PRIMARY KEY,
59+ session_token VARCHAR(255) UNIQUE NOT NULL,
60+ user_id VARCHAR(255) NOT NULL,
61+ expires DATETIME,
62+ is_online BOOLEAN DEFAULT FALSE,
63+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
64+ );
65+ CREATE INDEX idx_sessions_user_id ON sessions(user_id);`
66+
67+ _, err := db.Exec(createTableSQL)
68+ if err != nil {
69+ return fmt.Errorf("failed to create session table: %v", err)
70+ }
71+
72+ return nil
73+}
@@ -5,14 +5,16 @@ import (
5 "fmt"5 "fmt"
6 )6 )
7 7
8-// createUserTable creates the 'user' table in the provided SQLite database.8+// CreateUserTable creates the 'users' table.
9 func CreateUserTable(db *sql.DB) error {9 func CreateUserTable(db *sql.DB) error {
10 createTableSQL := `10 createTableSQL := `
11 CREATE TABLE users (11 CREATE TABLE users (
12- id INTEGER PRIMARY KEY AUTOINCREMENT,12+ id VARCHAR(255) PRIMARY KEY,
13- username TEXT NOT NULL,13+ name VARCHAR(255) UNIQUE NOT NULL,
14- password TEXT NOT NULL, -- This should be hashed and salted in a real-world scenario.14+ email VARCHAR(255) UNIQUE NOT NULL,
15- oauth_token TEXT15+ email_verified DATETIME,
16+ image VARCHAR(255),
17+ is_admin BOOLEAN DEFAULT FALSE
16 );`18 );`
17 19
18 _, err := db.Exec(createTableSQL)20 _, err := db.Exec(createTableSQL)
@@ -22,3 +24,50 @@ func CreateUserTable(db *sql.DB) error {
22 24
23 return nil25 return nil
24 }26 }
27+
28+// CreateAccountTable creates the 'accounts' table.
29+func CreateAccountTable(db *sql.DB) error {
30+ createTableSQL := `
31+ CREATE TABLE accounts (
32+ id VARCHAR(255) PRIMARY KEY,
33+ user_id VARCHAR(255) NOT NULL,
34+ type VARCHAR(50) NOT NULL,
35+ provider VARCHAR(50) NOT NULL,
36+ provider_account_id VARCHAR(255) NOT NULL,
37+ refresh_token VARCHAR(255),
38+ access_token VARCHAR(255),
39+ expires_at DATETIME,
40+ token_type VARCHAR(50),
41+ scope VARCHAR(255),
42+ id_token VARCHAR(255),
43+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
44+ );`
45+
46+ _, err := db.Exec(createTableSQL)
47+ if err != nil {
48+ return fmt.Errorf("failed to create account table: %v", err)
49+ }
50+
51+ return nil
52+}
53+
54+// CreateSessionTable creates the 'sessions' table.
55+func CreateSessionTable(db *sql.DB) error {
56+ createTableSQL := `
57+ CREATE TABLE sessions (
58+ id VARCHAR(255) PRIMARY KEY,
59+ session_token VARCHAR(255) UNIQUE NOT NULL,
60+ user_id VARCHAR(255) NOT NULL,
61+ expires DATETIME,
62+ is_online BOOLEAN DEFAULT FALSE,
63+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
64+ );
65+ CREATE INDEX idx_sessions_user_id ON sessions(user_id);`
66+
67+ _, err := db.Exec(createTableSQL)
68+ if err != nil {
69+ return fmt.Errorf("failed to create session table: %v", err)
70+ }
71+
72+ return nil
73+}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close