Preserve metrics_id from signup to user record

This commit is contained in:
Max Brunsfeld 2022-09-16 15:45:10 -07:00
parent 3dd8845bd8
commit 963ced1dd8
3 changed files with 10 additions and 4 deletions

View File

@ -4,3 +4,5 @@ ALTER TABLE users
DROP COLUMN metrics_id;
DROP SEQUENCE metrics_id_seq;
DROP INDEX index_users_on_email_address;

View File

@ -25,3 +25,6 @@ CREATE INDEX "index_signups_on_email_confirmation_sent" ON "signups" ("email_con
ALTER TABLE "users"
ADD "metrics_id" INTEGER DEFAULT nextval('metrics_id_seq');
UPDATE users
SET metrics_id = nextval('metrics_id_seq');

View File

@ -448,9 +448,9 @@ impl Db for PostgresDb {
) -> Result<(UserId, Option<UserId>)> {
let mut tx = self.pool.begin().await?;
let (signup_id, inviting_user_id): (i32, Option<UserId>) = sqlx::query_as(
let (signup_id, metrics_id, inviting_user_id): (i32, i32, Option<UserId>) = sqlx::query_as(
"
SELECT id, inviting_user_id
SELECT id, metrics_id, inviting_user_id
FROM signups
WHERE
email_address = $1 AND
@ -467,9 +467,9 @@ impl Db for PostgresDb {
let user_id: UserId = sqlx::query_scalar(
"
INSERT INTO users
(email_address, github_login, admin, invite_count, invite_code)
(email_address, github_login, admin, invite_count, invite_code, metrics_id)
VALUES
($1, $2, 'f', $3, $4)
($1, $2, 'f', $3, $4, $5)
RETURNING id
",
)
@ -477,6 +477,7 @@ impl Db for PostgresDb {
.bind(&user.github_login)
.bind(&user.invite_count)
.bind(random_invite_code())
.bind(metrics_id)
.fetch_one(&mut tx)
.await?;