Skip to content

Commit cb3eee2

Browse files
committed
Update to use new users_user table
1 parent c6138a5 commit cb3eee2

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

core/models/user.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ type User struct {
2323

2424
const sqlSelectUser = `
2525
SELECT row_to_json(r) FROM (
26-
SELECT u.id, u.email, TRIM(CONCAT(u.first_name, ' ', u.last_name)) AS name, s.avatar
27-
FROM auth_user u
28-
INNER JOIN orgs_usersettings s ON s.user_id = u.id
29-
WHERE u.id = $1 AND u.is_active
26+
SELECT id, email, TRIM(CONCAT(u.first_name, ' ', last_name)) AS name, avatar
27+
FROM users_user
28+
WHERE id = $1 AND is_active
3029
) r`
3130

3231
func LoadUser(ctx context.Context, rt *runtime.Runtime, id UserID) (*User, error) {

testsuite/schema.sql

+4-10
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,14 @@ CREATE TABLE contacts_contacturn (
5454
UNIQUE (org_id, identity)
5555
);
5656

57-
DROP TABLE IF EXISTS auth_user CASCADE;
58-
CREATE TABLE auth_user (
57+
DROP TABLE IF EXISTS users_user CASCADE;
58+
CREATE TABLE users_user (
5959
id serial primary key,
6060
email character varying(254) NOT NULL,
6161
first_name character varying(150),
6262
last_name character varying(150),
6363
is_active boolean NOT NULL,
64-
is_staff boolean NOT NULL
65-
);
66-
67-
DROP TABLE IF EXISTS orgs_usersettings CASCADE;
68-
CREATE TABLE orgs_usersettings (
69-
id serial primary key,
70-
user_id integer NOT NULL REFERENCES auth_user(id) ON DELETE CASCADE,
64+
is_staff boolean NOT NULL,
7165
avatar character varying(100) NULL
7266
);
7367

@@ -94,7 +88,7 @@ CREATE TABLE msgs_msg (
9488
broadcast_id integer REFERENCES msgs_broadcast(id) ON DELETE CASCADE,
9589
flow_id integer REFERENCES flows_flow(id) ON DELETE CASCADE,
9690
ticket_id integer REFERENCES tickets_ticket(id) ON DELETE CASCADE,
97-
created_by_id integer REFERENCES auth_user(id) ON DELETE CASCADE,
91+
created_by_id integer REFERENCES users_user(id) ON DELETE CASCADE,
9892
text text NOT NULL,
9993
attachments character varying(255)[] NULL,
10094
quick_replies character varying(64)[] NULL,

testsuite/testdata.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,10 @@ func InsertURN(rt *runtime.Runtime, orgID models.OrgID, contactID models.Contact
7171

7272
func InsertUser(rt *runtime.Runtime, email, firstName, lastName, avatar string) models.UserID {
7373
row := rt.DB.QueryRow(
74-
`INSERT INTO auth_user(email, first_name, last_name, is_active, is_staff)
75-
VALUES($1, $2, $3, TRUE, FALSE) RETURNING id`, email, firstName, lastName,
74+
`INSERT INTO users_user(email, first_name, last_name, is_active, is_staff, avatar)
75+
VALUES($1, $2, $3, TRUE, FALSE, $4) RETURNING id`, email, firstName, lastName, avatar,
7676
)
7777
var id models.UserID
7878
must(row.Scan(&id))
79-
80-
_, err := rt.DB.Exec(`INSERT INTO orgs_usersettings(user_id, avatar) VALUES($1, $2)`, id, avatar)
81-
noError(err)
82-
8379
return id
8480
}

0 commit comments

Comments
 (0)