-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b34d63
commit c7b62e5
Showing
8 changed files
with
323 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""merge heads | ||
Revision ID: a17996bd5bff | ||
Revises: c5cc3b0f01d6, f686be54aec9 | ||
Create Date: 2024-05-27 22:37:55.225109 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
import sqlmodel.sql.sqltypes | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'a17996bd5bff' | ||
down_revision = ('c5cc3b0f01d6', 'f686be54aec9') | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
pass | ||
|
||
|
||
def downgrade(): | ||
pass |
37 changes: 37 additions & 0 deletions
37
backend/app/alembic/versions/f686be54aec9_add_slug_column_with_unique_and_index_.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,37 @@ | ||
"""Add slug column with unique and index constraint in Team table | ||
Revision ID: f686be54aec9 | ||
Revises: a9b76125b71a | ||
Create Date: 2024-05-25 00:20:58.980226 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
import sqlmodel.sql.sqltypes | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'f686be54aec9' | ||
down_revision = 'a9b76125b71a' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('invitation', 'email', | ||
existing_type=sa.VARCHAR(), | ||
nullable=False) | ||
op.add_column('team', sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=False)) | ||
op.create_index(op.f('ix_team_slug'), 'team', ['slug'], unique=True) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index(op.f('ix_team_slug'), table_name='team') | ||
op.drop_column('team', 'slug') | ||
op.alter_column('invitation', 'email', | ||
existing_type=sa.VARCHAR(), | ||
nullable=True) | ||
# ### end Alembic commands ### |
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,14 @@ | ||
import secrets | ||
|
||
from sqlmodel import Session, select | ||
|
||
from app.models import Team | ||
from app.utils import slugify | ||
|
||
|
||
def verify_and_generate_slug_name(name: str, session: Session) -> str: | ||
slug_name = slugify(name) | ||
while session.exec(select(Team).where(Team.slug == slug_name)).first(): | ||
slug_name = f"{slug_name}-{secrets.token_hex(4)}" | ||
|
||
return slug_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
Oops, something went wrong.