Skip to content

Commit b4552c2

Browse files
committed
chore(compose): updates SQL db schemes
Signed-off-by: Pierre 'McFly' Marty <[email protected]>
1 parent 1e485b3 commit b4552c2

File tree

7 files changed

+192
-45
lines changed

7 files changed

+192
-45
lines changed

.compose/examples/tom+fed+chat.pgsql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ services:
155155
# - NODE_OPTIONS="--inspect=0.0.0.0:9229"
156156
- NODE_TLS_REJECT_UNAUTHORIZED=0
157157

158-
- BASE_URL=https://fed.docker.localhost
159158
- SERVER_NAME=docker.localhost
159+
- BASE_URL=https://fed.docker.localhost
160160
- TRUSTED_PROXIES=uniquelocal
161161
- TRUSTED_SERVERS_ADDRESSES=172.0.0.0/8
162162

.compose/lemon/create-user.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

.compose/lemon/init-db.sh

Lines changed: 100 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,103 @@
11
#!/usr/bin/env bash
22
# vim: set filetype=sh ts=2 sw=2 sts=2 expandtab :
33

4-
echo "Inflating Auth DB."
5-
sqlite3 lemon.db "Create table if not exists users (uid text,name text,mail text,mobile text,password text);"
6-
[[ "$?" == '0' ]] && echo "Done."
7-
8-
# nickname # Full Name # mail # mobile # password
9-
./create-user.sh 'dwho' 'Doctor Who' '[email protected]' '+33612345678' 'dwho'
10-
./create-user.sh 'rtyler' 'R. Tyler' '[email protected]' '+11234567890' 'rtyler'
11-
./create-user.sh 'jbinks' 'Jar Jar Binks' '[email protected]' '+84123456789' 'jbinks'
4+
echo "Inflating Authentication Database (lemon.db)."
5+
6+
# Create the users table if it doesn't already exist
7+
sqlite3 lemon.db "CREATE TABLE IF NOT EXISTS users (
8+
id INTEGER PRIMARY KEY AUTOINCREMENT,
9+
username TEXT,
10+
password TEXT,
11+
sn TEXT,
12+
mail TEXT,
13+
givenname TEXT,
14+
mobile TEXT,
15+
isadmin INTEGER DEFAULT 0,
16+
isblocked INTEGER DEFAULT 0
17+
);"
18+
[[ "$?" == '0' ]] && echo "Table 'users' created or already exists." || { echo "Error creating table 'users'. Exiting."; exit 1; }
19+
20+
# Create unique indexes for frequently searched fields
21+
# Note: The UNIQUE constraint on 'mail' above handles its uniqueness.
22+
sqlite3 lemon.db "CREATE UNIQUE INDEX IF NOT EXISTS u__username ON users (username);"
23+
[[ "$?" == '0' ]] && echo "Index 'u__username' created or already exists." || { echo "Error creating index 'u__username'. Exiting."; exit 1; }
24+
25+
sqlite3 lemon.db "CREATE UNIQUE INDEX IF NOT EXISTS u__mail ON users (mail);"
26+
[[ "$?" == '0' ]] && echo "Index 'u__mail' created or already exists." || { echo "Error creating index 'u__mail'. Exiting."; exit 1; }
27+
28+
sqlite3 lemon.db "CREATE UNIQUE INDEX IF NOT EXISTS u__mobile ON users (mobile);"
29+
[[ "$?" == '0' ]] && echo "Index 'u__mobile' created or already exists." || { echo "Error creating index 'u__mobile'. Exiting."; exit 1; }
30+
31+
echo "Inserting user data..."
32+
33+
# Insert user data matching the PostgreSQL schema
34+
# Using INSERT OR IGNORE to skip rows that would violate unique constraints (e.g., duplicate emails)
35+
# Derivation Logic:
36+
# givenname: Use 'givenName' from LDIF if present. Otherwise, use the first word of 'cn'.
37+
# sn: If 'cn' has multiple words, use the last word of 'cn'. Otherwise, use 'sn' from LDIF if present, else NULL.
38+
sqlite3 lemon.db "INSERT OR IGNORE INTO users (username, password, givenname, sn, mail, mobile) VALUES
39+
('dwho', 'dwho', 'Doctor', 'Who', '[email protected]', '+33612345678'),
40+
('rtyler', 'rtyler', 'R.', 'Tyler', '[email protected]', '+11234567890'),
41+
('jbinks', 'jbinks', 'Jar Jar', 'Binks', '[email protected]', '+84123456789'),
42+
('msmith', 'msmith', 'Mr', 'Smith', '[email protected]', NULL),
43+
('okenobi', 'okenobi', 'Obi-Wan', 'Kenobi', '[email protected]', NULL),
44+
('qjinn', 'qjinn', 'Qui-Gon', 'Jinn', '[email protected]', NULL),
45+
('chewbacca', 'chewbacca', 'Chewbacca', 'Chewbacca', '[email protected]', NULL),
46+
('lorgana', 'lorgana', 'Leia', 'Organa', '[email protected]', NULL),
47+
('pamidala', 'pamidala', 'Padme', 'Amidala', '[email protected]', NULL),
48+
('cdooku', 'cdooku', 'Comte', 'Dooku', '[email protected]', NULL),
49+
('kren', 'kren', 'Kylo', 'Ren', '[email protected]', NULL),
50+
('dmaul', 'dmaul', 'Dark', 'Maul', '[email protected]', NULL),
51+
('askywalker', 'askywalker', 'Anakin', 'Skywalker', '[email protected]', NULL),
52+
('bfett', 'bfett', 'Boba', 'Fett', '[email protected]', NULL),
53+
('jfett', 'jfett', 'Jango', 'Ffett', '[email protected]', NULL),
54+
('lskywalker', 'lskywalker', 'Luc', 'Skywalker', '[email protected]', NULL),
55+
('myoda', 'myoda', 'Master', 'Yoda', '[email protected]', NULL),
56+
('hsolo', 'hsolo', 'Han', 'Solo', '[email protected]', NULL),
57+
('r2d2', 'r2d2', 'R2D2', 'R2D2', '[email protected]', NULL),
58+
('c3po', 'c3po', 'C3PO', 'C3po', '[email protected]', NULL),
59+
('synapseadmin', 'synapseadmin', 'Synapse', 'Syadmin', '[email protected]', NULL),
60+
('annasmith', 'annasmith', 'Anna', 'Smith', '[email protected]', NULL),
61+
('johnjohnson', 'johnjohnson', 'John', 'Johnson', '[email protected]', NULL),
62+
('emilybrown', 'emilybrown', 'Emily', 'Brown', '[email protected]', NULL),
63+
('daviddavis', 'daviddavis', 'David', 'Davis', '[email protected]', NULL),
64+
('sarahwilson', 'sarahwilson', 'Sarah', 'Wilson', '[email protected]', NULL),
65+
('miketaylor', 'miketaylor', 'Mike', 'Taylor', '[email protected]', NULL),
66+
('graceadams', 'graceadams', 'Grace', 'Adams', '[email protected]', NULL),
67+
('mattmoore', 'mattmoore', 'Matt', 'Moore', '[email protected]', NULL),
68+
('lilyparker', 'lilyparker', 'Lily', 'Parker', '[email protected]', NULL),
69+
('danieldixon', 'danieldixon', 'Daniel', 'Dixon', '[email protected]', NULL),
70+
('mialopez', 'mialopez', 'Mia', 'Lopez', '[email protected]', NULL),
71+
('ethanjackson', 'ethanjackson', 'Ethan', 'Jackson', '[email protected]', NULL),
72+
('oliviaroberts', 'oliviaroberts', 'Olivia', 'Roberts', '[email protected]', NULL),
73+
('jamessmith', 'jamessmith', 'James', 'Smith', '[email protected]', NULL),
74+
('sophiathomas', 'sophiathomas', 'Sophia', 'Thomas', '[email protected]', NULL),
75+
('benjaminclark', 'benjaminclark', 'Benjamin', 'Clark', '[email protected]', NULL),
76+
('avamartin', 'avamartin', 'Ava', 'Martin', '[email protected]', NULL),
77+
('williamrogers', 'williamrogers', 'William', 'Rogers', '[email protected]', NULL),
78+
('emmawright', 'emmawright', 'Emma', 'Wright', '[email protected]', NULL),
79+
('chloescott', 'chloescott', 'Chloe', 'Scott', '[email protected]', NULL),
80+
('danieltaylor', 'danieltaylor', 'Daniel', 'Taylor', '[email protected]', NULL),
81+
('sophiarichardson', 'sophiarichardson', 'Sophia', 'Richardson', '[email protected]', NULL),
82+
('henryjones', 'henryjones', 'Henry', 'Jones', '[email protected]', NULL),
83+
('gracelewis', 'gracelewis', 'Lewis', '[email protected]', 'Grace', NULL),
84+
('samuelharris', 'samuelharris', 'Harris', '[email protected]', 'Samuel', NULL),
85+
('ameliahall', 'ameliahall', 'Amelia', 'Hall', '[email protected]', NULL),
86+
('lucyedwards', 'lucyedwards', 'Edwards', '[email protected]', 'Lucy', NULL),
87+
('christophermiller', 'christophermiller', 'Miller', '[email protected]', 'Christopher', NULL),
88+
('emilyperez', 'emilyperez', 'Perez', '[email protected]', 'Emily', NULL),
89+
('andrewcook', 'andrewcook', 'Andrew', 'Cook', '[email protected]', NULL),
90+
('oliviaparker', 'oliviaparker', 'Parker', '[email protected]', 'Olivia', NULL),
91+
('josephmartin', 'josephmartin', 'Joseph', 'Martin', '[email protected]', NULL),
92+
('lilybrown', 'lilybrown', 'Brown', '[email protected]', 'Lily', NULL),
93+
('elizabethlee', 'elizabethlee', 'Lee', '[email protected]', 'Elizabeth', NULL),
94+
('ethangreen', 'ethangreen', 'Green', '[email protected]', 'Ethan', NULL),
95+
('noahroberts', 'noahroberts', 'Noah', 'Roberts', '[email protected]', NULL),
96+
('gracegarcia', 'gracegarcia', 'Garcia', '[email protected]', 'Grace', NULL),
97+
('avaclark', 'avaclark', 'Clark', '[email protected]', 'Ava', NULL),
98+
('sophiedavis', 'sophiedavis', 'Davis', '[email protected]', 'Sophie', NULL),
99+
('benjaminharrison', 'benjaminharrison', 'Harrison', '[email protected]', 'Benjamin', NULL);
100+
"
101+
[[ "$?" == '0' ]] && echo "All user data inserted successfully (or ignored if duplicates existed)." || { echo "Error inserting user data. Exiting."; exit 1; }
102+
103+
echo "Database setup complete: lemon.db"

