Skip to content

Commit

Permalink
apply ruff reformatting in db migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 committed Aug 23, 2024
1 parent 3ace01c commit 57aa250
Show file tree
Hide file tree
Showing 97 changed files with 2,523 additions and 2,251 deletions.
26 changes: 11 additions & 15 deletions api/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,26 @@
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')
logger = logging.getLogger("alembic.env")


def get_engine():
return current_app.extensions['migrate'].db.engine
return current_app.extensions["migrate"].db.engine


def get_engine_url():
try:
return get_engine().url.render_as_string(hide_password=False).replace(
'%', '%%')
return get_engine().url.render_as_string(hide_password=False).replace("%", "%%")
except AttributeError:
return str(get_engine().url).replace('%', '%%')
return str(get_engine().url).replace("%", "%%")


# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
config.set_main_option('sqlalchemy.url', get_engine_url())
target_db = current_app.extensions['migrate'].db
config.set_main_option("sqlalchemy.url", get_engine_url())
target_db = current_app.extensions["migrate"].db

# other values from the config, defined by the needs of env.py,
# can be acquired:
Expand All @@ -40,7 +39,7 @@ def get_engine_url():


def get_metadata():
if hasattr(target_db, 'metadatas'):
if hasattr(target_db, "metadatas"):
return target_db.metadatas[None]
return target_db.metadata

Expand All @@ -65,9 +64,7 @@ def run_migrations_offline():
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=get_metadata(), literal_binds=True
)
context.configure(url=url, target_metadata=get_metadata(), literal_binds=True)

with context.begin_transaction():
context.run_migrations()
Expand All @@ -85,11 +82,11 @@ def run_migrations_online():
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
if getattr(config.cmd_opts, "autogenerate", False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')
logger.info("No changes in schema detected.")

connectable = get_engine()

Expand All @@ -99,7 +96,7 @@ def process_revision_directives(context, revision, directives):
target_metadata=get_metadata(),
process_revision_directives=process_revision_directives,
include_object=include_object,
**current_app.extensions['migrate'].configure_args
**current_app.extensions["migrate"].configure_args,
)

with context.begin_transaction():
Expand All @@ -110,4 +107,3 @@ def process_revision_directives(context, revision, directives):
run_migrations_offline()
else:
run_migrations_online()

Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@
Create Date: 2024-01-07 04:07:34.482983
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = '00bacef91f18'
down_revision = '8ec536f3c800'
revision = "00bacef91f18"
down_revision = "8ec536f3c800"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('description', sa.Text(), nullable=False))
batch_op.drop_column('description_str')
with op.batch_alter_table("tool_api_providers", schema=None) as batch_op:
batch_op.add_column(sa.Column("description", sa.Text(), nullable=False))
batch_op.drop_column("description_str")

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('description_str', sa.TEXT(), autoincrement=False, nullable=False))
batch_op.drop_column('description')
with op.batch_alter_table("tool_api_providers", schema=None) as batch_op:
batch_op.add_column(sa.Column("description_str", sa.TEXT(), autoincrement=False, nullable=False))
batch_op.drop_column("description")

# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@
Create Date: 2024-05-25 07:17:00.539125
"""

import sqlalchemy as sa
from alembic import op

import models as models

# revision identifiers, used by Alembic.
revision = '03f98355ba0e'
down_revision = '9e98fbaffb88'
revision = "03f98355ba0e"
down_revision = "9e98fbaffb88"
branch_labels = None
depends_on = None


def upgrade():
with op.batch_alter_table('tool_label_bindings', schema=None) as batch_op:
batch_op.create_unique_constraint('unique_tool_label_bind', ['tool_id', 'label_name'])
with op.batch_alter_table("tool_label_bindings", schema=None) as batch_op:
batch_op.create_unique_constraint("unique_tool_label_bind", ["tool_id", "label_name"])

with op.batch_alter_table("tool_workflow_providers", schema=None) as batch_op:
batch_op.add_column(sa.Column("label", sa.String(length=255), server_default="", nullable=False))

with op.batch_alter_table('tool_workflow_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('label', sa.String(length=255), server_default='', nullable=False))

def downgrade():
with op.batch_alter_table('tool_workflow_providers', schema=None) as batch_op:
batch_op.drop_column('label')
with op.batch_alter_table("tool_workflow_providers", schema=None) as batch_op:
batch_op.drop_column("label")

with op.batch_alter_table('tool_label_bindings', schema=None) as batch_op:
batch_op.drop_constraint('unique_tool_label_bind', type_='unique')
with op.batch_alter_table("tool_label_bindings", schema=None) as batch_op:
batch_op.drop_constraint("unique_tool_label_bind", type_="unique")
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,41 @@
Create Date: 2024-06-12 07:49:07.666510
"""

import sqlalchemy as sa
from alembic import op

import models as models

