Skip to content

Commit

Permalink
alembic: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kpsherva authored and zzacharo committed Aug 17, 2023
1 parent cba2f1c commit 010f758
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
8 changes: 6 additions & 2 deletions invenio_accounts/alembic/999dcbd19ace_users_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ def upgrade():

# populate the columns of existing rows
op.execute(
text("UPDATE accounts_role SET created = CURRENT_TIMESTAMP, updated = CURRENT_TIMESTAMP, version_id = 1;")
text(
"UPDATE accounts_role SET created = CURRENT_TIMESTAMP, updated = CURRENT_TIMESTAMP, version_id = 1;"
)
) # noqa
op.execute(
text("UPDATE accounts_user SET created = CURRENT_TIMESTAMP, updated = CURRENT_TIMESTAMP, version_id = 1;")
text(
"UPDATE accounts_user SET created = CURRENT_TIMESTAMP, updated = CURRENT_TIMESTAMP, version_id = 1;"
)
) # noqa

# make the columns not nullable
Expand Down
32 changes: 17 additions & 15 deletions invenio_accounts/alembic/dfbdf43a3e96_separate_login_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def upgrade():

# move information from the user table into the new table
op.execute(
text(
"INSERT INTO accounts_user_login_information "
"(user_id, current_login_at, current_login_ip, last_login_at, last_login_ip, login_count) " # noqa
"SELECT id, current_login_at, current_login_ip, last_login_at, last_login_ip, login_count " # noqa
"FROM accounts_user;"
text(
"INSERT INTO accounts_user_login_information "
"(user_id, current_login_at, current_login_ip, last_login_at, last_login_ip, login_count) " # noqa
"SELECT id, current_login_at, current_login_ip, last_login_at, last_login_ip, login_count " # noqa
"FROM accounts_user;"
)
)

Expand Down Expand Up @@ -87,16 +87,18 @@ def downgrade():
# (at least with postgres)
dialect_name = op._proxy.migration_context.dialect.name
if dialect_name == "postgresql":
op.execute(text(
"UPDATE accounts_user SET "
" current_login_at = li.current_login_at, "
" current_login_ip = li.current_login_ip, "
" last_login_at = li.last_login_at, "
" last_login_ip = li.last_login_ip, "
" login_count = li.login_count "
"FROM accounts_user_login_information AS li "
"WHERE accounts_user.id = li.user_id;"
))
op.execute(
text(
"UPDATE accounts_user SET "
" current_login_at = li.current_login_at, "
" current_login_ip = li.current_login_ip, "
" last_login_at = li.last_login_at, "
" last_login_ip = li.last_login_ip, "
" login_count = li.login_count "
"FROM accounts_user_login_information AS li "
"WHERE accounts_user.id = li.user_id;"
)
)

# drop the new table
op.drop_table("accounts_user_login_information")

0 comments on commit 010f758

Please sign in to comment.