.compose/lemon/lmConf-pgsql.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@
8989
"cspScript" : "'self'",
9090
"cspStyle" : "'self'",
9191
"dbiAuthChain" : "DBI:Pg:database=lemonldapng;host=pgsql",
92-
"dbiAuthLoginCol" : "uid",
92+
"dbiAuthLoginCol" : "username",
9393
"dbiAuthPassword" : "lemonldap",
9494
"dbiAuthPasswordCol" : "password",
9595
"dbiAuthTable" : "users",
9696
"dbiAuthUser" : "lemonldap",
9797
"dbiAuthnLevel" : 2,
9898
"dbiExportedVars" : {
99-
"uid" : "uid",
100-
"name" : "name",
99+
"uid" : "username",
100+
"name" : "sn",
101101
"email" : "mail",
102102
"phone" : "mobile"
103103
},

.compose/lemon/lmConf-sqlite.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@
8989
"cspScript" : "'self'",
9090
"cspStyle" : "'self'",
9191
"dbiAuthChain" : "dbi:SQLite:dbname=/db/lemon.db",
92-
"dbiAuthLoginCol" : "uid",
92+
"dbiAuthLoginCol" : "username",
9393
"dbiAuthPassword" : "",
9494
"dbiAuthPasswordCol" : "password",
9595
"dbiAuthTable" : "users",
9696
"dbiAuthUser" : "",
9797
"dbiAuthnLevel" : 2,
9898
"dbiExportedVars" : {
99-
"uid" : "uid",
100-
"name" : "name",
99+
"uid" : "username",
100+
"name" : "sn",
101101
"email" : "mail",
102102
"phone" : "mobile"
103103
},

