From 3f308330e5727619a34a7e060cb2980f7a601160 Mon Sep 17 00:00:00 2001 From: David Phan Date: Tue, 7 May 2024 12:05:41 -0700 Subject: [PATCH 01/28] Create new schema with login info tables --- conf/evolutions/default/225.sql | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 conf/evolutions/default/225.sql diff --git a/conf/evolutions/default/225.sql b/conf/evolutions/default/225.sql new file mode 100644 index 0000000000..21f8fdcff2 --- /dev/null +++ b/conf/evolutions/default/225.sql @@ -0,0 +1,58 @@ +# --- !Ups +-- Create Login Schema to unify login systems. +CREATE SCHEMA IF NOT EXISTS sidewalk_login; +ALTER SCHEMA sidewalk_login OWNER TO sidewalk; + +-- TABLE: user_password_info +CREATE TABLE sidewalk_login.user_password_info ( + user_password_info_id SERIAL NOT NULL, + login_info_id bigint NOT NULL, + password VARCHAR(254) NOT NULL, + salt VARCHAR(254), + hasher VARCHAR(254) NOT NULL, + PRIMARY KEY (user_password_info_id) +); +ALTER TABLE sidewalk_login.user_password_info OWNER TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.user_password_info TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.user_password_info TO postgres; + +-- TABLE: login_info +CREATE TABLE sidewalk_login.login_info( + login_info_id bigint SERIAL NOT NULL, + provider_id VARCHAR(254), + provider_key VARCHAR(254), + PRIMARY KEY (login_info_id) +); +ALTER TABLE sidewalk_login.login_info OWNER TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.login_info TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.login_info TO postgres; + +-- TABLE: user_login_info +CREATE TABLE sidewalk_login.user_login_info( + user_login_info_id SERIAL NOT NULL, + login_info_id bigint NOT NULL, + user_id VARCHAR(254) NOT NULL, + PRIMARY KEY (user_login_info_id) +); +CREATE INDEX user_login_info_login_info_id_idx ON sidewalk_login.user_login_info USING btree(login_info_id); +CREATE INDEX user_login_info_user_id_idx ON sidewalk_login.user_login_info USING btree(user_id); +ALTER TABLE sidewalk_login.user_login_info OWNER TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.user_login_info TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.user_login_info TO postgres; + +-- TABLE: sidewalk_user +CREATE TABLE sidewalk_login.sidewalk_user( + user_id TEXT[] UNIQUE NOT NULL, + username TEXT[] UNIQUE NOT NULL, + email TEXT[] NOT NULL, + PRIMARY KEY (user_id) +); +CREATE INDEX user_id_idx ON sidewalk_login.sidewalk_user USING btree(user_id); +CREATE INDEX username_idx ON sidewalk_login.sidewalk_user USING btree(username); +CREATE INDEX email_idx ON sidewalk_login.sidewalk_user USING btree(email); +ALTER TABLE sidewalk_login.sidewalk_user OWNER TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.sidewalk_user TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.sidewalk_user TO postgres; + +# --- !Downs +DROP SCHEMA IF EXISTS sidewalk_login CASCADE; From 9999808e80d7d8dccfd14c23dbcc8e63fbbdc5fe Mon Sep 17 00:00:00 2001 From: David Phan Date: Mon, 3 Jun 2024 11:05:21 -0700 Subject: [PATCH 02/28] New login schema generated, foreign key errors occuring --- .../daos/slick/DBTableDefinitions.scala | 8 +-- conf/evolutions/default/225.sql | 61 +++------------- conf/evolutions/default/226.sql | 72 +++++++++++++++++++ conf/evolutions/default/227.sql | 17 +++++ conf/evolutions/default/228.sql | 37 ++++++++++ 5 files changed, 139 insertions(+), 56 deletions(-) create mode 100644 conf/evolutions/default/226.sql create mode 100644 conf/evolutions/default/227.sql create mode 100644 conf/evolutions/default/228.sql diff --git a/app/models/daos/slick/DBTableDefinitions.scala b/app/models/daos/slick/DBTableDefinitions.scala index 8c197b83bf..42e6d47465 100644 --- a/app/models/daos/slick/DBTableDefinitions.scala +++ b/app/models/daos/slick/DBTableDefinitions.scala @@ -8,7 +8,7 @@ object DBTableDefinitions { case class DBUser (userId: String, username: String, email: String ) - class UserTable(tag: Tag) extends Table[DBUser](tag, "sidewalk_user") { + class UserTable(tag: Tag) extends Table[DBUser](tag, Some("sidewalk_login"), "sidewalk_user") { def userId = column[String]("user_id", O.PrimaryKey) def username = column[String]("username") def email = column[String]("email") @@ -17,7 +17,7 @@ object DBTableDefinitions { case class DBLoginInfo (id: Option[Long], providerID: String, providerKey: String ) - class LoginInfos(tag: Tag) extends Table[DBLoginInfo](tag, "login_info") { + class LoginInfos(tag: Tag) extends Table[DBLoginInfo](tag, Some("sidewalk_login"), "login_info") { def loginInfoId = column[Long]("login_info_id", O.PrimaryKey, O.AutoInc) def providerID = column[String]("provider_id") def providerKey = column[String]("provider_key") @@ -26,7 +26,7 @@ object DBTableDefinitions { case class DBUserLoginInfo (userID: String, loginInfoId: Long) - class UserLoginInfoTable(tag: Tag) extends Table[DBUserLoginInfo](tag, "user_login_info") { + class UserLoginInfoTable(tag: Tag) extends Table[DBUserLoginInfo](tag, Some("sidewalk_login"), "user_login_info") { def userID = column[String]("user_id", O.NotNull) def loginInfoId = column[Long]("login_info_id", O.NotNull) def * = (userID, loginInfoId) <> (DBUserLoginInfo.tupled, DBUserLoginInfo.unapply) @@ -34,7 +34,7 @@ object DBTableDefinitions { case class DBPasswordInfo (hasher: String, password: String, salt: Option[String], loginInfoId: Long) - class PasswordInfoTable(tag: Tag) extends Table[DBPasswordInfo](tag, "user_password_info") { + class PasswordInfoTable(tag: Tag) extends Table[DBPasswordInfo](tag, Some("sidewalk_login"), "user_password_info") { def hasher = column[String]("hasher") def password = column[String]("password") def salt = column[Option[String]]("salt") diff --git a/conf/evolutions/default/225.sql b/conf/evolutions/default/225.sql index 21f8fdcff2..6c2e8584c9 100644 --- a/conf/evolutions/default/225.sql +++ b/conf/evolutions/default/225.sql @@ -1,58 +1,15 @@ -# --- !Ups +-- Create new schema +-- Create tables/indexes in new schema +-- Grant access to all tables/indexes +-- Update sequences for pkeys of all new tables +-- Apply foreign keys to sidewalk_user table + -- Create Login Schema to unify login systems. + +# --- !Ups CREATE SCHEMA IF NOT EXISTS sidewalk_login; ALTER SCHEMA sidewalk_login OWNER TO sidewalk; --- TABLE: user_password_info -CREATE TABLE sidewalk_login.user_password_info ( - user_password_info_id SERIAL NOT NULL, - login_info_id bigint NOT NULL, - password VARCHAR(254) NOT NULL, - salt VARCHAR(254), - hasher VARCHAR(254) NOT NULL, - PRIMARY KEY (user_password_info_id) -); -ALTER TABLE sidewalk_login.user_password_info OWNER TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.user_password_info TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.user_password_info TO postgres; - --- TABLE: login_info -CREATE TABLE sidewalk_login.login_info( - login_info_id bigint SERIAL NOT NULL, - provider_id VARCHAR(254), - provider_key VARCHAR(254), - PRIMARY KEY (login_info_id) -); -ALTER TABLE sidewalk_login.login_info OWNER TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.login_info TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.login_info TO postgres; - --- TABLE: user_login_info -CREATE TABLE sidewalk_login.user_login_info( - user_login_info_id SERIAL NOT NULL, - login_info_id bigint NOT NULL, - user_id VARCHAR(254) NOT NULL, - PRIMARY KEY (user_login_info_id) -); -CREATE INDEX user_login_info_login_info_id_idx ON sidewalk_login.user_login_info USING btree(login_info_id); -CREATE INDEX user_login_info_user_id_idx ON sidewalk_login.user_login_info USING btree(user_id); -ALTER TABLE sidewalk_login.user_login_info OWNER TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.user_login_info TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.user_login_info TO postgres; - --- TABLE: sidewalk_user -CREATE TABLE sidewalk_login.sidewalk_user( - user_id TEXT[] UNIQUE NOT NULL, - username TEXT[] UNIQUE NOT NULL, - email TEXT[] NOT NULL, - PRIMARY KEY (user_id) -); -CREATE INDEX user_id_idx ON sidewalk_login.sidewalk_user USING btree(user_id); -CREATE INDEX username_idx ON sidewalk_login.sidewalk_user USING btree(username); -CREATE INDEX email_idx ON sidewalk_login.sidewalk_user USING btree(email); -ALTER TABLE sidewalk_login.sidewalk_user OWNER TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.sidewalk_user TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.sidewalk_user TO postgres; - # --- !Downs DROP SCHEMA IF EXISTS sidewalk_login CASCADE; + diff --git a/conf/evolutions/default/226.sql b/conf/evolutions/default/226.sql new file mode 100644 index 0000000000..d7ad316fd6 --- /dev/null +++ b/conf/evolutions/default/226.sql @@ -0,0 +1,72 @@ +-- Create tables and indexes for login tables and grant "sidewalk" user access + +# --- !Ups + +-- TABLE: user_password_info +CREATE TABLE sidewalk_login.user_password_info ( + user_password_info_id SERIAL NOT NULL, + login_info_id bigint NOT NULL, + password VARCHAR(254) NOT NULL, + salt VARCHAR(254), + hasher VARCHAR(254) NOT NULL, + PRIMARY KEY (user_password_info_id) +); +ALTER TABLE sidewalk_login.user_password_info OWNER TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.user_password_info TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.user_password_info TO postgres; + +-- TABLE: login_info +CREATE TABLE sidewalk_login.login_info( + login_info_id BIGSERIAL NOT NULL, + provider_id VARCHAR(254), + provider_key VARCHAR(254), + PRIMARY KEY (login_info_id) +); +ALTER TABLE sidewalk_login.login_info OWNER TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.login_info TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.login_info TO postgres; + +-- TABLE: user_login_info +CREATE TABLE sidewalk_login.user_login_info( + user_login_info_id SERIAL NOT NULL, + login_info_id bigint NOT NULL, + user_id VARCHAR(254) NOT NULL, + PRIMARY KEY (user_login_info_id) +); +CREATE INDEX user_login_info_login_info_id_idx ON sidewalk_login.user_login_info USING btree(login_info_id); +CREATE INDEX user_login_info_user_id_idx ON sidewalk_login.user_login_info USING btree(user_id); +ALTER TABLE sidewalk_login.user_login_info OWNER TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.user_login_info TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.user_login_info TO postgres; + +-- TABLE: sidewalk_user +CREATE TABLE sidewalk_login.sidewalk_user( + user_id TEXT UNIQUE NOT NULL, + username TEXT UNIQUE NOT NULL, + email TEXT NOT NULL, + PRIMARY KEY (user_id) +); +CREATE INDEX user_id_idx ON sidewalk_login.sidewalk_user USING btree(user_id); +CREATE INDEX username_idx ON sidewalk_login.sidewalk_user USING btree(username); +CREATE INDEX email_idx ON sidewalk_login.sidewalk_user USING btree(email); +ALTER TABLE sidewalk_login.sidewalk_user OWNER TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.sidewalk_user TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.sidewalk_user TO postgres; + +# --- !Downs +-- TABLE: user_password_info +DROP TABLE IF EXISTS sidewalk_login.user_password_info; + +-- TABLE: login_info +DROP TABLE IF EXISTS sidewalk_login.login_info; + +-- TABLE: user_login_info +DROP TABLE IF EXISTS sidewalk_login.user_login_info; +DROP INDEX IF EXISTS user_login_info_login_info_id_idx; +DROP INDEX IF EXISTS user_login_info_user_id_idx; + +-- TABLE: sidewalk_user +DROP TABLE IF EXISTS sidewalk_login.sidewalk_user; +DROP INDEX IF EXISTS user_id_idx; +DROP INDEX IF EXISTS username_idx; +DROP INDEX IF EXISTS email_idx; diff --git a/conf/evolutions/default/227.sql b/conf/evolutions/default/227.sql new file mode 100644 index 0000000000..fc729dddf7 --- /dev/null +++ b/conf/evolutions/default/227.sql @@ -0,0 +1,17 @@ +-- Move data from city schemas to new login data schema +-- TODO: Copy login data from ALL cities to login schema +-- TODO: Among duplicates across cities, keep data from most recently logged in user. +-- TODO: Update pkey sequence to the end of the data's sequence + +-- Copy all login info from Pittsburgh into the new sidewalk_login schema +INSERT INTO sidewalk_login.sidewalk_user(user_id, username, email) +SELECT user_id, username, email FROM sidewalk_pittsburgh.sidewalk_user; + +INSERT INTO sidewalk_login.login_info(login_info_id, provider_id, provider_key) +SELECT login_info_id, provider_id, provider_key FROM sidewalk_pittsburgh.login_info; + +INSERT INTO sidewalk_login.user_login_info(user_login_info_id, user_id, login_info_id) +SELECT user_login_info_id, user_id, login_info_id FROM sidewalk_pittsburgh.user_login_info; + +INSERT INTO sidewalk_login.user_password_info (user_password_info_id, login_info_id, "password", salt, hasher) +SELECT user_password_info_id, login_info_id, "password", salt, hasher FROM sidewalk_pittsburgh.user_password_info; diff --git a/conf/evolutions/default/228.sql b/conf/evolutions/default/228.sql new file mode 100644 index 0000000000..8417c760ef --- /dev/null +++ b/conf/evolutions/default/228.sql @@ -0,0 +1,37 @@ +-- Add foreign key constraints from city schemas to login schema + +# --- !Ups + +-- Pittsburgh +ALTER TABLE sidewalk_pittsburgh.audit_task DROP CONSTRAINT IF EXISTS audit_task_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.audit_task ADD CONSTRAINT audit_task_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.gallery_task_environment DROP CONSTRAINT IF EXISTS gallery_task_environment_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.gallery_task_environment ADD CONSTRAINT gallery_task_environment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.gallery_task_interaction DROP CONSTRAINT IF EXISTS gallery_task_interaction_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.gallery_task_interaction ADD CONSTRAINT gallery_task_interaction_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.label_history DROP CONSTRAINT IF EXISTS label_history_edited_by_fkey; +ALTER TABLE sidewalk_pittsburgh.label_history ADD CONSTRAINT label_history_edited_by_fkey FOREIGN KEY (edited_by) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.label_validation DROP CONSTRAINT IF EXISTS label_validation_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.label_validation ADD CONSTRAINT label_validation_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.mission DROP CONSTRAINT IF EXISTS mission_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.mission ADD CONSTRAINT mission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.route DROP CONSTRAINT IF EXISTS route_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.route ADD CONSTRAINT route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.user_clustering_session DROP CONSTRAINT IF EXISTS user_clustering_session_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.user_clustering_session ADD CONSTRAINT user_clustering_session_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.user_org DROP CONSTRAINT IF EXISTS user_org_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.user_org ADD CONSTRAINT user_org_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.user_route DROP CONSTRAINT IF EXISTS user_route_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.user_route ADD CONSTRAINT user_route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.user_stat DROP CONSTRAINT IF EXISTS user_stat_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.user_stat ADD CONSTRAINT user_stat_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.user_survey_option_submission DROP CONSTRAINT IF EXISTS user_survey_option_submission_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.user_survey_option_submission ADD CONSTRAINT user_survey_option_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.user_survey_text_submission DROP CONSTRAINT IF EXISTS user_survey_text_submission_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.user_survey_text_submission ADD CONSTRAINT user_survey_text_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.validation_task_comment DROP CONSTRAINT IF EXISTS validation_task_comment_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.validation_task_comment ADD CONSTRAINT validation_task_comment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_pittsburgh.webpage_activity DROP CONSTRAINT IF EXISTS webpage_activity_user_id_fkey; +ALTER TABLE sidewalk_pittsburgh.webpage_activity ADD CONSTRAINT webpage_activity_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); + +# --- !Downs From c7f70c39369b1f8fd3563a3fd971a328292500b6 Mon Sep 17 00:00:00 2001 From: Mikey Saugstad Date: Mon, 23 Sep 2024 13:39:45 -0700 Subject: [PATCH 03/28] moves evolutions file to make merge easier --- conf/evolutions/default/{225.sql => 249.sql} | 0 conf/evolutions/default/{226.sql => 250.sql} | 0 conf/evolutions/default/{227.sql => 251.sql} | 0 conf/evolutions/default/{228.sql => 252.sql} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename conf/evolutions/default/{225.sql => 249.sql} (100%) rename conf/evolutions/default/{226.sql => 250.sql} (100%) rename conf/evolutions/default/{227.sql => 251.sql} (100%) rename conf/evolutions/default/{228.sql => 252.sql} (100%) diff --git a/conf/evolutions/default/225.sql b/conf/evolutions/default/249.sql similarity index 100% rename from conf/evolutions/default/225.sql rename to conf/evolutions/default/249.sql diff --git a/conf/evolutions/default/226.sql b/conf/evolutions/default/250.sql similarity index 100% rename from conf/evolutions/default/226.sql rename to conf/evolutions/default/250.sql diff --git a/conf/evolutions/default/227.sql b/conf/evolutions/default/251.sql similarity index 100% rename from conf/evolutions/default/227.sql rename to conf/evolutions/default/251.sql diff --git a/conf/evolutions/default/228.sql b/conf/evolutions/default/252.sql similarity index 100% rename from conf/evolutions/default/228.sql rename to conf/evolutions/default/252.sql From 4cb912d634161010f4b7a2ee687897a16117e923 Mon Sep 17 00:00:00 2001 From: Mikey Saugstad Date: Mon, 23 Sep 2024 13:58:33 -0700 Subject: [PATCH 04/28] cleans up evolutions for unified login --- conf/evolutions/default/250.sql | 45 ++++++++--------- conf/evolutions/default/251.sql | 19 ++++--- conf/evolutions/default/252.sql | 90 ++++++++++++++++++++++----------- 3 files changed, 95 insertions(+), 59 deletions(-) diff --git a/conf/evolutions/default/250.sql b/conf/evolutions/default/250.sql index d7ad316fd6..b4e5c9b92d 100644 --- a/conf/evolutions/default/250.sql +++ b/conf/evolutions/default/250.sql @@ -1,9 +1,8 @@ --- Create tables and indexes for login tables and grant "sidewalk" user access +-- Create tables and indexes for login tables and grant "sidewalk" user access. # --- !Ups - -- TABLE: user_password_info -CREATE TABLE sidewalk_login.user_password_info ( +CREATE TABLE IF NOT EXISTS sidewalk_login.user_password_info ( user_password_info_id SERIAL NOT NULL, login_info_id bigint NOT NULL, password VARCHAR(254) NOT NULL, @@ -16,7 +15,7 @@ GRANT ALL ON TABLE sidewalk_login.user_password_info TO sidewalk; GRANT ALL ON TABLE sidewalk_login.user_password_info TO postgres; -- TABLE: login_info -CREATE TABLE sidewalk_login.login_info( +CREATE TABLE IF NOT EXISTS sidewalk_login.login_info( login_info_id BIGSERIAL NOT NULL, provider_id VARCHAR(254), provider_key VARCHAR(254), @@ -27,46 +26,46 @@ GRANT ALL ON TABLE sidewalk_login.login_info TO sidewalk; GRANT ALL ON TABLE sidewalk_login.login_info TO postgres; -- TABLE: user_login_info -CREATE TABLE sidewalk_login.user_login_info( +CREATE TABLE IF NOT EXISTS sidewalk_login.user_login_info( user_login_info_id SERIAL NOT NULL, login_info_id bigint NOT NULL, user_id VARCHAR(254) NOT NULL, PRIMARY KEY (user_login_info_id) ); -CREATE INDEX user_login_info_login_info_id_idx ON sidewalk_login.user_login_info USING btree(login_info_id); -CREATE INDEX user_login_info_user_id_idx ON sidewalk_login.user_login_info USING btree(user_id); +CREATE INDEX IF NOT EXISTS user_login_info_login_info_id_idx ON sidewalk_login.user_login_info USING btree(login_info_id); +CREATE INDEX IF NOT EXISTS user_login_info_user_id_idx ON sidewalk_login.user_login_info USING btree(user_id); ALTER TABLE sidewalk_login.user_login_info OWNER TO sidewalk; GRANT ALL ON TABLE sidewalk_login.user_login_info TO sidewalk; GRANT ALL ON TABLE sidewalk_login.user_login_info TO postgres; -- TABLE: sidewalk_user -CREATE TABLE sidewalk_login.sidewalk_user( +CREATE TABLE IF NOT EXISTS sidewalk_login.sidewalk_user( user_id TEXT UNIQUE NOT NULL, username TEXT UNIQUE NOT NULL, email TEXT NOT NULL, PRIMARY KEY (user_id) ); -CREATE INDEX user_id_idx ON sidewalk_login.sidewalk_user USING btree(user_id); -CREATE INDEX username_idx ON sidewalk_login.sidewalk_user USING btree(username); -CREATE INDEX email_idx ON sidewalk_login.sidewalk_user USING btree(email); +CREATE INDEX IF NOT EXISTS user_id_idx ON sidewalk_login.sidewalk_user USING btree(user_id); +CREATE INDEX IF NOT EXISTS username_idx ON sidewalk_login.sidewalk_user USING btree(username); +CREATE INDEX IF NOT EXISTS email_idx ON sidewalk_login.sidewalk_user USING btree(email); ALTER TABLE sidewalk_login.sidewalk_user OWNER TO sidewalk; GRANT ALL ON TABLE sidewalk_login.sidewalk_user TO sidewalk; GRANT ALL ON TABLE sidewalk_login.sidewalk_user TO postgres; # --- !Downs --- TABLE: user_password_info -DROP TABLE IF EXISTS sidewalk_login.user_password_info; - --- TABLE: login_info -DROP TABLE IF EXISTS sidewalk_login.login_info; +-- TABLE: sidewalk_user +DROP INDEX IF EXISTS email_idx; +DROP INDEX IF EXISTS username_idx; +DROP INDEX IF EXISTS user_id_idx; +DROP TABLE IF EXISTS sidewalk_login.sidewalk_user; -- TABLE: user_login_info -DROP TABLE IF EXISTS sidewalk_login.user_login_info; -DROP INDEX IF EXISTS user_login_info_login_info_id_idx; DROP INDEX IF EXISTS user_login_info_user_id_idx; +DROP INDEX IF EXISTS user_login_info_login_info_id_idx; +DROP TABLE IF EXISTS sidewalk_login.user_login_info; --- TABLE: sidewalk_user -DROP TABLE IF EXISTS sidewalk_login.sidewalk_user; -DROP INDEX IF EXISTS user_id_idx; -DROP INDEX IF EXISTS username_idx; -DROP INDEX IF EXISTS email_idx; +-- TABLE: login_info +DROP TABLE IF EXISTS sidewalk_login.login_info; + +-- TABLE: user_password_info +DROP TABLE IF EXISTS sidewalk_login.user_password_info; diff --git a/conf/evolutions/default/251.sql b/conf/evolutions/default/251.sql index fc729dddf7..00ec699d2f 100644 --- a/conf/evolutions/default/251.sql +++ b/conf/evolutions/default/251.sql @@ -1,17 +1,24 @@ --- Move data from city schemas to new login data schema +-- Move data from city schemas to new login data schema. -- TODO: Copy login data from ALL cities to login schema -- TODO: Among duplicates across cities, keep data from most recently logged in user. -- TODO: Update pkey sequence to the end of the data's sequence --- Copy all login info from Pittsburgh into the new sidewalk_login schema +# --- !Ups +-- Copy all login info from Seattle into the new sidewalk_login schema INSERT INTO sidewalk_login.sidewalk_user(user_id, username, email) -SELECT user_id, username, email FROM sidewalk_pittsburgh.sidewalk_user; +SELECT user_id, username, email FROM sidewalk_seattle.sidewalk_user; INSERT INTO sidewalk_login.login_info(login_info_id, provider_id, provider_key) -SELECT login_info_id, provider_id, provider_key FROM sidewalk_pittsburgh.login_info; +SELECT login_info_id, provider_id, provider_key FROM sidewalk_seattle.login_info; INSERT INTO sidewalk_login.user_login_info(user_login_info_id, user_id, login_info_id) -SELECT user_login_info_id, user_id, login_info_id FROM sidewalk_pittsburgh.user_login_info; +SELECT user_login_info_id, user_id, login_info_id FROM sidewalk_seattle.user_login_info; INSERT INTO sidewalk_login.user_password_info (user_password_info_id, login_info_id, "password", salt, hasher) -SELECT user_password_info_id, login_info_id, "password", salt, hasher FROM sidewalk_pittsburgh.user_password_info; +SELECT user_password_info_id, login_info_id, "password", salt, hasher FROM sidewalk_seattle.user_password_info; + +# --- !Downs +TRUNCATE sidewalk_login.user_password_info; +TRUNCATE sidewalk_login.user_login_info; +TRUNCATE sidewalk_login.login_info; +TRUNCATE sidewalk_login.sidewalk_user; diff --git a/conf/evolutions/default/252.sql b/conf/evolutions/default/252.sql index 8417c760ef..9e4728733c 100644 --- a/conf/evolutions/default/252.sql +++ b/conf/evolutions/default/252.sql @@ -3,35 +3,65 @@ # --- !Ups -- Pittsburgh -ALTER TABLE sidewalk_pittsburgh.audit_task DROP CONSTRAINT IF EXISTS audit_task_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.audit_task ADD CONSTRAINT audit_task_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.gallery_task_environment DROP CONSTRAINT IF EXISTS gallery_task_environment_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.gallery_task_environment ADD CONSTRAINT gallery_task_environment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.gallery_task_interaction DROP CONSTRAINT IF EXISTS gallery_task_interaction_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.gallery_task_interaction ADD CONSTRAINT gallery_task_interaction_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.label_history DROP CONSTRAINT IF EXISTS label_history_edited_by_fkey; -ALTER TABLE sidewalk_pittsburgh.label_history ADD CONSTRAINT label_history_edited_by_fkey FOREIGN KEY (edited_by) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.label_validation DROP CONSTRAINT IF EXISTS label_validation_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.label_validation ADD CONSTRAINT label_validation_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.mission DROP CONSTRAINT IF EXISTS mission_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.mission ADD CONSTRAINT mission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.route DROP CONSTRAINT IF EXISTS route_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.route ADD CONSTRAINT route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.user_clustering_session DROP CONSTRAINT IF EXISTS user_clustering_session_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.user_clustering_session ADD CONSTRAINT user_clustering_session_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.user_org DROP CONSTRAINT IF EXISTS user_org_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.user_org ADD CONSTRAINT user_org_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.user_route DROP CONSTRAINT IF EXISTS user_route_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.user_route ADD CONSTRAINT user_route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.user_stat DROP CONSTRAINT IF EXISTS user_stat_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.user_stat ADD CONSTRAINT user_stat_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.user_survey_option_submission DROP CONSTRAINT IF EXISTS user_survey_option_submission_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.user_survey_option_submission ADD CONSTRAINT user_survey_option_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.user_survey_text_submission DROP CONSTRAINT IF EXISTS user_survey_text_submission_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.user_survey_text_submission ADD CONSTRAINT user_survey_text_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.validation_task_comment DROP CONSTRAINT IF EXISTS validation_task_comment_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.validation_task_comment ADD CONSTRAINT validation_task_comment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_pittsburgh.webpage_activity DROP CONSTRAINT IF EXISTS webpage_activity_user_id_fkey; -ALTER TABLE sidewalk_pittsburgh.webpage_activity ADD CONSTRAINT webpage_activity_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.audit_task DROP CONSTRAINT IF EXISTS audit_task_user_id_fkey; +ALTER TABLE sidewalk_seattle.audit_task ADD CONSTRAINT audit_task_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.gallery_task_environment DROP CONSTRAINT IF EXISTS gallery_task_environment_user_id_fkey; +ALTER TABLE sidewalk_seattle.gallery_task_environment ADD CONSTRAINT gallery_task_environment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.gallery_task_interaction DROP CONSTRAINT IF EXISTS gallery_task_interaction_user_id_fkey; +ALTER TABLE sidewalk_seattle.gallery_task_interaction ADD CONSTRAINT gallery_task_interaction_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.label_history DROP CONSTRAINT IF EXISTS label_history_edited_by_fkey; +ALTER TABLE sidewalk_seattle.label_history ADD CONSTRAINT label_history_edited_by_fkey FOREIGN KEY (edited_by) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.label_validation DROP CONSTRAINT IF EXISTS label_validation_user_id_fkey; +ALTER TABLE sidewalk_seattle.label_validation ADD CONSTRAINT label_validation_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.mission DROP CONSTRAINT IF EXISTS mission_user_id_fkey; +ALTER TABLE sidewalk_seattle.mission ADD CONSTRAINT mission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.route DROP CONSTRAINT IF EXISTS route_user_id_fkey; +ALTER TABLE sidewalk_seattle.route ADD CONSTRAINT route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_clustering_session DROP CONSTRAINT IF EXISTS user_clustering_session_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_clustering_session ADD CONSTRAINT user_clustering_session_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_org DROP CONSTRAINT IF EXISTS user_org_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_org ADD CONSTRAINT user_org_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_route DROP CONSTRAINT IF EXISTS user_route_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_route ADD CONSTRAINT user_route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_stat DROP CONSTRAINT IF EXISTS user_stat_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_stat ADD CONSTRAINT user_stat_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_survey_option_submission DROP CONSTRAINT IF EXISTS user_survey_option_submission_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_survey_option_submission ADD CONSTRAINT user_survey_option_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_survey_text_submission DROP CONSTRAINT IF EXISTS user_survey_text_submission_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_survey_text_submission ADD CONSTRAINT user_survey_text_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.validation_task_comment DROP CONSTRAINT IF EXISTS validation_task_comment_user_id_fkey; +ALTER TABLE sidewalk_seattle.validation_task_comment ADD CONSTRAINT validation_task_comment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.webpage_activity DROP CONSTRAINT IF EXISTS webpage_activity_user_id_fkey; +ALTER TABLE sidewalk_seattle.webpage_activity ADD CONSTRAINT webpage_activity_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); # --- !Downs +ALTER TABLE sidewalk_seattle.webpage_activity DROP CONSTRAINT IF EXISTS webpage_activity_user_id_fkey; +ALTER TABLE sidewalk_seattle.webpage_activity ADD CONSTRAINT webpage_activity_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.validation_task_comment DROP CONSTRAINT IF EXISTS validation_task_comment_user_id_fkey; +ALTER TABLE sidewalk_seattle.validation_task_comment ADD CONSTRAINT validation_task_comment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_survey_text_submission DROP CONSTRAINT IF EXISTS user_survey_text_submission_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_survey_text_submission ADD CONSTRAINT user_survey_text_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_survey_option_submission DROP CONSTRAINT IF EXISTS user_survey_option_submission_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_survey_option_submission ADD CONSTRAINT user_survey_option_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_stat DROP CONSTRAINT IF EXISTS user_stat_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_stat ADD CONSTRAINT user_stat_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_route DROP CONSTRAINT IF EXISTS user_route_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_route ADD CONSTRAINT user_route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_org DROP CONSTRAINT IF EXISTS user_org_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_org ADD CONSTRAINT user_org_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_clustering_session DROP CONSTRAINT IF EXISTS user_clustering_session_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_clustering_session ADD CONSTRAINT user_clustering_session_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.route DROP CONSTRAINT IF EXISTS route_user_id_fkey; +ALTER TABLE sidewalk_seattle.route ADD CONSTRAINT route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.mission DROP CONSTRAINT IF EXISTS mission_user_id_fkey; +ALTER TABLE sidewalk_seattle.mission ADD CONSTRAINT mission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.label_validation DROP CONSTRAINT IF EXISTS label_validation_user_id_fkey; +ALTER TABLE sidewalk_seattle.label_validation ADD CONSTRAINT label_validation_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.label_history DROP CONSTRAINT IF EXISTS label_history_edited_by_fkey; +ALTER TABLE sidewalk_seattle.label_history ADD CONSTRAINT label_history_edited_by_fkey FOREIGN KEY (edited_by) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.gallery_task_interaction DROP CONSTRAINT IF EXISTS gallery_task_interaction_user_id_fkey; +ALTER TABLE sidewalk_seattle.gallery_task_interaction ADD CONSTRAINT gallery_task_interaction_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.gallery_task_environment DROP CONSTRAINT IF EXISTS gallery_task_environment_user_id_fkey; +ALTER TABLE sidewalk_seattle.gallery_task_environment ADD CONSTRAINT gallery_task_environment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.audit_task DROP CONSTRAINT IF EXISTS audit_task_user_id_fkey; +ALTER TABLE sidewalk_seattle.audit_task ADD CONSTRAINT audit_task_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); From 7033fdf83f62f133c83f1bef83ac03c089e9238d Mon Sep 17 00:00:00 2001 From: Mikey Saugstad Date: Mon, 23 Sep 2024 14:10:50 -0700 Subject: [PATCH 05/28] raw SQL now references new sidewalk_login schema --- app/models/daos/slick/UserDAOSlick.scala | 8 ++++---- app/models/label/LabelTable.scala | 2 +- app/models/user/UserStatTable.scala | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/daos/slick/UserDAOSlick.scala b/app/models/daos/slick/UserDAOSlick.scala index a7f1c8e9cc..01c37ae1ef 100644 --- a/app/models/daos/slick/UserDAOSlick.scala +++ b/app/models/daos/slick/UserDAOSlick.scala @@ -285,7 +285,7 @@ object UserDAOSlick { val countQuery = Q.query[String, Int]( """SELECT COUNT(DISTINCT(label_validation.user_id)) |FROM label_validation - |INNER JOIN sidewalk_user ON sidewalk_user.user_id = label_validation.user_id + |INNER JOIN sidewalk_login.sidewalk_user ON sidewalk_user.user_id = label_validation.user_id |INNER JOIN user_role ON sidewalk_user.user_id = user_role.user_id |INNER JOIN role ON user_role.role_id = role.role_id |WHERE (label_validation.end_timestamp AT TIME ZONE 'US/Pacific')::date = (NOW() AT TIME ZONE 'US/Pacific')::date @@ -323,7 +323,7 @@ object UserDAOSlick { val countQuery = Q.query[String, Int]( """SELECT COUNT(DISTINCT(label_validation.user_id)) |FROM label_validation - |INNER JOIN sidewalk_user ON sidewalk_user.user_id = label_validation.user_id + |INNER JOIN sidewalk_login.sidewalk_user ON sidewalk_user.user_id = label_validation.user_id |INNER JOIN user_role ON sidewalk_user.user_id = user_role.user_id |INNER JOIN role ON user_role.role_id = role.role_id |WHERE (label_validation.end_timestamp AT TIME ZONE 'US/Pacific') > (NOW() AT TIME ZONE 'US/Pacific') - interval '168 hours' @@ -397,7 +397,7 @@ object UserDAOSlick { val countQuery = Q.query[String, Int]( """SELECT COUNT(DISTINCT(audit_task.user_id)) |FROM audit_task - |INNER JOIN sidewalk_user ON sidewalk_user.user_id = audit_task.user_id + |INNER JOIN sidewalk_login.sidewalk_user ON sidewalk_user.user_id = audit_task.user_id |INNER JOIN user_role ON sidewalk_user.user_id = user_role.user_id |INNER JOIN role ON user_role.role_id = role.role_id |WHERE (audit_task.task_end AT TIME ZONE 'US/Pacific')::date = (NOW() AT TIME ZONE 'US/Pacific')::date @@ -436,7 +436,7 @@ object UserDAOSlick { val countQuery = Q.query[String, Int]( """SELECT COUNT(DISTINCT(audit_task.user_id)) |FROM audit_task - |INNER JOIN sidewalk_user ON sidewalk_user.user_id = audit_task.user_id + |INNER JOIN sidewalk_login.sidewalk_user ON sidewalk_user.user_id = audit_task.user_id |INNER JOIN user_role ON sidewalk_user.user_id = user_role.user_id |INNER JOIN role ON user_role.role_id = role.role_id |WHERE (audit_task.task_end AT TIME ZONE 'US/Pacific') > (now() AT TIME ZONE 'US/Pacific') - interval '168 hours' diff --git a/app/models/label/LabelTable.scala b/app/models/label/LabelTable.scala index f24b19de4e..b1eaca9d4e 100644 --- a/app/models/label/LabelTable.scala +++ b/app/models/label/LabelTable.scala @@ -544,7 +544,7 @@ object LabelTable { |INNER JOIN gsv_data ON lb1.gsv_panorama_id = gsv_data.gsv_panorama_id |INNER JOIN audit_task AS at ON lb1.audit_task_id = at.audit_task_id |INNER JOIN street_edge_region AS ser ON lb1.street_edge_id = ser.street_edge_id - |INNER JOIN sidewalk_user AS u ON at.user_id = u.user_id + |INNER JOIN sidewalk_login.sidewalk_user AS u ON at.user_id = u.user_id |INNER JOIN label_point AS lp ON lb1.label_id = lp.label_id |INNER JOIN ( | SELECT lb.label_id, diff --git a/app/models/user/UserStatTable.scala b/app/models/user/UserStatTable.scala index 26c4365334..32ec5fb4cb 100644 --- a/app/models/user/UserStatTable.scala +++ b/app/models/user/UserStatTable.scala @@ -317,7 +317,7 @@ object UserStatTable { if (byOrg) { "INNER JOIN (SELECT org_id, org_name AS username FROM organization) \"usernames\" ON label_counts.org_id = usernames.org_id" } else { - "INNER JOIN (SELECT user_id, username FROM sidewalk_user) \"usernames\" ON label_counts.user_id = usernames.user_id" + "INNER JOIN (SELECT user_id, username FROM sidewalk_login.sidewalk_user) \"usernames\" ON label_counts.user_id = usernames.user_id" } } val statsQuery = Q.queryNA[(String, Int, Int, Float, Option[Float], Float)]( @@ -332,7 +332,7 @@ object UserStatTable { | END AS score |FROM ( | SELECT $groupingCol, COUNT(label_id) AS label_count - | FROM sidewalk_user + | FROM sidewalk_login.sidewalk_user | INNER JOIN user_role ON sidewalk_user.user_id = user_role.user_id | INNER JOIN role ON user_role.role_id = role.role_id | INNER JOIN user_stat ON sidewalk_user.user_id = user_stat.user_id @@ -352,7 +352,7 @@ object UserStatTable { |INNER JOIN ( | SELECT $groupingCol, COUNT(mission_id) AS mission_count | FROM mission - | INNER JOIN sidewalk_user ON mission.user_id = sidewalk_user.user_id + | INNER JOIN sidewalk_login.sidewalk_user ON mission.user_id = sidewalk_user.user_id | $joinUserOrgTable | WHERE (mission_end AT TIME ZONE 'US/Pacific') > $statStartTime | GROUP BY $groupingCol @@ -361,7 +361,7 @@ object UserStatTable { | SELECT $groupingCol, COALESCE(SUM(ST_LENGTH(ST_TRANSFORM(geom, 26918))), 0) AS distance_meters | FROM street_edge | INNER JOIN audit_task ON street_edge.street_edge_id = audit_task.street_edge_id - | INNER JOIN sidewalk_user ON audit_task.user_id = sidewalk_user.user_id + | INNER JOIN sidewalk_login.sidewalk_user ON audit_task.user_id = sidewalk_user.user_id | $joinUserOrgTable | WHERE audit_task.completed | AND (task_end AT TIME ZONE 'US/Pacific') > $statStartTime From d8d9835cf8fd1bb6be098c6c9100fdeee7cf45a3 Mon Sep 17 00:00:00 2001 From: Mikey Saugstad Date: Mon, 23 Sep 2024 14:22:00 -0700 Subject: [PATCH 06/28] primary key sequences now set correctly in sidewalk_login schema --- conf/evolutions/default/251.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conf/evolutions/default/251.sql b/conf/evolutions/default/251.sql index 00ec699d2f..c5c5312bab 100644 --- a/conf/evolutions/default/251.sql +++ b/conf/evolutions/default/251.sql @@ -10,12 +10,15 @@ SELECT user_id, username, email FROM sidewalk_seattle.sidewalk_user; INSERT INTO sidewalk_login.login_info(login_info_id, provider_id, provider_key) SELECT login_info_id, provider_id, provider_key FROM sidewalk_seattle.login_info; +SELECT setval('sidewalk_login.login_info_login_info_id_seq', (SELECT MAX(login_info_id) FROM sidewalk_login.login_info)); INSERT INTO sidewalk_login.user_login_info(user_login_info_id, user_id, login_info_id) SELECT user_login_info_id, user_id, login_info_id FROM sidewalk_seattle.user_login_info; +SELECT setval('sidewalk_login.user_login_info_user_login_info_id_seq', (SELECT MAX(user_login_info_id) FROM sidewalk_login.user_login_info)); INSERT INTO sidewalk_login.user_password_info (user_password_info_id, login_info_id, "password", salt, hasher) SELECT user_password_info_id, login_info_id, "password", salt, hasher FROM sidewalk_seattle.user_password_info; +SELECT setval('sidewalk_login.user_password_info_user_password_info_id_seq', (SELECT MAX(user_password_info_id) FROM sidewalk_login.user_password_info)); # --- !Downs TRUNCATE sidewalk_login.user_password_info; From 91ae8ca9c0510cfd3ff83f060d06bab9ccbdc8ac Mon Sep 17 00:00:00 2001 From: Mikey Saugstad Date: Mon, 23 Sep 2024 16:05:43 -0700 Subject: [PATCH 07/28] restructures unified login evolutions to fix foreign key issues --- conf/evolutions/default/251.sql | 86 +++++++++++++++++++++++++++++++++ conf/evolutions/default/252.sql | 67 ------------------------- 2 files changed, 86 insertions(+), 67 deletions(-) delete mode 100644 conf/evolutions/default/252.sql diff --git a/conf/evolutions/default/251.sql b/conf/evolutions/default/251.sql index c5c5312bab..82ac08b896 100644 --- a/conf/evolutions/default/251.sql +++ b/conf/evolutions/default/251.sql @@ -20,7 +20,93 @@ INSERT INTO sidewalk_login.user_password_info (user_password_info_id, login_info SELECT user_password_info_id, login_info_id, "password", salt, hasher FROM sidewalk_seattle.user_password_info; SELECT setval('sidewalk_login.user_password_info_user_password_info_id_seq', (SELECT MAX(user_password_info_id) FROM sidewalk_login.user_password_info)); +-- Move constraints over to the new schema. +ALTER TABLE sidewalk_seattle.audit_task DROP CONSTRAINT IF EXISTS audit_task_user_id_fkey; +ALTER TABLE sidewalk_seattle.audit_task ADD CONSTRAINT audit_task_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.gallery_task_environment DROP CONSTRAINT IF EXISTS gallery_task_environment_user_id_fkey; +ALTER TABLE sidewalk_seattle.gallery_task_environment ADD CONSTRAINT gallery_task_environment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.gallery_task_interaction DROP CONSTRAINT IF EXISTS gallery_task_interaction_user_id_fkey; +ALTER TABLE sidewalk_seattle.gallery_task_interaction ADD CONSTRAINT gallery_task_interaction_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.label_history DROP CONSTRAINT IF EXISTS label_history_edited_by_fkey; +ALTER TABLE sidewalk_seattle.label_history ADD CONSTRAINT label_history_edited_by_fkey FOREIGN KEY (edited_by) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.label_validation DROP CONSTRAINT IF EXISTS label_validation_user_id_fkey; +ALTER TABLE sidewalk_seattle.label_validation ADD CONSTRAINT label_validation_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.mission DROP CONSTRAINT IF EXISTS mission_user_id_fkey; +ALTER TABLE sidewalk_seattle.mission ADD CONSTRAINT mission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.route DROP CONSTRAINT IF EXISTS route_user_id_fkey; +ALTER TABLE sidewalk_seattle.route ADD CONSTRAINT route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_clustering_session DROP CONSTRAINT IF EXISTS user_clustering_session_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_clustering_session ADD CONSTRAINT user_clustering_session_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_org DROP CONSTRAINT IF EXISTS user_org_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_org ADD CONSTRAINT user_org_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_route DROP CONSTRAINT IF EXISTS user_route_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_route ADD CONSTRAINT user_route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_stat DROP CONSTRAINT IF EXISTS user_stat_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_stat ADD CONSTRAINT user_stat_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_survey_option_submission DROP CONSTRAINT IF EXISTS user_survey_option_submission_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_survey_option_submission ADD CONSTRAINT user_survey_option_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_survey_text_submission DROP CONSTRAINT IF EXISTS user_survey_text_submission_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_survey_text_submission ADD CONSTRAINT user_survey_text_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.validation_task_comment DROP CONSTRAINT IF EXISTS validation_task_comment_user_id_fkey; +ALTER TABLE sidewalk_seattle.validation_task_comment ADD CONSTRAINT validation_task_comment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.webpage_activity DROP CONSTRAINT IF EXISTS webpage_activity_user_id_fkey; +ALTER TABLE sidewalk_seattle.webpage_activity ADD CONSTRAINT webpage_activity_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); + +TRUNCATE sidewalk_seattle.sidewalk_user; +TRUNCATE sidewalk_seattle.login_info; +TRUNCATE sidewalk_seattle.user_login_info; +TRUNCATE sidewalk_seattle.user_password_info; + # --- !Downs +-- Copy all login info from sidewalk_login back into the Seattle schema. +INSERT INTO sidewalk_seattle.sidewalk_user(user_id, username, email) +SELECT user_id, username, email FROM sidewalk_login.sidewalk_user; + +INSERT INTO sidewalk_seattle.login_info(login_info_id, provider_id, provider_key) +SELECT login_info_id, provider_id, provider_key FROM sidewalk_login.login_info; +SELECT setval('sidewalk_seattle.logininfo_id_seq', (SELECT MAX(login_info_id) FROM sidewalk_seattle.login_info)); + +INSERT INTO sidewalk_seattle.user_login_info(user_login_info_id, user_id, login_info_id) +SELECT user_login_info_id, user_id, login_info_id FROM sidewalk_login.user_login_info; +-- SELECT setval('sidewalk_seattle.user_login_info_user_login_info_id_seq', (SELECT MAX(user_login_info_id) FROM sidewalk_seattle.user_login_info)); + +INSERT INTO sidewalk_seattle.user_password_info (user_password_info_id, login_info_id, "password", salt, hasher) +SELECT user_password_info_id, login_info_id, "password", salt, hasher FROM sidewalk_login.user_password_info; +-- SELECT setval('sidewalk_seattle.user_password_info_user_password_info_id_seq', (SELECT MAX(user_password_info_id) FROM sidewalk_seattle.user_password_info)); + +-- Move the constraints back to the Seattle schema. +ALTER TABLE sidewalk_seattle.webpage_activity DROP CONSTRAINT IF EXISTS webpage_activity_user_id_fkey; +ALTER TABLE sidewalk_seattle.webpage_activity ADD CONSTRAINT webpage_activity_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.validation_task_comment DROP CONSTRAINT IF EXISTS validation_task_comment_user_id_fkey; +ALTER TABLE sidewalk_seattle.validation_task_comment ADD CONSTRAINT validation_task_comment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_survey_text_submission DROP CONSTRAINT IF EXISTS user_survey_text_submission_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_survey_text_submission ADD CONSTRAINT user_survey_text_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_survey_option_submission DROP CONSTRAINT IF EXISTS user_survey_option_submission_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_survey_option_submission ADD CONSTRAINT user_survey_option_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_stat DROP CONSTRAINT IF EXISTS user_stat_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_stat ADD CONSTRAINT user_stat_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_route DROP CONSTRAINT IF EXISTS user_route_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_route ADD CONSTRAINT user_route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_org DROP CONSTRAINT IF EXISTS user_org_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_org ADD CONSTRAINT user_org_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.user_clustering_session DROP CONSTRAINT IF EXISTS user_clustering_session_user_id_fkey; +ALTER TABLE sidewalk_seattle.user_clustering_session ADD CONSTRAINT user_clustering_session_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.route DROP CONSTRAINT IF EXISTS route_user_id_fkey; +ALTER TABLE sidewalk_seattle.route ADD CONSTRAINT route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.mission DROP CONSTRAINT IF EXISTS mission_user_id_fkey; +ALTER TABLE sidewalk_seattle.mission ADD CONSTRAINT mission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.label_validation DROP CONSTRAINT IF EXISTS label_validation_user_id_fkey; +ALTER TABLE sidewalk_seattle.label_validation ADD CONSTRAINT label_validation_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.label_history DROP CONSTRAINT IF EXISTS label_history_edited_by_fkey; +ALTER TABLE sidewalk_seattle.label_history ADD CONSTRAINT label_history_edited_by_fkey FOREIGN KEY (edited_by) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.gallery_task_interaction DROP CONSTRAINT IF EXISTS gallery_task_interaction_user_id_fkey; +ALTER TABLE sidewalk_seattle.gallery_task_interaction ADD CONSTRAINT gallery_task_interaction_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.gallery_task_environment DROP CONSTRAINT IF EXISTS gallery_task_environment_user_id_fkey; +ALTER TABLE sidewalk_seattle.gallery_task_environment ADD CONSTRAINT gallery_task_environment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); +ALTER TABLE sidewalk_seattle.audit_task DROP CONSTRAINT IF EXISTS audit_task_user_id_fkey; +ALTER TABLE sidewalk_seattle.audit_task ADD CONSTRAINT audit_task_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); + +-- Truncate the tables in the sidewalk_login schema. TRUNCATE sidewalk_login.user_password_info; TRUNCATE sidewalk_login.user_login_info; TRUNCATE sidewalk_login.login_info; diff --git a/conf/evolutions/default/252.sql b/conf/evolutions/default/252.sql deleted file mode 100644 index 9e4728733c..0000000000 --- a/conf/evolutions/default/252.sql +++ /dev/null @@ -1,67 +0,0 @@ --- Add foreign key constraints from city schemas to login schema - -# --- !Ups - --- Pittsburgh -ALTER TABLE sidewalk_seattle.audit_task DROP CONSTRAINT IF EXISTS audit_task_user_id_fkey; -ALTER TABLE sidewalk_seattle.audit_task ADD CONSTRAINT audit_task_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.gallery_task_environment DROP CONSTRAINT IF EXISTS gallery_task_environment_user_id_fkey; -ALTER TABLE sidewalk_seattle.gallery_task_environment ADD CONSTRAINT gallery_task_environment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.gallery_task_interaction DROP CONSTRAINT IF EXISTS gallery_task_interaction_user_id_fkey; -ALTER TABLE sidewalk_seattle.gallery_task_interaction ADD CONSTRAINT gallery_task_interaction_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.label_history DROP CONSTRAINT IF EXISTS label_history_edited_by_fkey; -ALTER TABLE sidewalk_seattle.label_history ADD CONSTRAINT label_history_edited_by_fkey FOREIGN KEY (edited_by) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.label_validation DROP CONSTRAINT IF EXISTS label_validation_user_id_fkey; -ALTER TABLE sidewalk_seattle.label_validation ADD CONSTRAINT label_validation_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.mission DROP CONSTRAINT IF EXISTS mission_user_id_fkey; -ALTER TABLE sidewalk_seattle.mission ADD CONSTRAINT mission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.route DROP CONSTRAINT IF EXISTS route_user_id_fkey; -ALTER TABLE sidewalk_seattle.route ADD CONSTRAINT route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_clustering_session DROP CONSTRAINT IF EXISTS user_clustering_session_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_clustering_session ADD CONSTRAINT user_clustering_session_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_org DROP CONSTRAINT IF EXISTS user_org_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_org ADD CONSTRAINT user_org_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_route DROP CONSTRAINT IF EXISTS user_route_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_route ADD CONSTRAINT user_route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_stat DROP CONSTRAINT IF EXISTS user_stat_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_stat ADD CONSTRAINT user_stat_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_survey_option_submission DROP CONSTRAINT IF EXISTS user_survey_option_submission_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_survey_option_submission ADD CONSTRAINT user_survey_option_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_survey_text_submission DROP CONSTRAINT IF EXISTS user_survey_text_submission_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_survey_text_submission ADD CONSTRAINT user_survey_text_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.validation_task_comment DROP CONSTRAINT IF EXISTS validation_task_comment_user_id_fkey; -ALTER TABLE sidewalk_seattle.validation_task_comment ADD CONSTRAINT validation_task_comment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.webpage_activity DROP CONSTRAINT IF EXISTS webpage_activity_user_id_fkey; -ALTER TABLE sidewalk_seattle.webpage_activity ADD CONSTRAINT webpage_activity_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); - -# --- !Downs -ALTER TABLE sidewalk_seattle.webpage_activity DROP CONSTRAINT IF EXISTS webpage_activity_user_id_fkey; -ALTER TABLE sidewalk_seattle.webpage_activity ADD CONSTRAINT webpage_activity_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.validation_task_comment DROP CONSTRAINT IF EXISTS validation_task_comment_user_id_fkey; -ALTER TABLE sidewalk_seattle.validation_task_comment ADD CONSTRAINT validation_task_comment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_survey_text_submission DROP CONSTRAINT IF EXISTS user_survey_text_submission_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_survey_text_submission ADD CONSTRAINT user_survey_text_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_survey_option_submission DROP CONSTRAINT IF EXISTS user_survey_option_submission_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_survey_option_submission ADD CONSTRAINT user_survey_option_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_stat DROP CONSTRAINT IF EXISTS user_stat_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_stat ADD CONSTRAINT user_stat_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_route DROP CONSTRAINT IF EXISTS user_route_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_route ADD CONSTRAINT user_route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_org DROP CONSTRAINT IF EXISTS user_org_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_org ADD CONSTRAINT user_org_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_clustering_session DROP CONSTRAINT IF EXISTS user_clustering_session_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_clustering_session ADD CONSTRAINT user_clustering_session_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.route DROP CONSTRAINT IF EXISTS route_user_id_fkey; -ALTER TABLE sidewalk_seattle.route ADD CONSTRAINT route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.mission DROP CONSTRAINT IF EXISTS mission_user_id_fkey; -ALTER TABLE sidewalk_seattle.mission ADD CONSTRAINT mission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.label_validation DROP CONSTRAINT IF EXISTS label_validation_user_id_fkey; -ALTER TABLE sidewalk_seattle.label_validation ADD CONSTRAINT label_validation_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.label_history DROP CONSTRAINT IF EXISTS label_history_edited_by_fkey; -ALTER TABLE sidewalk_seattle.label_history ADD CONSTRAINT label_history_edited_by_fkey FOREIGN KEY (edited_by) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.gallery_task_interaction DROP CONSTRAINT IF EXISTS gallery_task_interaction_user_id_fkey; -ALTER TABLE sidewalk_seattle.gallery_task_interaction ADD CONSTRAINT gallery_task_interaction_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.gallery_task_environment DROP CONSTRAINT IF EXISTS gallery_task_environment_user_id_fkey; -ALTER TABLE sidewalk_seattle.gallery_task_environment ADD CONSTRAINT gallery_task_environment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.audit_task DROP CONSTRAINT IF EXISTS audit_task_user_id_fkey; -ALTER TABLE sidewalk_seattle.audit_task ADD CONSTRAINT audit_task_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); From b8c8debe46054e80b0de88a974c513d1f4e5c588 Mon Sep 17 00:00:00 2001 From: Mikey Saugstad Date: Thu, 3 Oct 2024 11:32:47 -0700 Subject: [PATCH 08/28] moves password resets to unified login schema --- app/models/daos/slick/DBTableDefinitions.scala | 2 +- app/utils/actor/AuthTokenCleanerActor.scala | 1 + conf/evolutions/default/250.sql | 13 +++++++++++++ conf/evolutions/default/251.sql | 2 ++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/daos/slick/DBTableDefinitions.scala b/app/models/daos/slick/DBTableDefinitions.scala index 42e6d47465..680abcd315 100644 --- a/app/models/daos/slick/DBTableDefinitions.scala +++ b/app/models/daos/slick/DBTableDefinitions.scala @@ -44,7 +44,7 @@ object DBTableDefinitions { case class DBAuthToken (id: Array[Byte], userID: String, expirationTimestamp: Timestamp) - class AuthTokenTable(tag: Tag) extends Table[DBAuthToken](tag, "auth_tokens") { + class AuthTokenTable(tag: Tag) extends Table[DBAuthToken](tag, Some("sidewalk_login"), "auth_tokens") { def id = column[Array[Byte]]("id") def userID = column[String]("user_id", O.PrimaryKey) def expirationTimestamp = column[Timestamp]("expiration_timestamp") diff --git a/app/utils/actor/AuthTokenCleanerActor.scala b/app/utils/actor/AuthTokenCleanerActor.scala index 3f89790ab4..15831170f8 100644 --- a/app/utils/actor/AuthTokenCleanerActor.scala +++ b/app/utils/actor/AuthTokenCleanerActor.scala @@ -38,6 +38,7 @@ class AuthTokenCleanerActor extends Actor { val durationToNextUpdate: FiniteDuration = FiniteDuration(millisUntilNextUpdate, MILLISECONDS) // Run auth token cleaner every 24 hours + // TODO this is being run in every city, even though all cities are pointing to the same table. cancellable = Some( context.system.scheduler.schedule( durationToNextUpdate, diff --git a/conf/evolutions/default/250.sql b/conf/evolutions/default/250.sql index b4e5c9b92d..6b88ed35c9 100644 --- a/conf/evolutions/default/250.sql +++ b/conf/evolutions/default/250.sql @@ -52,7 +52,20 @@ ALTER TABLE sidewalk_login.sidewalk_user OWNER TO sidewalk; GRANT ALL ON TABLE sidewalk_login.sidewalk_user TO sidewalk; GRANT ALL ON TABLE sidewalk_login.sidewalk_user TO postgres; +-- TABLE: auth_tokens +CREATE TABLE sidewalk_login.auth_tokens ( + user_id character varying(254) NOT NULL, + id bytea NOT NULL, + expiration_timestamp TIMESTAMPTZ NOT NULL +); +ALTER TABLE sidewalk_login.auth_tokens OWNER TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.auth_tokens TO sidewalk; +GRANT ALL ON TABLE sidewalk_login.auth_tokens TO postgres; + # --- !Downs +-- TABLE: auth_tokens +DROP TABLE IF EXISTS sidewalk_login.auth_tokens; + -- TABLE: sidewalk_user DROP INDEX IF EXISTS email_idx; DROP INDEX IF EXISTS username_idx; diff --git a/conf/evolutions/default/251.sql b/conf/evolutions/default/251.sql index 82ac08b896..247efb9a81 100644 --- a/conf/evolutions/default/251.sql +++ b/conf/evolutions/default/251.sql @@ -52,6 +52,7 @@ ALTER TABLE sidewalk_seattle.validation_task_comment ADD CONSTRAINT validation_t ALTER TABLE sidewalk_seattle.webpage_activity DROP CONSTRAINT IF EXISTS webpage_activity_user_id_fkey; ALTER TABLE sidewalk_seattle.webpage_activity ADD CONSTRAINT webpage_activity_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); +TRUNCATE sidewalk_seattle.auth_tokens; TRUNCATE sidewalk_seattle.sidewalk_user; TRUNCATE sidewalk_seattle.login_info; TRUNCATE sidewalk_seattle.user_login_info; @@ -111,3 +112,4 @@ TRUNCATE sidewalk_login.user_password_info; TRUNCATE sidewalk_login.user_login_info; TRUNCATE sidewalk_login.login_info; TRUNCATE sidewalk_login.sidewalk_user; +TRUNCATE sidewalk_login.auth_tokens; From 414bcb936a64586f4ef9c4da548c4ff5bc2a9739 Mon Sep 17 00:00:00 2001 From: Mikey Saugstad Date: Fri, 18 Oct 2024 13:21:54 -0700 Subject: [PATCH 09/28] removes unified login evolutions, queries will be manually run --- conf/evolutions/default/249.sql | 15 ----- conf/evolutions/default/250.sql | 84 ----------------------- conf/evolutions/default/251.sql | 115 -------------------------------- 3 files changed, 214 deletions(-) delete mode 100644 conf/evolutions/default/249.sql delete mode 100644 conf/evolutions/default/250.sql delete mode 100644 conf/evolutions/default/251.sql diff --git a/conf/evolutions/default/249.sql b/conf/evolutions/default/249.sql deleted file mode 100644 index 6c2e8584c9..0000000000 --- a/conf/evolutions/default/249.sql +++ /dev/null @@ -1,15 +0,0 @@ --- Create new schema --- Create tables/indexes in new schema --- Grant access to all tables/indexes --- Update sequences for pkeys of all new tables --- Apply foreign keys to sidewalk_user table - --- Create Login Schema to unify login systems. - -# --- !Ups -CREATE SCHEMA IF NOT EXISTS sidewalk_login; -ALTER SCHEMA sidewalk_login OWNER TO sidewalk; - -# --- !Downs -DROP SCHEMA IF EXISTS sidewalk_login CASCADE; - diff --git a/conf/evolutions/default/250.sql b/conf/evolutions/default/250.sql deleted file mode 100644 index 6b88ed35c9..0000000000 --- a/conf/evolutions/default/250.sql +++ /dev/null @@ -1,84 +0,0 @@ --- Create tables and indexes for login tables and grant "sidewalk" user access. - -# --- !Ups --- TABLE: user_password_info -CREATE TABLE IF NOT EXISTS sidewalk_login.user_password_info ( - user_password_info_id SERIAL NOT NULL, - login_info_id bigint NOT NULL, - password VARCHAR(254) NOT NULL, - salt VARCHAR(254), - hasher VARCHAR(254) NOT NULL, - PRIMARY KEY (user_password_info_id) -); -ALTER TABLE sidewalk_login.user_password_info OWNER TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.user_password_info TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.user_password_info TO postgres; - --- TABLE: login_info -CREATE TABLE IF NOT EXISTS sidewalk_login.login_info( - login_info_id BIGSERIAL NOT NULL, - provider_id VARCHAR(254), - provider_key VARCHAR(254), - PRIMARY KEY (login_info_id) -); -ALTER TABLE sidewalk_login.login_info OWNER TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.login_info TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.login_info TO postgres; - --- TABLE: user_login_info -CREATE TABLE IF NOT EXISTS sidewalk_login.user_login_info( - user_login_info_id SERIAL NOT NULL, - login_info_id bigint NOT NULL, - user_id VARCHAR(254) NOT NULL, - PRIMARY KEY (user_login_info_id) -); -CREATE INDEX IF NOT EXISTS user_login_info_login_info_id_idx ON sidewalk_login.user_login_info USING btree(login_info_id); -CREATE INDEX IF NOT EXISTS user_login_info_user_id_idx ON sidewalk_login.user_login_info USING btree(user_id); -ALTER TABLE sidewalk_login.user_login_info OWNER TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.user_login_info TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.user_login_info TO postgres; - --- TABLE: sidewalk_user -CREATE TABLE IF NOT EXISTS sidewalk_login.sidewalk_user( - user_id TEXT UNIQUE NOT NULL, - username TEXT UNIQUE NOT NULL, - email TEXT NOT NULL, - PRIMARY KEY (user_id) -); -CREATE INDEX IF NOT EXISTS user_id_idx ON sidewalk_login.sidewalk_user USING btree(user_id); -CREATE INDEX IF NOT EXISTS username_idx ON sidewalk_login.sidewalk_user USING btree(username); -CREATE INDEX IF NOT EXISTS email_idx ON sidewalk_login.sidewalk_user USING btree(email); -ALTER TABLE sidewalk_login.sidewalk_user OWNER TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.sidewalk_user TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.sidewalk_user TO postgres; - --- TABLE: auth_tokens -CREATE TABLE sidewalk_login.auth_tokens ( - user_id character varying(254) NOT NULL, - id bytea NOT NULL, - expiration_timestamp TIMESTAMPTZ NOT NULL -); -ALTER TABLE sidewalk_login.auth_tokens OWNER TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.auth_tokens TO sidewalk; -GRANT ALL ON TABLE sidewalk_login.auth_tokens TO postgres; - -# --- !Downs --- TABLE: auth_tokens -DROP TABLE IF EXISTS sidewalk_login.auth_tokens; - --- TABLE: sidewalk_user -DROP INDEX IF EXISTS email_idx; -DROP INDEX IF EXISTS username_idx; -DROP INDEX IF EXISTS user_id_idx; -DROP TABLE IF EXISTS sidewalk_login.sidewalk_user; - --- TABLE: user_login_info -DROP INDEX IF EXISTS user_login_info_user_id_idx; -DROP INDEX IF EXISTS user_login_info_login_info_id_idx; -DROP TABLE IF EXISTS sidewalk_login.user_login_info; - --- TABLE: login_info -DROP TABLE IF EXISTS sidewalk_login.login_info; - --- TABLE: user_password_info -DROP TABLE IF EXISTS sidewalk_login.user_password_info; diff --git a/conf/evolutions/default/251.sql b/conf/evolutions/default/251.sql deleted file mode 100644 index 247efb9a81..0000000000 --- a/conf/evolutions/default/251.sql +++ /dev/null @@ -1,115 +0,0 @@ --- Move data from city schemas to new login data schema. --- TODO: Copy login data from ALL cities to login schema --- TODO: Among duplicates across cities, keep data from most recently logged in user. --- TODO: Update pkey sequence to the end of the data's sequence - -# --- !Ups --- Copy all login info from Seattle into the new sidewalk_login schema -INSERT INTO sidewalk_login.sidewalk_user(user_id, username, email) -SELECT user_id, username, email FROM sidewalk_seattle.sidewalk_user; - -INSERT INTO sidewalk_login.login_info(login_info_id, provider_id, provider_key) -SELECT login_info_id, provider_id, provider_key FROM sidewalk_seattle.login_info; -SELECT setval('sidewalk_login.login_info_login_info_id_seq', (SELECT MAX(login_info_id) FROM sidewalk_login.login_info)); - -INSERT INTO sidewalk_login.user_login_info(user_login_info_id, user_id, login_info_id) -SELECT user_login_info_id, user_id, login_info_id FROM sidewalk_seattle.user_login_info; -SELECT setval('sidewalk_login.user_login_info_user_login_info_id_seq', (SELECT MAX(user_login_info_id) FROM sidewalk_login.user_login_info)); - -INSERT INTO sidewalk_login.user_password_info (user_password_info_id, login_info_id, "password", salt, hasher) -SELECT user_password_info_id, login_info_id, "password", salt, hasher FROM sidewalk_seattle.user_password_info; -SELECT setval('sidewalk_login.user_password_info_user_password_info_id_seq', (SELECT MAX(user_password_info_id) FROM sidewalk_login.user_password_info)); - --- Move constraints over to the new schema. -ALTER TABLE sidewalk_seattle.audit_task DROP CONSTRAINT IF EXISTS audit_task_user_id_fkey; -ALTER TABLE sidewalk_seattle.audit_task ADD CONSTRAINT audit_task_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.gallery_task_environment DROP CONSTRAINT IF EXISTS gallery_task_environment_user_id_fkey; -ALTER TABLE sidewalk_seattle.gallery_task_environment ADD CONSTRAINT gallery_task_environment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.gallery_task_interaction DROP CONSTRAINT IF EXISTS gallery_task_interaction_user_id_fkey; -ALTER TABLE sidewalk_seattle.gallery_task_interaction ADD CONSTRAINT gallery_task_interaction_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.label_history DROP CONSTRAINT IF EXISTS label_history_edited_by_fkey; -ALTER TABLE sidewalk_seattle.label_history ADD CONSTRAINT label_history_edited_by_fkey FOREIGN KEY (edited_by) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.label_validation DROP CONSTRAINT IF EXISTS label_validation_user_id_fkey; -ALTER TABLE sidewalk_seattle.label_validation ADD CONSTRAINT label_validation_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.mission DROP CONSTRAINT IF EXISTS mission_user_id_fkey; -ALTER TABLE sidewalk_seattle.mission ADD CONSTRAINT mission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.route DROP CONSTRAINT IF EXISTS route_user_id_fkey; -ALTER TABLE sidewalk_seattle.route ADD CONSTRAINT route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_clustering_session DROP CONSTRAINT IF EXISTS user_clustering_session_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_clustering_session ADD CONSTRAINT user_clustering_session_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_org DROP CONSTRAINT IF EXISTS user_org_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_org ADD CONSTRAINT user_org_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_route DROP CONSTRAINT IF EXISTS user_route_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_route ADD CONSTRAINT user_route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_stat DROP CONSTRAINT IF EXISTS user_stat_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_stat ADD CONSTRAINT user_stat_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_survey_option_submission DROP CONSTRAINT IF EXISTS user_survey_option_submission_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_survey_option_submission ADD CONSTRAINT user_survey_option_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_survey_text_submission DROP CONSTRAINT IF EXISTS user_survey_text_submission_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_survey_text_submission ADD CONSTRAINT user_survey_text_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.validation_task_comment DROP CONSTRAINT IF EXISTS validation_task_comment_user_id_fkey; -ALTER TABLE sidewalk_seattle.validation_task_comment ADD CONSTRAINT validation_task_comment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.webpage_activity DROP CONSTRAINT IF EXISTS webpage_activity_user_id_fkey; -ALTER TABLE sidewalk_seattle.webpage_activity ADD CONSTRAINT webpage_activity_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_login.sidewalk_user(user_id); - -TRUNCATE sidewalk_seattle.auth_tokens; -TRUNCATE sidewalk_seattle.sidewalk_user; -TRUNCATE sidewalk_seattle.login_info; -TRUNCATE sidewalk_seattle.user_login_info; -TRUNCATE sidewalk_seattle.user_password_info; - -# --- !Downs --- Copy all login info from sidewalk_login back into the Seattle schema. -INSERT INTO sidewalk_seattle.sidewalk_user(user_id, username, email) -SELECT user_id, username, email FROM sidewalk_login.sidewalk_user; - -INSERT INTO sidewalk_seattle.login_info(login_info_id, provider_id, provider_key) -SELECT login_info_id, provider_id, provider_key FROM sidewalk_login.login_info; -SELECT setval('sidewalk_seattle.logininfo_id_seq', (SELECT MAX(login_info_id) FROM sidewalk_seattle.login_info)); - -INSERT INTO sidewalk_seattle.user_login_info(user_login_info_id, user_id, login_info_id) -SELECT user_login_info_id, user_id, login_info_id FROM sidewalk_login.user_login_info; --- SELECT setval('sidewalk_seattle.user_login_info_user_login_info_id_seq', (SELECT MAX(user_login_info_id) FROM sidewalk_seattle.user_login_info)); - -INSERT INTO sidewalk_seattle.user_password_info (user_password_info_id, login_info_id, "password", salt, hasher) -SELECT user_password_info_id, login_info_id, "password", salt, hasher FROM sidewalk_login.user_password_info; --- SELECT setval('sidewalk_seattle.user_password_info_user_password_info_id_seq', (SELECT MAX(user_password_info_id) FROM sidewalk_seattle.user_password_info)); - --- Move the constraints back to the Seattle schema. -ALTER TABLE sidewalk_seattle.webpage_activity DROP CONSTRAINT IF EXISTS webpage_activity_user_id_fkey; -ALTER TABLE sidewalk_seattle.webpage_activity ADD CONSTRAINT webpage_activity_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.validation_task_comment DROP CONSTRAINT IF EXISTS validation_task_comment_user_id_fkey; -ALTER TABLE sidewalk_seattle.validation_task_comment ADD CONSTRAINT validation_task_comment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_survey_text_submission DROP CONSTRAINT IF EXISTS user_survey_text_submission_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_survey_text_submission ADD CONSTRAINT user_survey_text_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_survey_option_submission DROP CONSTRAINT IF EXISTS user_survey_option_submission_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_survey_option_submission ADD CONSTRAINT user_survey_option_submission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_stat DROP CONSTRAINT IF EXISTS user_stat_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_stat ADD CONSTRAINT user_stat_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_route DROP CONSTRAINT IF EXISTS user_route_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_route ADD CONSTRAINT user_route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_org DROP CONSTRAINT IF EXISTS user_org_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_org ADD CONSTRAINT user_org_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.user_clustering_session DROP CONSTRAINT IF EXISTS user_clustering_session_user_id_fkey; -ALTER TABLE sidewalk_seattle.user_clustering_session ADD CONSTRAINT user_clustering_session_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.route DROP CONSTRAINT IF EXISTS route_user_id_fkey; -ALTER TABLE sidewalk_seattle.route ADD CONSTRAINT route_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.mission DROP CONSTRAINT IF EXISTS mission_user_id_fkey; -ALTER TABLE sidewalk_seattle.mission ADD CONSTRAINT mission_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.label_validation DROP CONSTRAINT IF EXISTS label_validation_user_id_fkey; -ALTER TABLE sidewalk_seattle.label_validation ADD CONSTRAINT label_validation_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.label_history DROP CONSTRAINT IF EXISTS label_history_edited_by_fkey; -ALTER TABLE sidewalk_seattle.label_history ADD CONSTRAINT label_history_edited_by_fkey FOREIGN KEY (edited_by) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.gallery_task_interaction DROP CONSTRAINT IF EXISTS gallery_task_interaction_user_id_fkey; -ALTER TABLE sidewalk_seattle.gallery_task_interaction ADD CONSTRAINT gallery_task_interaction_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.gallery_task_environment DROP CONSTRAINT IF EXISTS gallery_task_environment_user_id_fkey; -ALTER TABLE sidewalk_seattle.gallery_task_environment ADD CONSTRAINT gallery_task_environment_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); -ALTER TABLE sidewalk_seattle.audit_task DROP CONSTRAINT IF EXISTS audit_task_user_id_fkey; -ALTER TABLE sidewalk_seattle.audit_task ADD CONSTRAINT audit_task_user_id_fkey FOREIGN KEY (user_id) REFERENCES sidewalk_seattle.sidewalk_user(user_id); - --- Truncate the tables in the sidewalk_login schema. -TRUNCATE sidewalk_login.user_password_info; -TRUNCATE sidewalk_login.user_login_info; -TRUNCATE sidewalk_login.login_info; -TRUNCATE sidewalk_login.sidewalk_user; -TRUNCATE sidewalk_login.auth_tokens; From 9361e24bd12209bb97f2ebad6b08d058b7960585 Mon Sep 17 00:00:00 2001 From: Mikey Saugstad Date: Mon, 21 Oct 2024 15:48:55 -0700 Subject: [PATCH 10/28] LabelMap can now filter for labels along a route --- app/controllers/AdminController.scala | 7 +++--- app/controllers/ApplicationController.scala | 9 ++++--- app/models/label/LabelTable.scala | 23 ++++++++++++++---- app/views/labelMap.scala.html | 26 +++++++++++++-------- conf/routes | 6 ++--- 5 files changed, 48 insertions(+), 23 deletions(-) diff --git a/app/controllers/AdminController.scala b/app/controllers/AdminController.scala index 4e62bdccea..44305ae84d 100644 --- a/app/controllers/AdminController.scala +++ b/app/controllers/AdminController.scala @@ -108,7 +108,7 @@ class AdminController @Inject() (implicit val env: Environment[User, SessionAuth */ def getAllLabels = UserAwareAction.async { implicit request => if (isAdmin(request.identity)) { - val labels = LabelTable.selectLocationsAndSeveritiesOfLabels(List()) + val labels = LabelTable.selectLocationsAndSeveritiesOfLabels(List(), List()) val features: List[JsObject] = labels.par.map { label => val point = geojson.Point(geojson.LatLng(label.lat.toDouble, label.lng.toDouble)) val properties = Json.obj( @@ -131,9 +131,10 @@ class AdminController @Inject() (implicit val env: Environment[User, SessionAuth /** * Get a list of all labels with metadata needed for /labelMap. */ - def getAllLabelsForLabelMap(regions: Option[String]) = UserAwareAction.async { implicit request => + def getAllLabelsForLabelMap(regions: Option[String], routes: Option[String]) = UserAwareAction.async { implicit request => val regionIds: List[Int] = regions.map(parseIntegerList).getOrElse(List()) - val labels: List[LabelLocationWithSeverity] = LabelTable.selectLocationsAndSeveritiesOfLabels(regionIds) + val routeIds: List[Int] = routes.map(parseIntegerList).getOrElse(List()) + val labels: List[LabelLocationWithSeverity] = LabelTable.selectLocationsAndSeveritiesOfLabels(regionIds, routeIds) val features: List[JsObject] = labels.par.map { label => val point: Point[LatLng] = geojson.Point(geojson.LatLng(label.lat.toDouble, label.lng.toDouble)) val properties: JsObject = Json.obj( diff --git a/app/controllers/ApplicationController.scala b/app/controllers/ApplicationController.scala index 0db692d9e5..4b6f590789 100644 --- a/app/controllers/ApplicationController.scala +++ b/app/controllers/ApplicationController.scala @@ -348,10 +348,12 @@ class ApplicationController @Inject() (implicit val env: Environment[User, Sessi } /** - * Returns the labelmap page that contains a cool visualization. + * Returns the LabelMap page that contains a cool visualization. */ - def labelMap(regions: Option[String]) = UserAwareAction.async { implicit request => + def labelMap(regions: Option[String], routes: Option[String]) = UserAwareAction.async { implicit request => + // TODO what do we do if the route doesn't exist? val regionIds: List[Int] = regions.map(parseIntegerList).getOrElse(List()) + val routeIds: List[Int] = routes.map(parseIntegerList).getOrElse(List()) request.identity match { case Some(user) => val timestamp: Timestamp = new Timestamp(Instant.now.toEpochMilli) @@ -359,8 +361,9 @@ class ApplicationController @Inject() (implicit val env: Environment[User, Sessi val activityStr: String = if (regions.isEmpty) "Visit_LabelMap" else s"Visit_LabelMap_Regions=$regions" WebpageActivityTable.save(WebpageActivity(0, user.userId.toString, ipAddress, activityStr, timestamp)) - Future.successful(Ok(views.html.labelMap("Sidewalk - LabelMap", Some(user), regionIds))) + Future.successful(Ok(views.html.labelMap("Sidewalk - LabelMap", Some(user), regionIds, routeIds))) case None => + // TODO include routeId query param in redirect for anon users. // UTF-8 codes needed to pass a URL that contains parameters: ? is %3F, & is %26 val queryParams: String = regions.map(r => s"%3Fregions=$r").getOrElse("") Future.successful(Redirect("/anonSignUp?url=/labelmap" + queryParams)) diff --git a/app/models/label/LabelTable.scala b/app/models/label/LabelTable.scala index f24b19de4e..1b4835bafb 100644 --- a/app/models/label/LabelTable.scala +++ b/app/models/label/LabelTable.scala @@ -13,7 +13,8 @@ import models.gsv.GSVDataTable import models.mission.{Mission, MissionTable} import models.region.RegionTable import models.attribute.ConfigTable -import models.street.StreetEdgeRegionTable +import models.route.RouteStreetTable +import models.street.{StreetEdgeRegionTable, StreetEdgeTable} import models.user.{RoleTable, UserRoleTable, UserStatTable, VersionTable} import models.utils.MyPostgresDriver import models.utils.MyPostgresDriver.simple._ @@ -107,6 +108,7 @@ object LabelTable { val labelPoints = TableQuery[LabelPointTable] val labelValidations = TableQuery[LabelValidationTable] val missions = TableQuery[MissionTable] + val streets = TableQuery[StreetEdgeTable] val regions = TableQuery[RegionTable] val users = TableQuery[UserTable] val userRoles = TableQuery[UserRoleTable] @@ -991,7 +993,7 @@ object LabelTable { /** * Returns all the submitted labels with their severities included. If provided, filter for only given regions. */ - def selectLocationsAndSeveritiesOfLabels(regionIds: List[Int]): List[LabelLocationWithSeverity] = db.withSession { implicit session => + def selectLocationsAndSeveritiesOfLabels(regionIds: List[Int], routeIds: List[Int]): List[LabelLocationWithSeverity] = db.withSession { implicit session => val _labels = for { _l <- labels _lType <- labelTypes if _l.labelTypeId === _lType.labelTypeId @@ -1002,12 +1004,25 @@ object LabelTable { if (_ser.regionId inSet regionIds) || regionIds.isEmpty if _lPoint.lat.isDefined && _lPoint.lng.isDefined // Make sure they are NOT NULL so we can safely use .get later. } yield (_l.labelId, _l.auditTaskId, _lType.labelType, _lPoint.lat, _lPoint.lng, _l.correct, - _l.agreeCount > 0 || _l.disagreeCount > 0 || _l.unsureCount > 0, _gsv.expired, _us.highQuality, _l.severity) + _l.agreeCount > 0 || _l.disagreeCount > 0 || _l.unsureCount > 0, _gsv.expired, _us.highQuality, _l.severity, _ser.streetEdgeId) + + // Filter for labels along the given route. Distance experimentally set to 0.0005 degrees. Would like to switch to + // different SRID and use meters: https://github.com/ProjectSidewalk/SidewalkWebpage/issues/3655. + val _labelsNearRoute = if (routeIds.nonEmpty) { + for { + _rs <- RouteStreetTable.routeStreets if _rs.routeId inSet routeIds + _se <- streets if _rs.streetEdgeId === _se.streetEdgeId + _l <- _labels if _se.streetEdgeId === _l._11 || + _se.geom.distance(makePoint(_l._5.asColumnOf[Double], _l._4.asColumnOf[Double]).setSRID(4326)) < 0.0005F + } yield _l + } else { + _labels + } // For some reason we couldn't use both `_l.agreeCount > 0` and `_lPoint.lat.get` in the yield without a runtime // error, which is why we couldn't use `.tupled` here. This was the error message: // SlickException: Expected an option type, found Float/REAL - _labels.list.map(l => LabelLocationWithSeverity(l._1, l._2, l._3, l._4.get, l._5.get, l._6, l._7, l._8, l._9, l._10)) + _labelsNearRoute.list.map(l => LabelLocationWithSeverity(l._1, l._2, l._3, l._4.get, l._5.get, l._6, l._7, l._8, l._9, l._10)) } /** diff --git a/app/views/labelMap.scala.html b/app/views/labelMap.scala.html index ea11956e1d..79b3cc0164 100644 --- a/app/views/labelMap.scala.html +++ b/app/views/labelMap.scala.html @@ -1,7 +1,7 @@ @import models.user.User @import play.api.Play @import play.api.Play.current -@(title: String, user: Option[User] = None, regionIds: List[Int])(implicit lang: Lang) +@(title: String, user: Option[User] = None, regionIds: List[Int], routeIds: List[Int])(implicit lang: Lang) @cityId = @{Play.configuration.getString("city-id").get} @@ -170,17 +170,23 @@ popupLabelViewer: AdminGSVLabelView(false, "LabelMap"), differentiateExpiredLabels: true }; + params.neighborhoodsURL = new URL('/neighborhoods', window.location.origin); + params.completionRatesURL = new URL('/adminapi/neighborhoodCompletionRate', window.location.origin); + params.streetsURL = new URL('/contribution/streets/all?filterLowQuality=true', window.location.origin); + params.labelsURL = new URL('/labels/all', window.location.origin); + let regionsParam = '@{regionIds.mkString(",")}'; if (regionsParam) { - params.neighborhoodsURL = `/neighborhoods?regions=${regionsParam}`; - params.completionRatesURL = `/adminapi/neighborhoodCompletionRate?regions=${regionsParam}`; - params.streetsURL = `/contribution/streets/all?filterLowQuality=true®ions=${regionsParam}`; - params.labelsURL = `/labels/all?regions=${regionsParam}`; - } else { - params.neighborhoodsURL = '/neighborhoods'; - params.completionRatesURL = '/adminapi/neighborhoodCompletionRate'; - params.streetsURL = '/contribution/streets/all?filterLowQuality=true'; - params.labelsURL = '/labels/all'; + params.neighborhoodsURL.searchParams.append('regions', regionsParam); + params.completionRatesURL.searchParams.append('regions', regionsParam); + params.streetsURL.searchParams.append('regions', regionsParam); + params.labelsURL.searchParams.append('regions', regionsParam); + } + + let routesParam = '@{routeIds.mkString(",")}'; + if (routesParam) { + params.streetsURL.searchParams.append('routes', routesParam); + params.labelsURL.searchParams.append('routes', routesParam); } // Show polling locations for Chicago, IL as part of a pilot. if ('@cityId' === 'chicago-il') { diff --git a/conf/routes b/conf/routes index b7a1d42bd7..da0474075f 100644 --- a/conf/routes +++ b/conf/routes @@ -11,8 +11,8 @@ GET /developer @controllers.Applic GET /terms @controllers.ApplicationController.terms GET /demo @controllers.ApplicationController.demo GET /results @controllers.ApplicationController.results -GET /labelMap @controllers.ApplicationController.labelMap(regions: Option[String] ?= None) -GET /labelmap @controllers.ApplicationController.labelMap(regions: Option[String] ?= None) +GET /labelMap @controllers.ApplicationController.labelMap(regions: Option[String] ?= None, routes: Option[String] ?= None) +GET /labelmap @controllers.ApplicationController.labelMap(regions: Option[String] ?= None, routes: Option[String] ?= None) GET /gallery @controllers.ApplicationController.gallery(labelType: String ?= "Assorted", neighborhoods: String ?= "", severities: String ?= "", tags: String ?= "", validationOptions: String ?= "correct,unvalidated") GET /help @controllers.ApplicationController.help GET /labelingGuide @controllers.ApplicationController.labelingGuide @@ -88,7 +88,7 @@ PUT /adminapi/setOrg @controllers.AdminC PUT /adminapi/setTaskFlagsBeforeDate @controllers.AdminController.setTaskFlagsBeforeDate PUT /adminapi/setTaskFlag @controllers.AdminController.setTaskFlag -GET /labels/all @controllers.AdminController.getAllLabelsForLabelMap(regions: Option[String] ?= None) +GET /labels/all @controllers.AdminController.getAllLabelsForLabelMap(regions: Option[String] ?= None, routes: Option[String] ?= None) GET /label/id/:labelId @controllers.AdminController.getLabelData(labelId: Int) # Auditing tasks From fb11aea39a5ae4cb4bda13f789ea64d27bff61a3 Mon Sep 17 00:00:00 2001 From: Mikey Saugstad Date: Mon, 21 Oct 2024 16:01:16 -0700 Subject: [PATCH 11/28] streets can now be filtered by route in LabelMap --- app/controllers/UserProfileController.scala | 5 +++-- app/models/audit/AuditTaskTable.scala | 14 ++++++++++++-- conf/routes | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controllers/UserProfileController.scala b/app/controllers/UserProfileController.scala index 68bb36f06b..c37b5961f8 100644 --- a/app/controllers/UserProfileController.scala +++ b/app/controllers/UserProfileController.scala @@ -78,9 +78,10 @@ class UserProfileController @Inject() (implicit val env: Environment[User, Sessi /** * Get the list of all streets and whether they have been audited or not, regardless of user. */ - def getAllStreets(filterLowQuality: Boolean, regions: Option[String]) = UserAwareAction.async { implicit request => + def getAllStreets(filterLowQuality: Boolean, regions: Option[String], routes: Option[String]) = UserAwareAction.async { implicit request => val regionIds: List[Int] = regions.map(parseIntegerList).getOrElse(List()) - val streets: List[StreetEdgeWithAuditStatus] = AuditTaskTable.selectStreetsWithAuditStatus(filterLowQuality, regionIds) + val routeIds: List[Int] = routes.map(parseIntegerList).getOrElse(List()) + val streets: List[StreetEdgeWithAuditStatus] = AuditTaskTable.selectStreetsWithAuditStatus(filterLowQuality, regionIds, routeIds) val features: List[JsObject] = streets.map { edge => val coordinates: Array[Coordinate] = edge.geom.getCoordinates val latlngs: List[geojson.LatLng] = coordinates.map(coord => geojson.LatLng(coord.y, coord.x)).toList // Map it to an immutable list diff --git a/app/models/audit/AuditTaskTable.scala b/app/models/audit/AuditTaskTable.scala index d98f87456f..43f7617d72 100644 --- a/app/models/audit/AuditTaskTable.scala +++ b/app/models/audit/AuditTaskTable.scala @@ -12,6 +12,7 @@ import models.label.{LabelTable, LabelTypeTable} import models.street.StreetEdgePriorityTable import models.user.{UserRoleTable, UserStatTable} import models.mission.{Mission, MissionTable} +import models.route.RouteStreetTable import play.api.libs.json._ import play.api.Play.current import play.extras.geojson @@ -313,7 +314,7 @@ object AuditTaskTable { /** * Return all street edges and whether they have been audited or not. If provided, filter for only given regions. */ - def selectStreetsWithAuditStatus(filterLowQuality: Boolean, regionIds: List[Int]): List[StreetEdgeWithAuditStatus] = db.withSession { implicit session => + def selectStreetsWithAuditStatus(filterLowQuality: Boolean, regionIds: List[Int], routeIds: List[Int]): List[StreetEdgeWithAuditStatus] = db.withSession { implicit session => // Optionally filter out data marked as low quality. val _filteredTasks = if (filterLowQuality) { for { @@ -335,7 +336,16 @@ object AuditTaskTable { .leftJoin(_distinctCompleted).on(_._1.streetEdgeId === _) .map(s => (s._1._1.streetEdgeId, s._1._1.geom, s._1._2.regionId, s._1._1.wayType, !s._2.?.isEmpty)) - streetsWithAuditedStatus.list.map(StreetEdgeWithAuditStatus.tupled) + // If routeIds are provided, filter out streets that are not part of the route. + val streetsWithAuditedStatusFiltered = if (routeIds.nonEmpty) { + RouteStreetTable.routeStreets.filter(_.routeId inSet routeIds) + .innerJoin(streetsWithAuditedStatus).on(_.streetEdgeId === _._1) + .map(_._2) + } else { + streetsWithAuditedStatus + } + + streetsWithAuditedStatusFiltered.list.map(StreetEdgeWithAuditStatus.tupled) } /** diff --git a/conf/routes b/conf/routes index da0474075f..068732a758 100644 --- a/conf/routes +++ b/conf/routes @@ -137,7 +137,7 @@ GET /neighborhoods @controllers.Region # User status # /:username has to come last in the list. Otherwise it eats other urls. GET /contribution/streets @controllers.UserProfileController.getAuditedStreets -GET /contribution/streets/all @controllers.UserProfileController.getAllStreets(filterLowQuality: Boolean ?= false, regions: Option[String] ?= None) +GET /contribution/streets/all @controllers.UserProfileController.getAllStreets(filterLowQuality: Boolean ?= false, regions: Option[String] ?= None, routes: Option[String] ?= None) GET /contribution/auditCounts/all @controllers.UserProfileController.getAllAuditCounts GET /dashboard @controllers.UserProfileController.userProfile GET /userapi/mistakes @controllers.UserProfileController.getRecentMistakes(n: Int ?= 5) From 45bdc96176c2e4f1ee9ae3e7487d57ac074df649 Mon Sep 17 00:00:00 2001 From: Mikey Saugstad Date: Mon, 21 Oct 2024 17:21:38 -0700 Subject: [PATCH 12/28] adds link from RouteBuilder to view route in LabelMap --- app/views/routeBuilder.scala.html | 1 + conf/messages.de | 1 + conf/messages.en | 1 + conf/messages.es | 1 + conf/messages.nl | 1 + conf/messages.zh-TW | 1 + public/javascripts/routeBuilder.js | 8 ++++++++ public/stylesheets/routeBuilder.css | 4 ++-- 8 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/views/routeBuilder.scala.html b/app/views/routeBuilder.scala.html index 11a2aadfb0..69acf6b4ca 100644 --- a/app/views/routeBuilder.scala.html +++ b/app/views/routeBuilder.scala.html @@ -82,6 +82,7 @@
+
diff --git a/conf/messages.de b/conf/messages.de index ff235871db..25f73f71d6 100644 --- a/conf/messages.de +++ b/conf/messages.de @@ -388,6 +388,7 @@ routebuilder.delete.route = Route löschen routebuilder.saved.icon.alt = Ein grüner Kreis mit einem weißen Checkmark in der Mitte routebuilder.saved = Route gespeichert! routebuilder.explore.route = Erforschen Sie diese Route +routebuilder.view.in.labelmap = In der Beschriftungskarte anzeigen routebuilder.build.another.route = Bauen Sie eine andere Route routebuilder.share.title = Speichern Sie diesen Link für den zukünftigen Zugriff: routebuilder.copy.link = Link kopieren diff --git a/conf/messages.en b/conf/messages.en index 1c987ba9ed..4ceb218d57 100644 --- a/conf/messages.en +++ b/conf/messages.en @@ -381,6 +381,7 @@ routebuilder.delete.route = Delete Route routebuilder.saved.icon.alt = A green circle with a white checkmark in the center routebuilder.saved = Route saved! routebuilder.explore.route = Explore This Route +routebuilder.view.in.labelmap = View in Label Map routebuilder.build.another.route = Build Another Route routebuilder.share.title = Save this link for future access: routebuilder.copy.link = Copy Link diff --git a/conf/messages.es b/conf/messages.es index 52e836a8e3..79ed9079f0 100644 --- a/conf/messages.es +++ b/conf/messages.es @@ -391,6 +391,7 @@ routebuilder.delete.route = Eliminar ruta routebuilder.saved.icon.alt = Un círculo verde con una marca de verificación blanca en el centro routebuilder.saved = Ruta guardada! routebuilder.explore.route = Explore esta ruta +routebuilder.view.in.labelmap = Ver en mapa de etiquetas routebuilder.build.another.route = Construir otra ruta routebuilder.share.title = Guarde este enlace para el acceso futuro: routebuilder.copy.link = Copiar link diff --git a/conf/messages.nl b/conf/messages.nl index 2b55e5a945..0d106065f6 100644 --- a/conf/messages.nl +++ b/conf/messages.nl @@ -383,6 +383,7 @@ routebuilder.delete.route = Verwijder route routebuilder.saved.icon.alt = Een groene cirkel met een wit vinkje in het midden routebuilder.saved = Route opgeslagen! routebuilder.explore.route = Verken deze route +routebuilder.view.in.labelmap = Bekijk in Label Kaart routebuilder.build.another.route = Bouw een andere route routebuilder.share.title = Sla deze link op voor toekomstige toegang: routebuilder.copy.link = Kopieer link diff --git a/conf/messages.zh-TW b/conf/messages.zh-TW index cf0cc13168..d58a57a5bc 100644 --- a/conf/messages.zh-TW +++ b/conf/messages.zh-TW @@ -418,6 +418,7 @@ routebuilder.delete.route = 刪除路線 routebuilder.saved.icon.alt = 一個有白色勾號在中心的綠色圓圈 routebuilder.saved = 路線已儲存! routebuilder.explore.route = 探索此路線 +routebuilder.view.in.labelmap = 標記地圖中查看 routebuilder.build.another.route = 設立另一條路線 routebuilder.share.title = 儲存此連結供未來使用: routebuilder.copy.link = 複製連結 diff --git a/public/javascripts/routeBuilder.js b/public/javascripts/routeBuilder.js index 76cf690679..22c1a62859 100644 --- a/public/javascripts/routeBuilder.js +++ b/public/javascripts/routeBuilder.js @@ -30,6 +30,7 @@ function RouteBuilder ($, mapParams) { let exploreButton = $('#explore-button'); let linkTextEl = document.getElementById('share-route-link'); let copyLinkButton = $('#copy-link-button'); + let viewInLabelmapButton = $('#view-in-labelmap-button'); // Add the click event for the clear route buttons. document.getElementById('cancel-button').addEventListener('click', clickCancelRoute); @@ -693,6 +694,13 @@ function RouteBuilder ($, mapParams) { logActivity(`RouteBuilder_Click=Copy_RouteId=${data.route_id}`); }); + // Update link for the 'View in LabelMap' button. + viewInLabelmapButton.off('click'); + viewInLabelmapButton.click(function () { + logActivity(`RouteBuilder_Click=LabelMap_RouteId=${data.route_id}`); + window.open(`/labelMap?routes=${data.route_id}`, '_blank'); + }); + logActivity(`RouteBuilder_Click=SaveSuccess_RouteId=${data.route_id}`); }) .catch((error) => { diff --git a/public/stylesheets/routeBuilder.css b/public/stylesheets/routeBuilder.css index 5f7031882f..20f22da2bc 100644 --- a/public/stylesheets/routeBuilder.css +++ b/public/stylesheets/routeBuilder.css @@ -26,9 +26,9 @@ } .routebuilder-centered-overlay { - width: 520px; + width: 590px; top: calc(4% + 85px); /* 2% + navbar height + map margin-top */ - left: calc(50% - 260px); /* 50% - width/2 */ + left: calc(50% - 295px); /* 50% - width/2 */ } .routebuilder-h1 { From d82896e8921db34c53b50a3d839541f54f11d04e Mon Sep 17 00:00:00 2001 From: Mikey Saugstad Date: Tue, 22 Oct 2024 12:16:10 -0700 Subject: [PATCH 13/28] fixes anon redirect URL for LabelMap when viewing a route --- app/controllers/ApplicationController.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/ApplicationController.scala b/app/controllers/ApplicationController.scala index 4b6f590789..d9813c953c 100644 --- a/app/controllers/ApplicationController.scala +++ b/app/controllers/ApplicationController.scala @@ -351,7 +351,6 @@ class ApplicationController @Inject() (implicit val env: Environment[User, Sessi * Returns the LabelMap page that contains a cool visualization. */ def labelMap(regions: Option[String], routes: Option[String]) = UserAwareAction.async { implicit request => - // TODO what do we do if the route doesn't exist? val regionIds: List[Int] = regions.map(parseIntegerList).getOrElse(List()) val routeIds: List[Int] = routes.map(parseIntegerList).getOrElse(List()) request.identity match { @@ -363,9 +362,13 @@ class ApplicationController @Inject() (implicit val env: Environment[User, Sessi WebpageActivityTable.save(WebpageActivity(0, user.userId.toString, ipAddress, activityStr, timestamp)) Future.successful(Ok(views.html.labelMap("Sidewalk - LabelMap", Some(user), regionIds, routeIds))) case None => - // TODO include routeId query param in redirect for anon users. // UTF-8 codes needed to pass a URL that contains parameters: ? is %3F, & is %26 - val queryParams: String = regions.map(r => s"%3Fregions=$r").getOrElse("") + val queryParams: String = (regionIds, routeIds) match { + case (Nil, Nil) => "" + case (r, Nil) => s"%3Fregions=${r.mkString(",")}" + case (Nil, r) => s"%3Froutes=${r.mkString(",")}" + case (r, s) => s"%3Fregions=${r.mkString(",")}%26routes=${s.mkString(",")}" + } Future.successful(Redirect("/anonSignUp?url=/labelmap" + queryParams)) } } From b6029b63d8731dd302abe163b48f0ec08bd560f3 Mon Sep 17 00:00:00 2001 From: Srihari Krishnaswamy Date: Wed, 23 Oct 2024 16:50:42 -0700 Subject: [PATCH 14/28] Addresses Street Edge data being slow to load in Admin template scala by moving it to new API endpoint --- app/controllers/AdminController.scala | 136 ++++++++++++++++++++++++++ app/views/admin/index.scala.html | 105 ++++++++++---------- public/javascripts/Admin/src/Admin.js | 80 +++++++++++++++ 3 files changed, 269 insertions(+), 52 deletions(-) diff --git a/app/controllers/AdminController.scala b/app/controllers/AdminController.scala index 4e62bdccea..5071d461f4 100644 --- a/app/controllers/AdminController.scala +++ b/app/controllers/AdminController.scala @@ -669,4 +669,140 @@ class AdminController @Inject() (implicit val env: Environment[User, SessionAuth } ) } + + /** + * Gets street edge data for the coverage section of the admin page. + * @return + */ + def getStreetEdgeData = UserAwareAction.async { implicit request => + if (isAdmin(request.identity)) { + val auditedStreetDistanceOverTimeData = Json.obj( + "all_time" -> StreetEdgeTable.auditedStreetDistanceOverTime("all time"), + "today" -> StreetEdgeTable.auditedStreetDistanceOverTime("today"), + "week" -> StreetEdgeTable.auditedStreetDistanceOverTime("week") + ) + + val auditedStreetsData = Json.obj( + "total_streets" -> StreetEdgeTable.countTotalStreets(), + + "total_audited_streets" -> Json.obj( + "all_users" -> Json.obj( + "total" -> StreetEdgeTable.countAuditedStreets(), + "percentage" -> StreetEdgeTable.auditCompletionRate(1) * 100 + ), + "high_quality" -> Json.obj( + "total" -> StreetEdgeTable.countAuditedStreets(1, "All", true), + "percentage" -> StreetEdgeTable.auditCompletionRate(1, "All", true) * 100 + ) + ), + + "registered" -> Json.obj( + "all_users" -> Json.obj( + "total" -> StreetEdgeTable.countAuditedStreets(1, "Registered"), + "percentage" -> StreetEdgeTable.auditCompletionRate(1, "Registered") * 100 + ), + "high_quality" -> Json.obj( + "total" -> StreetEdgeTable.countAuditedStreets(1, "Registered", true), + "percentage" -> StreetEdgeTable.auditCompletionRate(1, "Registered", true) * 100 + ) + ), + + "anonymous" -> Json.obj( + "all_users" -> Json.obj( + "total" -> StreetEdgeTable.countAuditedStreets(1, "Anonymous"), + "percentage" -> StreetEdgeTable.auditCompletionRate(1, "Anonymous") * 100 + ), + "high_quality" -> Json.obj( + "total" -> StreetEdgeTable.countAuditedStreets(1, "Anonymous", true), + "percentage" -> StreetEdgeTable.auditCompletionRate(1, "Anonymous", true) * 100 + ) + ), + + "turker" -> Json.obj( + "all_users" -> Json.obj( + "total" -> StreetEdgeTable.countAuditedStreets(1, "Turker"), + "percentage" -> StreetEdgeTable.auditCompletionRate(1, "Turker") * 100 + ), + "high_quality" -> Json.obj( + "total" -> StreetEdgeTable.countAuditedStreets(1, "Turker", true), + "percentage" -> StreetEdgeTable.auditCompletionRate(1, "Turker", true) * 100 + ) + ), + + "researcher" -> Json.obj( + "all_users" -> Json.obj( + "total" -> StreetEdgeTable.countAuditedStreets(1, "Researcher"), + "percentage" -> StreetEdgeTable.auditCompletionRate(1, "Researcher") * 100 + ), + "high_quality" -> Json.obj( + "total" -> StreetEdgeTable.countAuditedStreets(1, "Researcher", true), + "percentage" -> StreetEdgeTable.auditCompletionRate(1, "Researcher", true) * 100 + ) + ) + ) + + val distanceData = Json.obj( + "total_distance" -> StreetEdgeTable.totalStreetDistance(), + + "total_audited_streets" -> Json.obj( + "all_users" -> Json.obj( + "total" -> StreetEdgeTable.auditedStreetDistance(1), + "percentage" -> StreetEdgeTable.streetDistanceCompletionRate(1) * 100 + ), + "high_quality" -> Json.obj( + "total" -> StreetEdgeTable.auditedStreetDistance(1, "All", true), + "percentage" -> StreetEdgeTable.streetDistanceCompletionRate(1, "All", true) * 100 + ) + ), + + "registered" -> Json.obj( + "all_users" -> Json.obj( + "total" -> StreetEdgeTable.auditedStreetDistance(1, "Registered"), + "percentage" -> StreetEdgeTable.streetDistanceCompletionRate(1, "Registered") * 100 + ), + "high_quality" -> Json.obj( + "total" -> StreetEdgeTable.auditedStreetDistance(1, "Registered", true), + "percentage" -> StreetEdgeTable.streetDistanceCompletionRate(1, "Registered", true) * 100 + ) + ), + + "anonymous" -> Json.obj( + "all_users" -> Json.obj( + "total" -> StreetEdgeTable.auditedStreetDistance(1, "Anonymous"), + "percentage" -> StreetEdgeTable.streetDistanceCompletionRate(1, "Anonymous") * 100 + ), + "high_quality" -> Json.obj( + "total" -> StreetEdgeTable.auditedStreetDistance(1, "Anonymous", true), + "percentage" -> StreetEdgeTable.streetDistanceCompletionRate(1, "Anonymous", true) * 100 + ) + ), + + "turker" -> Json.obj( + "all_users" -> Json.obj( + "total" -> StreetEdgeTable.auditedStreetDistance(1, "Turker"), + "percentage" -> StreetEdgeTable.streetDistanceCompletionRate(1, "Turker") * 100 + ), + "high_quality" -> Json.obj( + "total" -> StreetEdgeTable.auditedStreetDistance(1, "Turker", true), + "percentage" -> StreetEdgeTable.streetDistanceCompletionRate(1, "Turker", true) * 100 + ) + ), + + "researcher" -> Json.obj( + "all_users" -> Json.obj( + "total" -> StreetEdgeTable.auditedStreetDistance(1, "Researcher"), + "percentage" -> StreetEdgeTable.streetDistanceCompletionRate(1, "Researcher") * 100 + ), + "high_quality" -> Json.obj( + "total" -> StreetEdgeTable.auditedStreetDistance(1, "Researcher", true), + "percentage" -> StreetEdgeTable.streetDistanceCompletionRate(1, "Researcher", true) * 100 + ) + ) + ) + val data = Json.obj("audited_street_distance_over_time" -> auditedStreetDistanceOverTimeData, "audited_streets" -> auditedStreetsData, "distance" -> distanceData) + Future.successful(Ok(data)) + } else { + Future.failed(new AuthenticationException("User is not an administrator")) + } + } } diff --git a/app/views/admin/index.scala.html b/app/views/admin/index.scala.html index 147de565e3..1b7fa0a6b9 100644 --- a/app/views/admin/index.scala.html +++ b/app/views/admin/index.scala.html @@ -8,10 +8,6 @@ @import models.user.OrganizationTable @(title: String, user: Option[User] = None)(implicit lang: Lang) -@convertDistance(distance: Float) = @{ - if (Messages("measurement.system") == "metric") distance * 1.60934.toDouble - else distance.toDouble -} @main(title) { @navbar(user, Some("/admin"))