-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration script for user limits overrides (#1755)
* Add migration script for user limits overrides * Bump packages * Compose fix * Fix links
- Loading branch information
Showing
11 changed files
with
196 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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,37 @@ | ||
[alembic] | ||
script_location = . | ||
sqlalchemy.url = postgresql://postgres:postgres@localhost:5432/postgres | ||
|
||
[loggers] | ||
keys = root,sqlalchemy,alembic | ||
|
||
[handlers] | ||
keys = console | ||
|
||
[formatters] | ||
keys = generic | ||
|
||
[logger_root] | ||
level = WARN | ||
handlers = console | ||
qualname = | ||
|
||
[logger_sqlalchemy] | ||
level = WARN | ||
handlers = | ||
qualname = sqlalchemy.engine | ||
|
||
[logger_alembic] | ||
level = INFO | ||
handlers = | ||
qualname = alembic | ||
|
||
[handler_console] | ||
class = StreamHandler | ||
args = (sys.stderr,) | ||
level = NOTSET | ||
formatter = generic | ||
|
||
[formatter_generic] | ||
format = %(levelname)-5.5s [%(name)s] %(message)s | ||
datefmt = %H:%M:%S |
This file contains 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
66 changes: 66 additions & 0 deletions
66
py/migrations/versions/7eb70560f406_add_limits_overrides_to_users.py
This file contains 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,66 @@ | ||
"""add_limits_overrides_to_users | ||
Revision ID: 7eb70560f406 | ||
Revises: c45a9cf6a8a4 | ||
Create Date: 2025-01-03 20:27:16.139511 | ||
""" | ||
|
||
import os | ||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy import inspect | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "7eb70560f406" | ||
down_revision: Union[str, None] = "c45a9cf6a8a4" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
project_name = os.getenv("R2R_PROJECT_NAME", "r2r_default") | ||
|
||
|
||
def check_if_upgrade_needed(): | ||
"""Check if the upgrade has already been applied""" | ||
connection = op.get_bind() | ||
inspector = inspect(connection) | ||
|
||
# Check if users table exists | ||
if not inspector.has_table("users", schema=project_name): | ||
print( | ||
f"Migration not needed: '{project_name}.users' table doesn't exist" | ||
) | ||
return False | ||
|
||
users_columns = { | ||
col["name"] | ||
for col in inspector.get_columns("users", schema=project_name) | ||
} | ||
|
||
if "limits_overrides" in users_columns: | ||
print( | ||
"Migration not needed: users table already has limits_overrides column" | ||
) | ||
return False | ||
else: | ||
print("Migration needed: users table needs limits_overrides column") | ||
return True | ||
|
||
|
||
def upgrade() -> None: | ||
if not check_if_upgrade_needed(): | ||
return | ||
|
||
# Add the limits_overrides column as JSONB with default NULL | ||
op.add_column( | ||
"users", | ||
sa.Column("limits_overrides", sa.JSON(), nullable=True), | ||
schema=project_name, | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
# Remove the limits_overrides column | ||
op.drop_column("users", "limits_overrides", schema=project_name) |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" | |
[tool.poetry] | ||
name = "r2r" | ||
readme = "README.md" | ||
version = "3.3.18" | ||
version = "3.3.19" | ||
|
||
description = "SciPhi R2R" | ||
authors = ["Owen Colegrove <[email protected]>"] | ||
|