Skip to content

Commit

Permalink
Merge 35e4fab into e991cfc
Browse files Browse the repository at this point in the history
  • Loading branch information
paulineribeyre committed Feb 22, 2023
2 parents e991cfc + 35e4fab commit f172ccd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
"filename": "migrations/versions/a04a70296688_non_unique_client_name.py",
"hashed_secret": "bb2372fb50034d559d2920e7229fb5879cf1be72",
"is_verified": false,
"line_number": 13
"line_number": 14
}
],
"migrations/versions/e4c7b0ab68d3_create_tables.py": [
Expand Down Expand Up @@ -368,5 +368,5 @@
}
]
},
"generated_at": "2023-01-26T20:09:03Z"
"generated_at": "2023-02-22T17:22:09Z"
}
19 changes: 11 additions & 8 deletions migrations/versions/a04a70296688_non_unique_client_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
from alembic import op
import logging


# revision identifiers, used by Alembic.
Expand All @@ -14,6 +15,8 @@
branch_labels = None
depends_on = None

logger = logging.getLogger("fence.alembic")


def upgrade():
# get all "unique" constraints on "client" table
Expand All @@ -24,14 +27,14 @@ def upgrade():

# filter out the constraints that are not for the "name" column; only 1 constraint should be left
name_constraints = [e[0] for e in results if "name" in e[0]]
if len(name_constraints) != 1:
raise Exception(
f"Did not find exactly one 'unique client name' constraint: {name_constraints}"
)

# the `name` does not have to be unique anymore: remove the constraint
print(f"Droppping 'unique client name' constraint: '{name_constraints[0]}'")
op.drop_constraint(name_constraints[0], "client")
logger.info(
f"Found {len(name_constraints)} 'unique client name' constraints; deleting all of them: {name_constraints}"
)

# the `name` does not have to be unique anymore: remove the constraints
for name in name_constraints:
logger.info(f"Droppping 'unique client name' constraint: '{name}'")
op.drop_constraint(name, "client")


def downgrade():
Expand Down

0 comments on commit f172ccd

Please sign in to comment.