-
Notifications
You must be signed in to change notification settings - Fork 32
♻️ Refactor and Upgrade Users Repository including users_secrets split 🗃️
#8124
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
Merged
pcrespov
merged 47 commits into
ITISFoundation:master
from
pcrespov:is8060/split_secret_tables
Jul 21, 2025
Merged
Changes from 45 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
a32e396
upgrades tests to asyncpg
pcrespov 7882f21
UsersRepo.new_user
pcrespov 6cb5281
♻️ Refactor UsersRepo to use instance methods for user creation and l…
pcrespov a842fc7
fixes
pcrespov 308d296
refactor ruther
pcrespov ad943ba
refactor ruther
pcrespov cd71407
new users secrests table
pcrespov 4f32540
migration table
pcrespov 8391c31
refactoring users
pcrespov debb50f
user
pcrespov b61755b
implement user phone update functionality and refactor related services
pcrespov fd7d979
update user passwrrod
pcrespov da4997d
tests migration
pcrespov d642425
tests migration
pcrespov 1dcc007
create user
pcrespov 6d49cf4
mypy fixes
pcrespov c34af40
insert_user_and_secrets
pcrespov f4207bc
fixing tests fixtures
pcrespov 8b0faf5
fixing tests fixtures
pcrespov e9a4fd5
fixing migration tests
pcrespov 4a41e91
fixes test
pcrespov 77d7161
fixes
pcrespov c57864d
cleanup
pcrespov 82a28e4
using new techniqe
pcrespov 3ba921c
both user and secrets
pcrespov fb08c8c
fixing secret
pcrespov 93c5ccf
common
pcrespov cac9327
rm get_user
pcrespov 134f828
deprecating Storage
pcrespov 5123ab9
refactor: update user injection methods to use new lifespan helpers
pcrespov 772d99a
refactor: improve error handling and user message integration in 2FA …
pcrespov 2e1a775
fixes tests
pcrespov a0220d6
refactor: update billing details retrieval in UsersRepo and improve l…
pcrespov efaf9ce
refactor: streamline user and secrets insertion in tests by consolida…
pcrespov 7b62ec7
test: enhance user password hash update tests and add missing assertions
pcrespov f8f89b1
refactor: ensure user existence check before updating password hash i…
pcrespov ba4cc5a
refactor: improve user credential retrieval by utilizing UsersRepo an…
pcrespov d96a9bd
refactor: simplify user creation in tests by utilizing sync_insert_an…
pcrespov ff9f41b
minor
pcrespov 9aa7514
refactor: fix random_user call in insert_and_get_user_and_secrets_lif…
pcrespov 114e846
fixes tests
pcrespov 6646fa4
rename
pcrespov 6c4e09d
fixes exception
pcrespov f4f37e9
refactor: update user linking logic to associate all pre-registration…
pcrespov 177de8c
fixes error
pcrespov 72d4f4e
fixes
pcrespov 1d9a6c1
@sanderegg review: relative imports
pcrespov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...tabase/src/simcore_postgres_database/migration/versions/5679165336c8_new_users_secrets.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| """new users secrets | ||
|
|
||
| Revision ID: 5679165336c8 | ||
| Revises: 61b98a60e934 | ||
| Create Date: 2025-07-17 17:07:20.200038+00:00 | ||
|
|
||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "5679165336c8" | ||
| down_revision = "61b98a60e934" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.create_table( | ||
| "users_secrets", | ||
| sa.Column("user_id", sa.BigInteger(), nullable=False), | ||
| sa.Column("password_hash", sa.String(), nullable=False), | ||
| sa.Column( | ||
| "modified", | ||
| sa.DateTime(timezone=True), | ||
| server_default=sa.text("now()"), | ||
| nullable=False, | ||
| ), | ||
| sa.ForeignKeyConstraint( | ||
| ["user_id"], | ||
| ["users.id"], | ||
| name="fk_users_secrets_user_id_users", | ||
| onupdate="CASCADE", | ||
| ondelete="CASCADE", | ||
| ), | ||
| sa.PrimaryKeyConstraint("user_id", name="users_secrets_pkey"), | ||
| ) | ||
|
|
||
| # Copy password data from users table to users_secrets table | ||
| op.execute( | ||
| sa.DDL( | ||
| """ | ||
| INSERT INTO users_secrets (user_id, password_hash, modified) | ||
| SELECT id, password_hash, created_at | ||
| FROM users | ||
| WHERE password_hash IS NOT NULL | ||
| """ | ||
| ) | ||
| ) | ||
|
|
||
| op.drop_column("users", "password_hash") | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # Add column as nullable first | ||
| op.add_column( | ||
| "users", | ||
| sa.Column("password_hash", sa.VARCHAR(), autoincrement=False, nullable=True), | ||
| ) | ||
|
|
||
| # Copy password data back from users_secrets table to users table | ||
| op.execute( | ||
| sa.DDL( | ||
| """ | ||
| UPDATE users | ||
| SET password_hash = us.password_hash | ||
| FROM users_secrets us | ||
| WHERE users.id = us.user_id | ||
| """ | ||
| ) | ||
| ) | ||
|
|
||
| # Now make the column NOT NULL | ||
| op.alter_column("users", "password_hash", nullable=False) | ||
|
|
||
| op.drop_table("users_secrets") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/postgres-database/src/simcore_postgres_database/models/users_secrets.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import sqlalchemy as sa | ||
|
|
||
| from ._common import RefActions, column_modified_datetime | ||
| from .base import metadata | ||
|
|
||
| __all__: tuple[str, ...] = ("users_secrets",) | ||
|
|
||
| users_secrets = sa.Table( | ||
| "users_secrets", | ||
| metadata, | ||
| # | ||
| # User Secrets ------------------ | ||
| # | ||
| sa.Column( | ||
| "user_id", | ||
| sa.BigInteger(), | ||
| sa.ForeignKey( | ||
| "users.id", | ||
| name="fk_users_secrets_user_id_users", | ||
| onupdate=RefActions.CASCADE, | ||
| ondelete=RefActions.CASCADE, | ||
| ), | ||
| nullable=False, | ||
| ), | ||
| sa.Column( | ||
| "password_hash", | ||
| sa.String(), | ||
| nullable=False, | ||
| doc="Hashed password", | ||
| ), | ||
| column_modified_datetime(timezone=True, doc="Last password modification timestamp"), | ||
pcrespov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # --------------------------- | ||
| sa.PrimaryKeyConstraint("user_id", name="users_secrets_pkey"), | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.