Skip to content

Commit

Permalink
Enable string normalization in Black (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
soininen authored Apr 2, 2024
2 parents ca54884 + 2cccc95 commit a427173
Show file tree
Hide file tree
Showing 46 changed files with 535 additions and 536 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,4 @@ ignore_errors = true

[tool.black]
line-length = 120
skip-string-normalization = true
exclude = '\.git'
2 changes: 1 addition & 1 deletion spinedb_api/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# for 'autogenerate' support
import sys

sys.path = ['', '..'] + sys.path[1:]
sys.path = ["", ".."] + sys.path[1:]
from spinedb_api.helpers import create_spine_metadata

target_metadata = create_spine_metadata()
Expand Down
40 changes: 20 additions & 20 deletions spinedb_api/alembic/versions/0c7d199ae915_add_list_value_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from spinedb_api.helpers import LONGTEXT_LENGTH

# revision identifiers, used by Alembic.
revision = '0c7d199ae915'
down_revision = '7d0b467f2f4e'
revision = "0c7d199ae915"
down_revision = "7d0b467f2f4e"
branch_labels = None
depends_on = None

Expand All @@ -36,14 +36,14 @@ def upgrade():
with op.batch_alter_table("next_id") as batch_op:
batch_op.add_column(sa.Column("list_value_id", sa.Integer, server_default=sa.null()))
op.create_table(
'list_value',
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('parameter_value_list_id', sa.Integer, sa.ForeignKey("parameter_value_list.id"), nullable=False),
sa.Column('index', sa.Integer, nullable=False),
sa.Column('type', sa.String(255)),
sa.Column('value', sa.LargeBinary(LONGTEXT_LENGTH), server_default=sa.null()),
sa.Column('commit_id', sa.Integer, sa.ForeignKey("commit.id")),
sa.UniqueConstraint('parameter_value_list_id', 'index'),
"list_value",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("parameter_value_list_id", sa.Integer, sa.ForeignKey("parameter_value_list.id"), nullable=False),
sa.Column("index", sa.Integer, nullable=False),
sa.Column("type", sa.String(255)),
sa.Column("value", sa.LargeBinary(LONGTEXT_LENGTH), server_default=sa.null()),
sa.Column("commit_id", sa.Integer, sa.ForeignKey("commit.id")),
sa.UniqueConstraint("parameter_value_list_id", "index"),
)
# NOTE: At some point, by mistake, we modified ``helpers.create_new_spine_database`` by specifying a name for the fk
# that refers parameter_value_list in tool_feature_method. But since this was just a mistake, we didn't provide a
Expand All @@ -55,22 +55,22 @@ def upgrade():
x["name"]
for x in sa.inspect(conn).get_foreign_keys("tool_feature_method")
if x["referred_table"] == "parameter_value_list"
and x["referred_columns"] == ['id', 'value_index']
and x["constrained_columns"] == ['parameter_value_list_id', 'method_index']
and x["referred_columns"] == ["id", "value_index"]
and x["constrained_columns"] == ["parameter_value_list_id", "method_index"]
)
with op.batch_alter_table("tool_feature_method") as batch_op:
batch_op.drop_constraint(fk_name, type_='foreignkey')
batch_op.drop_constraint(fk_name, type_="foreignkey")
with op.batch_alter_table("parameter_value_list") as batch_op:
batch_op.drop_column('value_index')
batch_op.drop_column('value')
batch_op.drop_column("value_index")
batch_op.drop_column("value")
with op.batch_alter_table("tool_feature_method") as batch_op:
batch_op.create_foreign_key(
None,
'list_value',
['parameter_value_list_id', 'method_index'],
['parameter_value_list_id', 'index'],
onupdate='CASCADE',
ondelete='CASCADE',
"list_value",
["parameter_value_list_id", "method_index"],
["parameter_value_list_id", "index"],
onupdate="CASCADE",
ondelete="CASCADE",
)
# Add rescued data
pvl_items = list({x.id: {"id": x.id, "name": x.name, "commit_id": x.commit_id} for x in pvl}.values())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@


