diff --git a/crates/collab/migrations/20220913211150_create_signups.down.sql b/crates/collab/migrations/20220913211150_create_signups.down.sql index 6ef51842c9..14b4e43cea 100644 --- a/crates/collab/migrations/20220913211150_create_signups.down.sql +++ b/crates/collab/migrations/20220913211150_create_signups.down.sql @@ -4,3 +4,5 @@ ALTER TABLE users DROP COLUMN metrics_id; DROP SEQUENCE metrics_id_seq; + +DROP INDEX index_users_on_email_address; \ No newline at end of file diff --git a/crates/collab/migrations/20220913211150_create_signups.up.sql b/crates/collab/migrations/20220913211150_create_signups.up.sql index 9acb313fd6..6c9380275d 100644 --- a/crates/collab/migrations/20220913211150_create_signups.up.sql +++ b/crates/collab/migrations/20220913211150_create_signups.up.sql @@ -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'); diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rs index 1509b15cb2..c89a8ba0fc 100644 --- a/crates/collab/src/db.rs +++ b/crates/collab/src/db.rs @@ -448,9 +448,9 @@ impl Db for PostgresDb { ) -> Result<(UserId, Option)> { let mut tx = self.pool.begin().await?; - let (signup_id, inviting_user_id): (i32, Option) = sqlx::query_as( + let (signup_id, metrics_id, inviting_user_id): (i32, i32, Option) = 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?;