-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/alembic migrations #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8015cde
fix: Delete alembic.ini
8775c79
chore: add alembic.ini into .gitignore
746c201
chore: update alembic scheme
d4e6317
fix: Remove the backup key from config.py
31a0067
fix: Fix the SECRET_KEY test environment variable
d9e270b
fix(auth): Fixing a missing SECRET_KEY error in .env
271d79a
fix(tests): Fix E401 [*] Multiple imports on one line
b763bf5
feat(config): Add a check for the absence of DATABSE_URL in .env
422bacc
Add a database engine to lifespan's fastapi
deb9426
refactor: Move session factory to lifespan
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -16,4 +16,5 @@ cloudflared.deb | |
| .ruff_cache | ||
| .gigaide | ||
| coverage.xml | ||
| .coverage | ||
| .coverage | ||
| alembic.ini | ||
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains hidden or 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,102 @@ | ||
| """v0.0.1 | ||
|
|
||
| Revision ID: 4972fe91500d | ||
| Revises: 001 | ||
| Create Date: 2026-05-31 17:00:41.411887 | ||
|
|
||
| """ | ||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = '4972fe91500d' | ||
| down_revision: Union[str, Sequence[str], None] = '001' | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Upgrade schema.""" | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.create_table('bans', | ||
| sa.Column('id', sa.Integer(), nullable=False), | ||
| sa.Column('reason', sa.String(length=150), nullable=False, comment='Причина бана'), | ||
| sa.Column('user_id', sa.Integer(), nullable=False, comment='ID пользователя, который получил бан'), | ||
| sa.Column('banned_by', sa.Integer(), nullable=False, comment='Тот, кто выдал бан'), | ||
| sa.Column('revoked_by', sa.Integer(), nullable=True, comment='Тот, кто снял бан'), | ||
| sa.Column('banned_at', sa.DateTime(timezone=True), nullable=False), | ||
| sa.Column('expires_at', sa.DateTime(timezone=True), nullable=True, comment='Время окончания бана'), | ||
| sa.Column('revoked_at', sa.DateTime(timezone=True), nullable=True, comment='Время отмены бана'), | ||
| sa.Column('revoked_reason', sa.String(length=150), nullable=True, comment='Причина отмены бана'), | ||
| sa.CheckConstraint('expires_at IS NULL OR expires_at > banned_at', name='ck_ban_expires_after_banned'), | ||
| sa.CheckConstraint('revoked_at IS NULL OR (revoked_at >= banned_at AND (expires_at IS NULL OR revoked_at <= expires_at))', name='ck_ban_revoke_logic'), | ||
| sa.ForeignKeyConstraint(['banned_by'], ['users.id'], ), | ||
| sa.ForeignKeyConstraint(['revoked_by'], ['users.id'], ), | ||
| sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), | ||
| sa.PrimaryKeyConstraint('id') | ||
| ) | ||
| op.create_index(op.f('ix_bans_banned_by'), 'bans', ['banned_by'], unique=False) | ||
| op.create_index(op.f('ix_bans_revoked_by'), 'bans', ['revoked_by'], unique=False) | ||
| op.create_index(op.f('ix_bans_user_id'), 'bans', ['user_id'], unique=False) | ||
| op.create_index('uq_active_ban', 'bans', ['user_id'], unique=True, postgresql_where=sa.text('revoked_at IS NULL AND (expires_at IS NULL OR expires_at > now())')) | ||
| op.alter_column('appointments', 'comment', | ||
| existing_type=sa.VARCHAR(length=1200), | ||
| nullable=False) | ||
| op.add_column('magic_tokens', sa.Column('user_id', sa.Integer(), nullable=True)) | ||
| op.create_foreign_key(None, 'magic_tokens', 'users', ['user_id'], ['id']) | ||
| op.alter_column('services', 'description', | ||
| existing_type=sa.VARCHAR(length=2000), | ||
| nullable=False) | ||
| op.alter_column('services', 'address', | ||
| existing_type=sa.VARCHAR(length=100), | ||
| nullable=False) | ||
| op.add_column('users', sa.Column('user_role', sa.Enum('user', 'admin', 'moderator'), nullable=False)) | ||
| op.alter_column('users', 'email', | ||
| existing_type=sa.VARCHAR(length=50), | ||
| nullable=False) | ||
| op.drop_constraint(op.f('users_phone_key'), 'users', type_='unique') | ||
| op.drop_constraint(op.f('users_telegram_id_key'), 'users', type_='unique') | ||
| op.drop_index(op.f('ix_users_email'), table_name='users') | ||
| op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True) | ||
| op.drop_index(op.f('ix_users_phone'), table_name='users') | ||
| op.create_index(op.f('ix_users_phone'), 'users', ['phone'], unique=True) | ||
| op.drop_index(op.f('ix_users_telegram_id'), table_name='users') | ||
| op.create_index(op.f('ix_users_telegram_id'), 'users', ['telegram_id'], unique=True) | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| """Downgrade schema.""" | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_index(op.f('ix_users_telegram_id'), table_name='users') | ||
| op.create_index(op.f('ix_users_telegram_id'), 'users', ['telegram_id'], unique=False) | ||
| op.drop_index(op.f('ix_users_phone'), table_name='users') | ||
| op.create_index(op.f('ix_users_phone'), 'users', ['phone'], unique=False) | ||
| op.drop_index(op.f('ix_users_email'), table_name='users') | ||
| op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=False) | ||
| op.create_unique_constraint(op.f('users_telegram_id_key'), 'users', ['telegram_id'], postgresql_nulls_not_distinct=False) | ||
| op.create_unique_constraint(op.f('users_phone_key'), 'users', ['phone'], postgresql_nulls_not_distinct=False) | ||
| op.alter_column('users', 'email', | ||
| existing_type=sa.VARCHAR(length=50), | ||
| nullable=True) | ||
| op.drop_column('users', 'user_role') | ||
| op.alter_column('services', 'address', | ||
| existing_type=sa.VARCHAR(length=100), | ||
| nullable=True) | ||
| op.alter_column('services', 'description', | ||
| existing_type=sa.VARCHAR(length=2000), | ||
| nullable=True) | ||
| op.drop_constraint(None, 'magic_tokens', type_='foreignkey') | ||
|
Fl1riX marked this conversation as resolved.
|
||
| op.drop_column('magic_tokens', 'user_id') | ||
| op.alter_column('appointments', 'comment', | ||
| existing_type=sa.VARCHAR(length=1200), | ||
| nullable=True) | ||
| op.drop_index('uq_active_ban', table_name='bans', postgresql_where=sa.text('revoked_at IS NULL AND (expires_at IS NULL OR expires_at > now())')) | ||
| op.drop_index(op.f('ix_bans_user_id'), table_name='bans') | ||
| op.drop_index(op.f('ix_bans_revoked_by'), table_name='bans') | ||
| op.drop_index(op.f('ix_bans_banned_by'), table_name='bans') | ||
| op.drop_table('bans') | ||
| # ### end Alembic commands ### | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.