# revision identifiers, used by Alembic.
revision = '1892adebc00f'
down_revision = 'defbda3bf2b5'
revision = "1892adebc00f"
down_revision = "defbda3bf2b5"
branch_labels = None
depends_on = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@


# revision identifiers, used by Alembic.
revision = '1e4997105288'
down_revision = 'fbb540efbf15'
revision = "1e4997105288"
down_revision = "fbb540efbf15"
branch_labels = None
depends_on = None

Expand All @@ -34,14 +34,14 @@ def upgrade():
pvl_items = _get_pvl_items(session, Base)
# Alter tables
with op.batch_alter_table("parameter_definition") as batch_op:
batch_op.drop_column('data_type')
batch_op.drop_column("data_type")
batch_op.drop_column("default_value")
batch_op.add_column(sa.Column("default_value", sa.LargeBinary(LONGTEXT_LENGTH), server_default=sa.null()))
batch_op.add_column(sa.Column('default_type', sa.String(length=255), nullable=True))
batch_op.add_column(sa.Column("default_type", sa.String(length=255), nullable=True))
with op.batch_alter_table("parameter_value") as batch_op:
batch_op.drop_column("value")
batch_op.add_column(sa.Column("value", sa.LargeBinary(LONGTEXT_LENGTH), server_default=sa.null()))
batch_op.add_column(sa.Column('type', sa.String(length=255), nullable=True))
batch_op.add_column(sa.Column("type", sa.String(length=255), nullable=True))
with op.batch_alter_table("parameter_value_list") as batch_op:
batch_op.drop_column("value")
batch_op.add_column(sa.Column("value", sa.LargeBinary(LONGTEXT_LENGTH), server_default=sa.null()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@


# revision identifiers, used by Alembic.
revision = '39e860a11b05'
down_revision = '9da58d2def22'
revision = "39e860a11b05"
down_revision = "9da58d2def22"
branch_labels = None
depends_on = None

Expand Down Expand Up @@ -85,7 +85,7 @@ def alter_tables_after_update():

op.execute("UPDATE parameter_value SET alternative_id = 1")
with op.batch_alter_table("parameter_value") as batch_op:
batch_op.alter_column('alternative_id', nullable=False)
batch_op.alter_column("alternative_id", nullable=False)
batch_op.create_foreign_key(
None, "alternative", ("alternative_id",), ("id",), onupdate="CASCADE", ondelete="CASCADE"
)
Expand Down Expand Up @@ -115,9 +115,9 @@ def alter_tables_after_update():
)

with op.batch_alter_table("entity_type") as batch_op:
batch_op.alter_column('commit_id', nullable=False)
batch_op.alter_column("commit_id", nullable=False)
with op.batch_alter_table("entity_class_type") as batch_op:
batch_op.alter_column('commit_id', nullable=False)
batch_op.alter_column("commit_id", nullable=False)


def upgrade():
Expand Down Expand Up @@ -146,6 +146,6 @@ def downgrade():
batch_op.drop_column("scenario_id")
batch_op.drop_column("scenario_alternative_id")
with op.batch_alter_table("entity_type") as batch_op:
batch_op.alter_column('commit_id', nullable=True)
batch_op.alter_column("commit_id", nullable=True)
with op.batch_alter_table("entity_class_type") as batch_op:
batch_op.alter_column('commit_id', nullable=True)
batch_op.alter_column("commit_id", nullable=True)
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@


# revision identifiers, used by Alembic.
revision = '5385f063bef2'
down_revision = 'ce9faa82ed59'
revision = "5385f063bef2"
down_revision = "ce9faa82ed59"
branch_labels = None
depends_on = None


def upgrade():
op.create_table(
'superclass_subclass',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('superclass_id', sa.Integer(), nullable=False),
sa.Column('subclass_id', sa.Integer(), nullable=False),
"superclass_subclass",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("superclass_id", sa.Integer(), nullable=False),
sa.Column("subclass_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
['subclass_id'],
['entity_class.id'],
name=op.f('fk_superclass_subclass_subclass_id_entity_class'),
onupdate='CASCADE',
ondelete='CASCADE',
["subclass_id"],
["entity_class.id"],
name=op.f("fk_superclass_subclass_subclass_id_entity_class"),
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
['superclass_id'],
['entity_class.id'],
name=op.f('fk_superclass_subclass_superclass_id_entity_class'),
onupdate='CASCADE',
ondelete='CASCADE',
["superclass_id"],
["entity_class.id"],
name=op.f("fk_superclass_subclass_superclass_id_entity_class"),
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.PrimaryKeyConstraint('id', name=op.f('pk_superclass_subclass')),
sa.UniqueConstraint('subclass_id', name=op.f('uq_superclass_subclass_subclass_id')),
sa.PrimaryKeyConstraint("id", name=op.f("pk_superclass_subclass")),
sa.UniqueConstraint("subclass_id", name=op.f("uq_superclass_subclass_subclass_id")),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,97 +10,97 @@
from spinedb_api.helpers import naming_convention

# revision identifiers, used by Alembic.
revision = '6b7c994c1c61'
down_revision = '989fccf80441'
revision = "6b7c994c1c61"
down_revision = "989fccf80441"
branch_labels = None
depends_on = None


def upgrade():
op.create_table(
'entity_class_dimension',
sa.Column('entity_class_id', sa.Integer(), nullable=False),
sa.Column('dimension_id', sa.Integer(), nullable=False),
sa.Column('position', sa.Integer(), nullable=False),
"entity_class_dimension",
sa.Column("entity_class_id", sa.Integer(), nullable=False),
sa.Column("dimension_id", sa.Integer(), nullable=False),
sa.Column("position", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
['dimension_id'],
['entity_class.id'],
name=op.f('fk_entity_class_dimension_dimension_id_entity_class'),
onupdate='CASCADE',
ondelete='CASCADE',
["dimension_id"],
["entity_class.id"],
name=op.f("fk_entity_class_dimension_dimension_id_entity_class"),
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
['entity_class_id'],
['entity_class.id'],
name=op.f('fk_entity_class_dimension_entity_class_id_entity_class'),
onupdate='CASCADE',
ondelete='CASCADE',
["entity_class_id"],
["entity_class.id"],
name=op.f("fk_entity_class_dimension_entity_class_id_entity_class"),
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.PrimaryKeyConstraint('entity_class_id', 'dimension_id', 'position', name=op.f('pk_entity_class_dimension')),
sa.UniqueConstraint('entity_class_id', 'dimension_id', 'position', name='uq_entity_class_dimension'),
sa.PrimaryKeyConstraint("entity_class_id", "dimension_id", "position", name=op.f("pk_entity_class_dimension")),
sa.UniqueConstraint("entity_class_id", "dimension_id", "position", name="uq_entity_class_dimension"),
)
op.create_table(
'entity_element',
sa.Column('entity_id', sa.Integer(), nullable=False),
sa.Column('entity_class_id', sa.Integer(), nullable=False),
sa.Column('element_id', sa.Integer(), nullable=False),
sa.Column('dimension_id', sa.Integer(), nullable=False),
sa.Column('position', sa.Integer(), nullable=False),
"entity_element",
sa.Column("entity_id", sa.Integer(), nullable=False),
sa.Column("entity_class_id", sa.Integer(), nullable=False),
sa.Column("element_id", sa.Integer(), nullable=False),
sa.Column("dimension_id", sa.Integer(), nullable=False),
sa.Column("position", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
['element_id', 'dimension_id'],
['entity.id', 'entity.class_id'],
name=op.f('fk_entity_element_element_id_entity'),
onupdate='CASCADE',
ondelete='CASCADE',
["element_id", "dimension_id"],
["entity.id", "entity.class_id"],
name=op.f("fk_entity_element_element_id_entity"),
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
['entity_class_id', 'dimension_id', 'position'],
["entity_class_id", "dimension_id", "position"],
[
'entity_class_dimension.entity_class_id',
'entity_class_dimension.dimension_id',
'entity_class_dimension.position',
"entity_class_dimension.entity_class_id",
"entity_class_dimension.dimension_id",
"entity_class_dimension.position",
],
name=op.f('fk_entity_element_entity_class_id_entity_class_dimension'),
onupdate='CASCADE',
ondelete='CASCADE',
name=op.f("fk_entity_element_entity_class_id_entity_class_dimension"),
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
['entity_id', 'entity_class_id'],
['entity.id', 'entity.class_id'],
name=op.f('fk_entity_element_entity_id_entity'),
onupdate='CASCADE',
ondelete='CASCADE',
["entity_id", "entity_class_id"],
["entity.id", "entity.class_id"],
name=op.f("fk_entity_element_entity_id_entity"),
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.PrimaryKeyConstraint('entity_id', 'position', name=op.f('pk_entity_element')),
sa.PrimaryKeyConstraint("entity_id", "position", name=op.f("pk_entity_element")),
)
_persist_data()
# NOTE: some constraints are only created by the create_new_spine_database() function,
# not by the corresponding migration script. Thus we need to check before removing those constraints.
# We should avoid this in the future.
entity_class_constraints, entity_constraints = _get_constraints()
with op.batch_alter_table("entity", naming_convention=naming_convention) as batch_op:
for cname in ('uq_entity_idclass_id', 'uq_entity_idtype_idclass_id'):
for cname in ("uq_entity_idclass_id", "uq_entity_idtype_idclass_id"):
if cname in entity_constraints:
batch_op.drop_constraint(cname, type_='unique')
batch_op.drop_constraint('fk_entity_type_id_entity_type', type_='foreignkey')
batch_op.drop_column('type_id')
batch_op.drop_constraint(cname, type_="unique")
batch_op.drop_constraint("fk_entity_type_id_entity_type", type_="foreignkey")
batch_op.drop_column("type_id")
with op.batch_alter_table("entity_class", naming_convention=naming_convention) as batch_op:
for cname in ('uq_entity_class_idtype_id', 'uq_entity_class_type_idname'):
for cname in ("uq_entity_class_idtype_id", "uq_entity_class_type_idname"):
if cname in entity_class_constraints:
batch_op.drop_constraint(cname, type_='unique')
batch_op.drop_constraint('fk_entity_class_type_id_entity_class_type', type_='foreignkey')
batch_op.drop_constraint('fk_entity_class_commit_id_commit', type_='foreignkey')
batch_op.drop_column('commit_id')
batch_op.drop_column('type_id')
op.drop_table('object_class')
op.drop_table('entity_class_type')
batch_op.drop_constraint(cname, type_="unique")
batch_op.drop_constraint("fk_entity_class_type_id_entity_class_type", type_="foreignkey")
batch_op.drop_constraint("fk_entity_class_commit_id_commit", type_="foreignkey")
batch_op.drop_column("commit_id")
batch_op.drop_column("type_id")
op.drop_table("object_class")
op.drop_table("entity_class_type")
# op.drop_table('next_id')
op.drop_table('object')
op.drop_table('relationship_entity_class')
op.drop_table('relationship')
op.drop_table('entity_type')
op.drop_table('relationship_class')
op.drop_table('relationship_entity')
op.drop_table("object")
op.drop_table("relationship_entity_class")
op.drop_table("relationship")
op.drop_table("entity_type")
op.drop_table("relationship_class")
op.drop_table("relationship_entity")


def _get_constraints():
Expand Down
Loading

0 comments on commit a427173

Please sign in to comment.