.compose/pgsql/init-users-db.sh

Lines changed: 83 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,90 @@ PASSWORD=${PG_PASSWORD:-lemonldap}
77
TABLE=${PG_TABLE:-users}
88

99
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$DATABASE" <<-EOSQL
10-
CREATE TABLE IF NOT EXISTS $TABLE (
11-
uid VARCHAR(255) PRIMARY KEY NOT NULL,
12-
name VARCHAR(255) NOT NULL,
13-
mail VARCHAR(255) NOT NULL UNIQUE,
14-
password VARCHAR(255) NOT NULL,
15-
mobile VARCHAR(50)
16-
);
17-
GRANT ALL PRIVILEGES ON TABLE $TABLE TO $USER;
10+
CREATE TABLE IF NOT EXISTS $TABLE (
11+
id SERIAL PRIMARY KEY,
12+
username VARCHAR(64),
13+
password VARCHAR(64),
14+
sn VARCHAR(64),
15+
mail VARCHAR(64),
16+
givenname VARCHAR(64),
17+
mobile VARCHAR(20),
18+
isadmin BOOLEAN DEFAULT FALSE,
19+
isblocked BOOLEAN DEFAULT FALSE
20+
);
1821
19-
-- User: dwho
20-
INSERT INTO $TABLE (uid, name, mail, password, mobile) VALUES
21-
('dwho', 'Doctor Who', '[email protected]', 'dwho', '+442079460123');
22+
-- Create unique indexes for frequently searched fields
23+
CREATE UNIQUE INDEX u__username ON $TABLE USING btree(username);
24+
CREATE UNIQUE INDEX u__mail ON $TABLE USING btree(mail);
25+
CREATE UNIQUE INDEX u__mobile ON $TABLE USING btree(mobile);
2226
23-
-- User: rtyler
24-
INSERT INTO $TABLE (uid, name, mail, password, mobile) VALUES
25-
('rtyler', 'Rose Tyler', '[email protected]', 'rtyler', '+15559876543');
27+
-- Grant privileges to the specified user (replace $TABLE and $USER with actual values)
28+
GRANT ALL PRIVILEGES ON TABLE $TABLE TO $USER;
2629
27-
-- User: half
28-
INSERT INTO $TABLE (uid, name, mail, password, mobile) VALUES
29-
('half', 'Martha Jones', '[email protected]', 'half', '+33123456789');
30+
-- Insert user data based on LDIF reference with international phone number format
31+
-- Derivation Logic:
32+
-- givenname: Use 'givenName' from LDIF if present. Otherwise, use the first word of 'cn'.
33+
-- sn: If 'cn' has multiple words, use the last word of 'cn'. Otherwise, use 'sn' from LDIF if present, else NULL.
34+
INSERT INTO $TABLE (username, password, sn, mail, givenname, mobile) VALUES
35+
('dwho', 'dwho', 'Who', NULL, 'Dr', '+33671298765'),
36+
('rtyler', 'rtyler', 'Tyler', '[email protected]', 'Rose', '+33671298767'),
37+
('msmith', 'msmith', 'Smith', '[email protected]', 'Mr', NULL),
38+
('okenobi', 'okenobi', 'Kenobi', '[email protected]', 'Obi-Wan', NULL),
39+
('qjinn', 'qjinn', 'Jinn', '[email protected]', 'Qui-Gon', NULL),
40+
('chewbacca', 'chewbacca', 'Chewbacca', '[email protected]', 'Chewbacca', NULL),
41+
('lorgana', 'lorgana', 'Organa', '[email protected]', 'Leia', NULL),
42+
('pamidala', 'pamidala', 'Amidala', '[email protected]', 'Padme', NULL),
43+
('cdooku', 'cdooku', 'Dooku', '[email protected]', 'Comte', NULL),
44+
('kren', 'kren', 'Ren', '[email protected]', 'Kylo', NULL),
45+
('dmaul', 'dmaul', 'Maul', '[email protected]', 'Dark', NULL),
46+
('askywalker', 'askywalker', 'Skywalker', '[email protected]', 'Anakin', NULL),
47+
('jbinks', 'jbinks', 'Binks', '[email protected]', 'Jar Jar', NULL),
48+
('bfett', 'bfett', 'Fett', '[email protected]', 'Boba', NULL),
49+
('jfett', 'jfett', 'Ffett', '[email protected]', 'Jango', NULL),
50+
('lskywalker', 'lskywalker', 'Skywalker', '[email protected]', 'Luc', NULL),
51+
('myoda', 'myoda', 'Yoda', '[email protected]', 'Master', NULL),
52+
('hsolo', 'hsolo', 'Solo', '[email protected]', 'Han', NULL),
53+
('r2d2', 'r2d2', 'R2D2', '[email protected]', 'R2D2', NULL),
54+
('c3po', 'c3po', 'C3po', '[email protected]', 'C3PO', NULL),
55+
('synapseadmin', 'synapseadmin', 'Syadmin', '[email protected]', 'Synapse', NULL),
56+
('annasmith', 'annasmith', 'Smith', '[email protected]', 'Anna', NULL),
57+
('johnjohnson', 'johnjohnson', 'Johnson', '[email protected]', 'John', NULL),
58+
('emilybrown', 'emilybrown', 'Brown', '[email protected]', 'Emily', NULL),
59+
('daviddavis', 'daviddavis', 'Davis', '[email protected]', 'David', NULL),
60+
('sarahwilson', 'sarahwilson', 'Wilson', '[email protected]', 'Sarah', NULL),
61+
('miketaylor', 'miketaylor', 'Taylor', '[email protected]', 'Mike', NULL),
62+
('graceadams', 'graceadams', 'Adams', '[email protected]', 'Grace', NULL),
63+
('mattmoore', 'mattmoore', 'Moore', '[email protected]', 'Matt', NULL),
64+
('lilyparker', 'lilyparker', 'Parker', '[email protected]', 'Lily', NULL),
65+
('danieldixon', 'danieldixon', 'Dixon', '[email protected]', 'Daniel', NULL),
66+
('mialopez', 'mialopez', 'Lopez', '[email protected]', 'Mia', NULL),
67+
('ethanjackson', 'ethanjackson', 'Jackson', '[email protected]', 'Ethan', NULL),
68+
('oliviaroberts', 'oliviaroberts', 'Roberts', '[email protected]', 'Olivia', NULL),
69+
('jamessmith', 'jamessmith', 'Smith', '[email protected]', 'James', NULL),
70+
('sophiathomas', 'sophiathomas', 'Thomas', '[email protected]', 'Sophia', NULL),
71+
('benjaminclark', 'benjaminclark', 'Clark', '[email protected]', 'Benjamin', NULL),
72+
('avamartin', 'avamartin', 'Martin', '[email protected]', 'Ava', NULL),
73+
('williamrogers', 'williamrogers', 'Rogers', '[email protected]', 'William', NULL),
74+
('emmawright', 'emmawright', 'Wright', '[email protected]', 'Emma', NULL),
75+
('chloescott', 'chloescott', 'Scott', '[email protected]', 'Chloe', NULL),
76+
('danieltaylor', 'danieltaylor', 'Taylor', '[email protected]', 'Daniel', NULL),
77+
('sophiarichardson', 'sophiarichardson', 'Richardson', '[email protected]', 'Sophia', NULL),
78+
('henryjones', 'henryjones', 'Jones', '[email protected]', 'Henry', NULL),
79+
('gracelewis', 'gracelewis', 'Lewis', '[email protected]', 'Grace', NULL),
80+
('samuelharris', 'samuelharris', 'Harris', '[email protected]', 'Samuel', NULL),
81+
('ameliahall', 'ameliahall', 'Hall', '[email protected]', 'Amelia', NULL),
82+
('lucyedwards', 'lucyedwards', 'Edwards', '[email protected]', 'Lucy', NULL),
83+
('christophermiller', 'christophermiller', 'Miller', '[email protected]', 'Christopher', NULL),
84+
('emilyperez', 'emilyperez', 'Perez', '[email protected]', 'Emily', NULL),
85+
('andrewcook', 'andrewcook', 'Cook', '[email protected]', 'Andrew', NULL),
86+
('oliviaparker', 'oliviaparker', 'Parker', '[email protected]', 'Olivia', NULL),
87+
('josephmartin', 'josephmartin', 'Martin', '[email protected]', 'Joseph', NULL),
88+
('lilybrown', 'lilybrown', 'Brown', '[email protected]', 'Lily', NULL),
89+
('elizabethlee', 'elizabethlee', 'Lee', '[email protected]', 'Elizabeth', NULL),
90+
('ethangreen', 'ethangreen', 'Green', '[email protected]', 'Ethan', NULL),
91+
('noahroberts', 'noahroberts', 'Roberts', '[email protected]', 'Noah', NULL),
92+
('gracegarcia', 'gracegarcia', 'Garcia', '[email protected]', 'Grace', NULL),
93+
('avaclark', 'avaclark', 'Clark', '[email protected]', 'Ava', NULL),
94+
('sophiedavis', 'sophiedavis', 'Davis', '[email protected]', 'Sophie', NULL),
95+
('benjaminharrison', 'benjaminharrison', 'Harrison', '[email protected]', 'Benjamin', NULL);
3096
EOSQL

packages/matrix-identity-server/src/db/sql/pg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ class Pg<T extends string> extends SQL<T> implements IdDbBackend<T> {
333333
values,
334334
(err: any, rows: any) => {
335335
if (rows === undefined) {
336-
resolve([]);
337-
return;
336+
resolve([])
337+
return
338338
}
339339
err ? reject(err) : resolve(rows.rows)
340340
}

0 commit comments

Comments
 (0)