# revision identifiers, used by Alembic.
revision = '04c602f5dc9b'
down_revision = '4ff534e1eb11'
revision = "04c602f5dc9b"
down_revision = "4ff534e1eb11"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('tracing_app_configs',
sa.Column('id', models.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('app_id', models.StringUUID(), nullable=False),
sa.Column('tracing_provider', sa.String(length=255), nullable=True),
sa.Column('tracing_config', sa.JSON(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tracing_app_config_pkey')
op.create_table(
"tracing_app_configs",
sa.Column("id", models.StringUUID(), server_default=sa.text("uuid_generate_v4()"), nullable=False),
sa.Column("app_id", models.StringUUID(), nullable=False),
sa.Column("tracing_provider", sa.String(length=255), nullable=True),
sa.Column("tracing_config", sa.JSON(), nullable=True),
sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False),
sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False),
sa.PrimaryKeyConstraint("id", name="tracing_app_config_pkey"),
)
with op.batch_alter_table('tracing_app_configs', schema=None) as batch_op:
batch_op.create_index('tracing_app_config_app_id_idx', ['app_id'], unique=False)
with op.batch_alter_table("tracing_app_configs", schema=None) as batch_op:
batch_op.create_index("tracing_app_config_app_id_idx", ["app_id"], unique=False)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ##
with op.batch_alter_table('tracing_app_configs', schema=None) as batch_op:
batch_op.drop_index('tracing_app_config_app_id_idx')
with op.batch_alter_table("tracing_app_configs", schema=None) as batch_op:
batch_op.drop_index("tracing_app_config_app_id_idx")

op.drop_table('tracing_app_configs')
op.drop_table("tracing_app_configs")
# ### end Alembic commands ###
50 changes: 25 additions & 25 deletions api/migrations/versions/053da0c1d756_add_api_tool_privacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,47 @@
Create Date: 2024-01-12 06:47:21.656262
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '053da0c1d756'
down_revision = '4829e54d2fee'
revision = "053da0c1d756"
down_revision = "4829e54d2fee"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('tool_conversation_variables',
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('user_id', postgresql.UUID(), nullable=False),
sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('conversation_id', postgresql.UUID(), nullable=False),
sa.Column('variables_str', sa.Text(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_conversation_variables_pkey')
op.create_table(
"tool_conversation_variables",
sa.Column("id", postgresql.UUID(), server_default=sa.text("uuid_generate_v4()"), nullable=False),
sa.Column("user_id", postgresql.UUID(), nullable=False),
sa.Column("tenant_id", postgresql.UUID(), nullable=False),
sa.Column("conversation_id", postgresql.UUID(), nullable=False),
sa.Column("variables_str", sa.Text(), nullable=False),
sa.Column("created_at", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP(0)"), nullable=False),
sa.Column("updated_at", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP(0)"), nullable=False),
sa.PrimaryKeyConstraint("id", name="tool_conversation_variables_pkey"),
)
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('privacy_policy', sa.String(length=255), nullable=True))
batch_op.alter_column('icon',
existing_type=sa.VARCHAR(length=256),
type_=sa.String(length=255),
existing_nullable=False)
with op.batch_alter_table("tool_api_providers", schema=None) as batch_op:
batch_op.add_column(sa.Column("privacy_policy", sa.String(length=255), nullable=True))
batch_op.alter_column(
"icon", existing_type=sa.VARCHAR(length=256), type_=sa.String(length=255), existing_nullable=False
)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.alter_column('icon',
existing_type=sa.String(length=255),
type_=sa.VARCHAR(length=256),
existing_nullable=False)
batch_op.drop_column('privacy_policy')

op.drop_table('tool_conversation_variables')
with op.batch_alter_table("tool_api_providers", schema=None) as batch_op:
batch_op.alter_column(
"icon", existing_type=sa.String(length=255), type_=sa.VARCHAR(length=256), existing_nullable=False
)
batch_op.drop_column("privacy_policy")

op.drop_table("tool_conversation_variables")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@
Create Date: 2024-01-10 04:40:57.257824
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '114eed84c228'
down_revision = 'c71211c8f604'
revision = "114eed84c228"
down_revision = "c71211c8f604"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_model_invokes', schema=None) as batch_op:
batch_op.drop_column('tool_id')
with op.batch_alter_table("tool_model_invokes", schema=None) as batch_op:
batch_op.drop_column("tool_id")

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_model_invokes', schema=None) as batch_op:
batch_op.add_column(sa.Column('tool_id', postgresql.UUID(), autoincrement=False, nullable=False))
with op.batch_alter_table("tool_model_invokes", schema=None) as batch_op:
batch_op.add_column(sa.Column("tool_id", postgresql.UUID(), autoincrement=False, nullable=False))

# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,31 @@
Create Date: 2024-07-05 14:30:59.472593
"""

import sqlalchemy as sa
from alembic import op

import models as models

# revision identifiers, used by Alembic.
revision = '161cadc1af8d'
down_revision = '7e6a8693e07a'
revision = "161cadc1af8d"
down_revision = "7e6a8693e07a"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('dataset_permissions', schema=None) as batch_op:
with op.batch_alter_table("dataset_permissions", schema=None) as batch_op:
# Step 1: Add column without NOT NULL constraint
op.add_column('dataset_permissions', sa.Column('tenant_id', sa.UUID(), nullable=False))
op.add_column("dataset_permissions", sa.Column("tenant_id", sa.UUID(), nullable=False))

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('dataset_permissions', schema=None) as batch_op:
batch_op.drop_column('tenant_id')
with op.batch_alter_table("dataset_permissions", schema=None) as batch_op:
batch_op.drop_column("tenant_id")

# ### end Alembic commands ###
Loading

0 comments on commit 57aa250

Please sign in to comment.