-
Notifications
You must be signed in to change notification settings - Fork 29
Allow users to change their email #8781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
bdab4af
8b4ac8b
3562d51
07fabe0
209bf8b
9774d5a
58bcc29
74fe1f2
5b866a0
04151f4
8d7ed7b
8be7adb
56098bc
9ec548d
d443e02
cc94854
2a1166d
9dd940d
7ff58c0
c45795f
dae5355
34bb221
c9731b2
4477287
9811f0a
ddc9f57
30e72ab
d0ca9c5
6b14824
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
START TRANSACTION; | ||
|
||
do $$ begin ASSERT (select schemaVersion from webknossos.releaseInformation) = 135, 'Previous schema version mismatch'; end; $$ LANGUAGE plpgsql; | ||
|
||
DROP VIEW IF EXISTS webknossos.userInfos; | ||
DROP VIEW IF EXISTS webknossos.multiUsers_; | ||
|
||
ALTER TABLE webknossos.multiUsers ADD COLUMN emailChangeDate TIMESTAMPTZ NOT NULL DEFAULT NOW(); | ||
UPDATE webknossos.multiUsers SET emailChangeDate = created; | ||
|
||
Comment on lines
+8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Heavy rewrite risk – split the A less disruptive pattern: -ALTER TABLE webknossos.multiUsers ADD COLUMN emailChangeDate TIMESTAMPTZ NOT NULL DEFAULT NOW();
+-- 1. add nullable column without default (no rewrite)
+ALTER TABLE webknossos.multiUsers ADD COLUMN emailChangeDate TIMESTAMPTZ;
+
+-- 2. back-fill existing rows
+UPDATE webknossos.multiUsers SET emailChangeDate = created;
+
+-- 3. make it NOT NULL and set the default for new rows
+ALTER TABLE webknossos.multiUsers
+ ALTER COLUMN emailChangeDate SET NOT NULL,
+ ALTER COLUMN emailChangeDate SET DEFAULT NOW(); This avoids the rewrite while achieving the same outcome. 🤖 Prompt for AI Agents
|
||
CREATE VIEW webknossos.multiUsers_ AS SELECT * FROM webknossos.multiUsers WHERE NOT isDeleted; | ||
CREATE VIEW webknossos.userInfos AS | ||
SELECT | ||
u._id AS _user, m.email, u.firstName, u.lastname, o.name AS organization_name, | ||
u.isDeactivated, u.isDatasetManager, u.isAdmin, m.isSuperUser, | ||
u._organization, o._id AS organization_id, u.created AS user_created, | ||
m.created AS multiuser_created, u._multiUser, m._lastLoggedInIdentity, u.lastActivity, m.isEmailVerified | ||
FROM webknossos.users_ u | ||
JOIN webknossos.organizations_ o ON u._organization = o._id | ||
JOIN webknossos.multiUsers_ m on u._multiUser = m._id; | ||
Comment on lines
+11
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Missing Add the column so callers get it “for free”: -SELECT
-u._id AS _user, m.email, u.firstName, u.lastname, o.name AS organization_name,
+SELECT
+u._id AS _user, m.email, u.firstName, u.lastname, o.name AS organization_name,
+m.emailChangeDate, Update all select lists and keep the column order consistent with the forward-migration philosophy that views reflect relevant business data. 🤖 Prompt for AI Agents
|
||
|
||
UPDATE webknossos.releaseInformation SET schemaVersion = 136; | ||
|
||
COMMIT TRANSACTION; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
START TRANSACTION; | ||
|
||
do $$ begin ASSERT (select schemaVersion from webknossos.releaseInformation) = 136, 'Previous schema version mismatch'; end; $$ LANGUAGE plpgsql; | ||
|
||
DROP VIEW IF EXISTS webknossos.userInfos; | ||
DROP VIEW IF EXISTS webknossos.multiUsers_; | ||
|
||
ALTER TABLE webknossos.multiUsers DROP COLUMN emailChangeDate; | ||
|
||
CREATE VIEW webknossos.multiUsers_ AS SELECT * FROM webknossos.multiUsers WHERE NOT isDeleted; | ||
CREATE VIEW webknossos.userInfos AS | ||
SELECT | ||
u._id AS _user, m.email, u.firstName, u.lastname, o.name AS organization_name, | ||
u.isDeactivated, u.isDatasetManager, u.isAdmin, m.isSuperUser, | ||
u._organization, o._id AS organization_id, u.created AS user_created, | ||
m.created AS multiuser_created, u._multiUser, m._lastLoggedInIdentity, u.lastActivity, m.isEmailVerified | ||
FROM webknossos.users_ u | ||
JOIN webknossos.organizations_ o ON u._organization = o._id | ||
JOIN webknossos.multiUsers_ m on u._multiUser = m._id; | ||
|
||
UPDATE webknossos.releaseInformation SET schemaVersion = 135; | ||
|
||
COMMIT TRANSACTION; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider using
CASCADE
when dropping views to avoid dependency errorsIf other objects depend on
userInfos
ormultiUsers_
, theDROP VIEW
will fail and abort the whole migration. AddingCASCADE
is safer in complex schemas.🤖 Prompt for AI Agents