-
Notifications
You must be signed in to change notification settings - Fork 19
Implement graceful move+migration of Facade repo path calculation #497
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 all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0e2cdc9
add some database IO functions to lib.py for this
MoralCode 6978bcb
add new column to operations table for this
MoralCode 8652e21
set clone path when fetching a new repo
MoralCode 1c0927e
use new clone path function to get the path to an existing repo in th…
MoralCode fa098ba
deprecate the old function
MoralCode 68a85ea
swap uses of path fetching function
MoralCode b709d7f
commit the new helpers file
MoralCode bb5732d
add comments to repo path and name tables to indicate their status as…
MoralCode aab9eee
print complete paths if the absolute clone path function throws an ex…
MoralCode 01ed453
Bug fixes from AI code review
MoralCode 5ebe29f
update docs for new facade path resolution and other misc things
MoralCode 8eb003b
fix typo
MoralCode 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
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
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
53 changes: 53 additions & 0 deletions
53
collectoss/application/schema/alembic/versions/45_add_facade_path_column.py
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,53 @@ | ||
| """add facade path column | ||
|
|
||
| Revision ID: 45 | ||
| Revises: 44 | ||
| Create Date: 2026-09-28 11:44:57.974030 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = '45' | ||
| down_revision = '44' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.add_column('collection_status', sa.Column('facade_clone_path', sa.String(), nullable=True), schema='operations') | ||
| op.alter_column('repo', 'repo_path', | ||
| existing_type=sa.VARCHAR(), | ||
| comment='deprecated by the addition of facade_clone_path in the collection_status table', | ||
| existing_nullable=True, | ||
| existing_server_default=sa.text("'NULL'::character varying"), | ||
| schema='data') | ||
| op.alter_column('repo', 'repo_name', | ||
| existing_type=sa.VARCHAR(), | ||
| comment='the current repo name', | ||
| existing_nullable=True, | ||
| existing_server_default=sa.text("'NULL'::character varying"), | ||
| schema='data') | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.alter_column('repo', 'repo_name', | ||
| existing_type=sa.VARCHAR(), | ||
| comment=None, | ||
| existing_comment='the current repo name', | ||
| existing_nullable=True, | ||
| existing_server_default=sa.text("'NULL'::character varying"), | ||
| schema='data') | ||
| op.alter_column('repo', 'repo_path', | ||
| existing_type=sa.VARCHAR(), | ||
| comment=None, | ||
| existing_comment='deprecated by the addition of facade_clone_path in the collection_status table', | ||
| existing_nullable=True, | ||
| existing_server_default=sa.text("'NULL'::character varying"), | ||
| schema='data') | ||
| op.drop_column('collection_status', 'facade_clone_path', schema='operations') | ||
| # ### 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
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
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
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
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
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
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,59 @@ | ||
| from pathlib import Path | ||
|
|
||
| from collectoss.application.db.lib import get_clone_path_by_repo_id, get_repo_by_repo_id, set_clone_path_by_repo_id | ||
|
|
||
| def is_git_repo(path:Path) -> bool: | ||
| if not path.exists(): | ||
| return False | ||
|
|
||
| gitdir = path.joinpath(".git") | ||
| if not gitdir.exists(): | ||
| return False | ||
| return True | ||
|
|
||
| def get_absolute_clone_path(facade_base_directory: str | Path, repo_id: int) -> Path: | ||
| """Returns the absolute path to the clone of the repo on disk | ||
|
|
||
| This method tries several methods to get the clone path and will automatically | ||
| update the database with the correct path if a less-than-ideal method is used. | ||
|
|
||
| This method expects that the clone directory already exists. | ||
| See `git_repo_initialize` for the method that creates the clone directory. | ||
|
|
||
| Args: | ||
| facade_base_directory (str): the configured base directory that all facade clones paths are relative to | ||
| repo_id (int): the id of the repo to get the clone path for | ||
| """ | ||
|
|
||
| base_dir = Path(facade_base_directory) | ||
|
|
||
| # check if [configured facade base dir] + [path from db operations table] exists and is a git repo (happy path/ideal case) | ||
| clone_path = get_clone_path_by_repo_id(repo_id) | ||
| if clone_path and is_git_repo(base_dir.joinpath(clone_path)): | ||
| return base_dir.joinpath(clone_path) | ||
| # if not, use the current path building technique ( [configured facade base dir] + [path from db data table] + [repo name]). if success, rewrite the facade path and return it | ||
| repo = get_repo_by_repo_id(repo_id) | ||
|
|
||
| # absolute_path = get_absolute_repo_path(base_dir, repo.repo_id, repo.repo_path,repo.repo_name) | ||
| legacy_path = f"{repo_id}-{repo.repo_path}/{repo.repo_name}" | ||
| if legacy_path and is_git_repo(base_dir.joinpath(legacy_path)): | ||
| set_clone_path_by_repo_id(repo_id, legacy_path) | ||
| return base_dir.joinpath(legacy_path) | ||
|
|
||
| # if not, discover it (check just the facade path from step 1, if it contains just one dir, use that and update the database else fail) | ||
| discover_path = base_dir.joinpath(f"{repo_id}-{repo.repo_path}") | ||
| discovered_directories = [] | ||
| if discover_path.exists(): | ||
| discovered_directories = [x for x in discover_path.iterdir() if x.is_dir()] | ||
| if len(discovered_directories) == 1 and is_git_repo(discover_path.joinpath(discovered_directories[0])): | ||
| discovered_repo = discovered_directories[0] # already an absolute Path | ||
| set_clone_path_by_repo_id(repo_id, str(discovered_repo.relative_to(base_dir))) | ||
| return discovered_repo | ||
|
|
||
|
|
||
| raise ValueError(f"""No valid git repo path found for repo {repo_id} ({repo.repo_git}). | ||
| Attempted paths: | ||
| - {base_dir.joinpath(clone_path) if clone_path else '(not set)'} | ||
| - {base_dir.joinpath(legacy_path)} | ||
| - {discover_path} ({len(discovered_directories)} children) | ||
| """) |
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
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.
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.