-
Notifications
You must be signed in to change notification settings - Fork 10
Collection: making the module provider agnostic #508
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
Changes from all commits
b796486
a2b0c49
7648f48
946e7c7
2b4a063
cd24f2c
3906faa
6ef49f4
57273d0
23c9685
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ on: | |
|
|
||
| jobs: | ||
| build: | ||
| if: false | ||
| runs-on: ubuntu-latest | ||
| environment: AWS_ENV_VARS | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,109 @@ | ||||||||||
| """extend collection table for provider agnostic support | ||||||||||
|
|
||||||||||
| Revision ID: 041 | ||||||||||
| Revises: 040 | ||||||||||
| Create Date: 2026-01-15 16:53:19.495583 | ||||||||||
|
|
||||||||||
| """ | ||||||||||
| from alembic import op | ||||||||||
| import sqlalchemy as sa | ||||||||||
| import sqlmodel.sql.sqltypes | ||||||||||
| from sqlalchemy.dialects import postgresql | ||||||||||
|
|
||||||||||
|
|
||||||||||
| # revision identifiers, used by Alembic. | ||||||||||
| revision = "041" | ||||||||||
| down_revision = "040" | ||||||||||
| branch_labels = None | ||||||||||
| depends_on = None | ||||||||||
|
|
||||||||||
| provider_type = postgresql.ENUM( | ||||||||||
| "OPENAI", | ||||||||||
| # aws | ||||||||||
| # gemini | ||||||||||
| name="providertype", | ||||||||||
| create_type=False, | ||||||||||
| ) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def upgrade(): | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add return type hints to migration functions. Required by the repo’s Python typing guidelines. ✍️ Suggested update-def upgrade():
+def upgrade() -> None:
@@
-def downgrade():
+def downgrade() -> None:Also applies to: 74-74 🤖 Prompt for AI Agents |
||||||||||
| provider_type.create(op.get_bind(), checkfirst=True) | ||||||||||
| op.add_column( | ||||||||||
| "collection", | ||||||||||
| sa.Column( | ||||||||||
| "provider", | ||||||||||
| provider_type, | ||||||||||
| nullable=False, | ||||||||||
| comment="LLM provider used for this collection", | ||||||||||
| ), | ||||||||||
| ) | ||||||||||
| op.execute("UPDATE collection SET provider = 'OPENAI' WHERE provider IS NULL") | ||||||||||
|
Comment on lines
+31
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "041_extend_collection_table_for_provider_*.py" -type fRepository: ProjectTech4DevAI/kaapi-backend Length of output: 150 🏁 Script executed: find backend -name "*.py" -path "*alembic/versions*" | grep -i providerRepository: ProjectTech4DevAI/kaapi-backend Length of output: 225 🏁 Script executed: ls -la backend/app/alembic/versions/ 2>/dev/null | head -20Repository: ProjectTech4DevAI/kaapi-backend Length of output: 1587 🏁 Script executed: find . -type d -name versionsRepository: ProjectTech4DevAI/kaapi-backend Length of output: 105 🏁 Script executed: git ls-files | grep -i alembic | grep -i version | head -20Repository: ProjectTech4DevAI/kaapi-backend Length of output: 1328 🏁 Script executed: find . -name "*041*" -type f 2>/dev/nullRepository: ProjectTech4DevAI/kaapi-backend Length of output: 150 🏁 Script executed: rg "extend_collection_table_for_provider" -lRepository: ProjectTech4DevAI/kaapi-backend Length of output: 57 🏁 Script executed: rg "provider_type" -l | head -10Repository: ProjectTech4DevAI/kaapi-backend Length of output: 286 🏁 Script executed: git ls-files | grep alembicRepository: ProjectTech4DevAI/kaapi-backend Length of output: 2986 🏁 Script executed: rg "op.add_column.*provider" -A 5 -B 2Repository: ProjectTech4DevAI/kaapi-backend Length of output: 57 🏁 Script executed: rg 'UPDATE collection SET provider' -B 5 -A 2Repository: ProjectTech4DevAI/kaapi-backend Length of output: 923 🏁 Script executed: ls -laRepository: ProjectTech4DevAI/kaapi-backend Length of output: 1555 🏁 Script executed: git ls-files | wc -lRepository: ProjectTech4DevAI/kaapi-backend Length of output: 78 🏁 Script executed: git ls-files | grep -E "\.py$" | grep -i migration | head -20Repository: ProjectTech4DevAI/kaapi-backend Length of output: 57 🌐 Web query:
💡 Result: Problem
Safe solutions (pick one)
Notes and gotchas
Concise Alembic examples
References If you want, tell me your DB (Postgres/MySQL/SQLite) and I’ll produce a migration file tuned to it. 🏁 Script executed: cat -n backend/app/alembic/versions/041_extend_collection_table_for_provider_.pyRepository: ProjectTech4DevAI/kaapi-backend Length of output: 3797 🏁 Script executed: wc -l backend/app/alembic/versions/041_extend_collection_table_for_provider_.pyRepository: ProjectTech4DevAI/kaapi-backend Length of output: 152 🏁 Script executed: cat backend/app/alembic/versions/041_extend_collection_table_for_provider_.pyRepository: ProjectTech4DevAI/kaapi-backend Length of output: 3034 🏁 Script executed: cat backend/app/alembic/versions/012_added_provider_column_to_the_credential_.pyRepository: ProjectTech4DevAI/kaapi-backend Length of output: 2468 🏁 Script executed: head -100 backend/app/alembic/versions/041_extend_collection_table_for_provider_.pyRepository: ProjectTech4DevAI/kaapi-backend Length of output: 2693 Fix migration failure risk: non-nullable On tables with existing rows, the ADD COLUMN with Additionally, the 🔧 Suggested migration fix op.add_column(
"collection",
sa.Column(
"provider",
provider_type,
nullable=False,
+ server_default="OPENAI",
comment="LLM provider used for this collection",
),
)
op.execute("UPDATE collection SET provider = 'OPENAI' WHERE provider IS NULL")
+ op.alter_column(
+ "collection",
+ "provider",
+ server_default=None,
+ existing_type=provider_type,
+ )Also add return type hints: -def upgrade():
+def upgrade() -> None:
-def downgrade():
+def downgrade() -> None:🤖 Prompt for AI Agents |
||||||||||
| op.add_column( | ||||||||||
| "collection", | ||||||||||
| sa.Column( | ||||||||||
| "name", | ||||||||||
| sqlmodel.sql.sqltypes.AutoString(), | ||||||||||
| nullable=True, | ||||||||||
| comment="Name of the collection", | ||||||||||
| ), | ||||||||||
| ) | ||||||||||
| op.add_column( | ||||||||||
| "collection", | ||||||||||
| sa.Column( | ||||||||||
| "description", | ||||||||||
| sqlmodel.sql.sqltypes.AutoString(), | ||||||||||
| nullable=True, | ||||||||||
| comment="Description of the collection", | ||||||||||
| ), | ||||||||||
| ) | ||||||||||
| op.alter_column( | ||||||||||
| "collection", | ||||||||||
| "llm_service_name", | ||||||||||
| existing_type=sa.VARCHAR(), | ||||||||||
| comment="Name of the LLM service", | ||||||||||
| existing_comment="Name of the LLM service provider", | ||||||||||
| existing_nullable=False, | ||||||||||
| ) | ||||||||||
| op.create_unique_constraint(None, "collection", ["name"]) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: fd -t f "041_extend_collection_table_for_provider_" backend/Repository: ProjectTech4DevAI/kaapi-backend Length of output: 148 🏁 Script executed: find . -path "*/alembic/versions/*" -name "*041*" -type fRepository: ProjectTech4DevAI/kaapi-backend Length of output: 150 🏁 Script executed: rg "exists_by_name" --type py -A 5Repository: ProjectTech4DevAI/kaapi-backend Length of output: 1138 🏁 Script executed: cat -n backend/app/alembic/versions/041_extend_collection_table_for_provider_.pyRepository: ProjectTech4DevAI/kaapi-backend Length of output: 3797 🏁 Script executed: rg "class Collection" --type py -A 20 backend/app/models/Repository: ProjectTech4DevAI/kaapi-backend Length of output: 8074 🏁 Script executed: cat -n backend/app/models/collection.py | head -60Repository: ProjectTech4DevAI/kaapi-backend Length of output: 2376 🏁 Script executed: rg "project_id" backend/app/models/collection.py -B 2 -A 2Repository: ProjectTech4DevAI/kaapi-backend Length of output: 338 🏁 Script executed: cat -n backend/app/models/collection.py | sed -n '50,75p'Repository: ProjectTech4DevAI/kaapi-backend Length of output: 1212 🏁 Script executed: rg "unique=True" backend/app/models/collection.py -B 5 -A 5Repository: ProjectTech4DevAI/kaapi-backend Length of output: 428 🏁 Script executed: rg "Collection.name" --type py -B 3 -A 3 backend/Repository: ProjectTech4DevAI/kaapi-backend Length of output: 656 🏁 Script executed: rg "unique_together\|UniqueConstraint" --type py backend/app/models/collection.pyRepository: ProjectTech4DevAI/kaapi-backend Length of output: 57 🏁 Script executed: rg "Index\|unique" backend/app/models/collection.pyRepository: ProjectTech4DevAI/kaapi-backend Length of output: 57 🏁 Script executed: python3 << 'EOF'
# Check if there are any other constraints or indexes defined
import ast
import sys
with open('backend/app/models/collection.py', 'r') as f:
content = f.read()
# Search for __table_args__ or similar constraint definitions
if '__table_args__' in content:
print("Found __table_args__ definition")
lines = content.split('\n')
for i, line in enumerate(lines):
if '__table_args__' in line:
print(f"Line {i+1}: {line}")
for j in range(1, 10):
if i+j < len(lines):
print(f"Line {i+j+1}: {lines[i+j]}")
else:
print("No __table_args__ found")
# Also check for other constraint patterns
if 'UniqueConstraint' in content or 'Index' in content:
print("\nFound constraint/index patterns")
EOFRepository: ProjectTech4DevAI/kaapi-backend Length of output: 161 🏁 Script executed: # Check if there's a previous migration that might have already defined a unique constraint differently
git log --oneline backend/app/alembic/versions/ | head -20Repository: ProjectTech4DevAI/kaapi-backend Length of output: 121 🏁 Script executed: # Check for any other usages or assumptions about name uniqueness
rg "\.name" backend/app/crud/collection/collection.py -B 2 -A 2Repository: ProjectTech4DevAI/kaapi-backend Length of output: 286 🏁 Script executed: # Verify the Collection model fully to see if unique=True constraint is defined at field level
sed -n '22,85p' backend/app/models/collection.pyRepository: ProjectTech4DevAI/kaapi-backend Length of output: 2448 🏁 Script executed: # Check if there are any queries that might assume global name uniqueness
rg "filter.*name\|where.*name" backend/app/crud/collection/ --type py -B 1 -A 1Repository: ProjectTech4DevAI/kaapi-backend Length of output: 57 Unique constraint must include The Required constraint change- op.create_unique_constraint(None, "collection", ["name"])
+ op.create_unique_constraint(
+ "uq_collection_project_id_name", "collection", ["project_id", "name"]
+ )- op.drop_constraint("collection_name_key", "collection", type_="unique")
+ op.drop_constraint("uq_collection_project_id_name", "collection", type_="unique")Also update the Collection model to remove 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| op.drop_constraint( | ||||||||||
| op.f("collection_organization_id_fkey"), "collection", type_="foreignkey" | ||||||||||
| ) | ||||||||||
| op.drop_column("collection", "organization_id") | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def downgrade(): | ||||||||||
| op.add_column( | ||||||||||
| "collection", | ||||||||||
| sa.Column( | ||||||||||
| "organization_id", | ||||||||||
| sa.INTEGER(), | ||||||||||
| autoincrement=False, | ||||||||||
| nullable=True, | ||||||||||
| comment="Reference to the organization", | ||||||||||
| ), | ||||||||||
| ) | ||||||||||
| op.execute( | ||||||||||
| """UPDATE collection SET organization_id = (SELECT organization_id FROM project | ||||||||||
| WHERE project.id = collection.project_id)""" | ||||||||||
| ) | ||||||||||
| op.alter_column("collection", "organization_id", nullable=False) | ||||||||||
| op.create_foreign_key( | ||||||||||
| op.f("collection_organization_id_fkey"), | ||||||||||
| "collection", | ||||||||||
| "organization", | ||||||||||
| ["organization_id"], | ||||||||||
| ["id"], | ||||||||||
| ondelete="CASCADE", | ||||||||||
| ) | ||||||||||
| op.drop_constraint("collection_name_key", "collection", type_="unique") | ||||||||||
| op.alter_column( | ||||||||||
| "collection", | ||||||||||
| "llm_service_name", | ||||||||||
| existing_type=sa.VARCHAR(), | ||||||||||
| comment="Name of the LLM service provider", | ||||||||||
| existing_comment="Name of the LLM service", | ||||||||||
| existing_nullable=False, | ||||||||||
| ) | ||||||||||
| op.drop_column("collection", "description") | ||||||||||
| op.drop_column("collection", "name") | ||||||||||
| op.drop_column("collection", "provider") | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 1676
🏁 Script executed:
Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 220
🏁 Script executed:
Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 1794
🏁 Script executed:
Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 57
🏁 Script executed:
git log --oneline .github/workflows/cd-staging.yml | head -20Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 110
🏁 Script executed:
git show 23c9685:.github/workflows/cd-staging.yml | head -50Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 1354
🏁 Script executed:
git log --all --oneline -- .github/workflows/cd-staging.yml | catRepository: ProjectTech4DevAI/kaapi-backend
Length of output: 146
🏁 Script executed:
Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 1354
🏁 Script executed:
Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 146
🏁 Script executed:
git show ef56025 --stat | head -20Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 475
🏁 Script executed:
git log --all --reverse --oneline | head -5Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 146
🏁 Script executed:
Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 420
Staging CD job is disabled; confirm intent and consider using a toggleable condition.
if: falseat line 10 disables the entire staging deployment job for all main branch pushes. If this is intentional but temporary, use a repository variable to make the toggle explicit and allow re-enabling without code changes.Suggested toggle via repo variable
📝 Committable suggestion
🧰 Tools
🪛 actionlint (1.7.10)
10-10: constant expression "false" in condition. remove the if: section
(if-cond)
🤖 Prompt for AI Agents