Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/app/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from logging.config import fileConfig

from alembic import context
from sqlmodel import SQLModel
from app.models import SQLModel
Copy link
Collaborator Author

@avirajsingh7 avirajsingh7 Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing sqlmodel directly removes all the tables from database,
I believe alembic expect metadata from models init folder.

below are comments from env.py file

add your model's MetaData object here
for 'autogenerate' support
from myapp import mymodel
target_metadata = mymodel.Base.metadata
target_metadata = None

from sqlalchemy import engine_from_config, pool

# this is the Alembic Config object, which provides
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""add organization project setup

Revision ID: 99f4fc325617
Revises: 1a31ce608336
Create Date: 2025-03-21 20:51:00.759926

"""
from alembic import op
import sqlalchemy as sa
import sqlmodel.sql.sqltypes


# revision identifiers, used by Alembic.
revision = '99f4fc325617'
down_revision = '1a31ce608336'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('organization',
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_organization_name'), 'organization', ['name'], unique=True)
op.create_table('project',
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(length=500), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('organization_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_project_name'), 'project', ['name'], unique=False)
op.create_index(op.f('ix_project_organization_id'), 'project', ['organization_id'], unique=False)
op.create_table('projectuser',
sa.Column('project_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Uuid(), nullable=False),
sa.Column('is_admin', sa.Boolean(), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.Column('is_deleted', sa.Boolean(), nullable=False),
sa.Column('deleted_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['project_id'], ['project.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('projectuser')
op.drop_index(op.f('ix_project_organization_id'), table_name='project')
op.drop_index(op.f('ix_project_name'), table_name='project')
op.drop_table('project')
op.drop_index(op.f('ix_organization_name'), table_name='organization')
op.drop_table('organization')
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion backend/app/api/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def read_user_by_id(
dependencies=[Depends(get_current_active_superuser)],
response_model=UserPublic,
)
def update_user(
def update_user_endpoint(
*,
session: SessionDep,
user_id: uuid.UUID,
Expand Down
2 changes: 2 additions & 0 deletions backend/app/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from sqlmodel import SQLModel

from .auth import Token, TokenPayload
from .item import Item, ItemCreate, ItemPublic, ItemsPublic, ItemUpdate
from .message import Message
Expand Down
2 changes: 1 addition & 1 deletion backend/app/tests/api/routes/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_get_existing_user_permissions_error(
headers=normal_user_token_headers,
)
assert r.status_code == 403
assert r.json() == {"detail": "The user doesn't have enough privileges"}
assert r.json()["detail"] == "The user doesn't have enough privileges"


def test_create_user_existing_username(
Expand Down
Loading