-
Notifications
You must be signed in to change notification settings - Fork 4
Save Apps in their own database table #373
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
Open
krokicki
wants to merge
7
commits into
main
Choose a base branch
from
apps-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
751e016
docs: fix misleading comments about job polling
krokicki dda7045
fix: rename npm config to minimum-release-age
krokicki 8ed7b8f
always use app manifest cache, update when file changes
krokicki 743171f
added gitconfig to devcontainer
krokicki 08827ff
Revert "fix: rename npm config to minimum-release-age"
krokicki b8a98b7
fix lint
krokicki 1067ec7
Merge branch 'main' into apps-improvements
allison-truhlar 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
124 changes: 124 additions & 0 deletions
124
fileglancer/alembic/versions/c4e8a7d92b15_add_user_apps_table.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,124 @@ | ||
| """add user_apps table | ||
|
|
||
| Revision ID: c4e8a7d92b15 | ||
| Revises: 20b763c28c4f | ||
| Create Date: 2026-05-24 00:00:00.000000 | ||
|
|
||
| """ | ||
| from datetime import datetime, UTC | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = 'c4e8a7d92b15' | ||
| down_revision = '20b763c28c4f' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def _parse_iso(value): | ||
| """Parse an ISO 8601 timestamp string into a naive UTC datetime. | ||
|
|
||
| Returns None if value is falsy or cannot be parsed. | ||
| """ | ||
| if not value: | ||
| return None | ||
| if isinstance(value, datetime): | ||
| return value | ||
| try: | ||
| dt = datetime.fromisoformat(str(value).replace("Z", "+00:00")) | ||
| except ValueError: | ||
| return None | ||
| if dt.tzinfo is not None: | ||
| dt = dt.astimezone(UTC).replace(tzinfo=None) | ||
| return dt | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.create_table( | ||
| 'user_apps', | ||
| sa.Column('id', sa.Integer(), primary_key=True, autoincrement=True), | ||
| sa.Column('username', sa.String(), nullable=False), | ||
| sa.Column('url', sa.String(), nullable=False), | ||
| sa.Column('manifest_path', sa.String(), nullable=False, server_default=''), | ||
| sa.Column('name', sa.String(), nullable=False), | ||
| sa.Column('description', sa.String(), nullable=True), | ||
| sa.Column('branch', sa.String(), nullable=True), | ||
| sa.Column('manifest', sa.JSON(), nullable=True), | ||
| sa.Column('added_at', sa.DateTime(), nullable=False), | ||
| sa.Column('updated_at', sa.DateTime(), nullable=True), | ||
| sa.UniqueConstraint('username', 'url', 'manifest_path', name='uq_user_app'), | ||
| ) | ||
| op.create_index('ix_user_apps_username', 'user_apps', ['username']) | ||
|
|
||
| # Data migration: move user_preferences['apps'] into user_apps rows. | ||
| user_preferences = sa.table( | ||
| 'user_preferences', | ||
| sa.column('id', sa.Integer), | ||
| sa.column('username', sa.String), | ||
| sa.column('key', sa.String), | ||
| sa.column('value', sa.JSON), | ||
| ) | ||
| user_apps = sa.table( | ||
| 'user_apps', | ||
| sa.column('username', sa.String), | ||
| sa.column('url', sa.String), | ||
| sa.column('manifest_path', sa.String), | ||
| sa.column('name', sa.String), | ||
| sa.column('description', sa.String), | ||
| sa.column('branch', sa.String), | ||
| sa.column('manifest', sa.JSON), | ||
| sa.column('added_at', sa.DateTime), | ||
| sa.column('updated_at', sa.DateTime), | ||
| ) | ||
|
|
||
| conn = op.get_bind() | ||
| rows = conn.execute( | ||
| sa.select( | ||
| user_preferences.c.id, | ||
| user_preferences.c.username, | ||
| user_preferences.c.value, | ||
| ).where(user_preferences.c.key == 'apps') | ||
| ).fetchall() | ||
|
|
||
| now = datetime.now(UTC).replace(tzinfo=None) | ||
| seen: set[tuple[str, str, str]] = set() | ||
| inserts = [] | ||
| for _pref_id, username, value in rows: | ||
| app_list = (value or {}).get('apps', []) if isinstance(value, dict) else [] | ||
| for entry in app_list: | ||
| if not isinstance(entry, dict): | ||
| continue | ||
| url = entry.get('url') | ||
| if not url: | ||
| continue | ||
| manifest_path = entry.get('manifest_path') or '' | ||
| key = (username, url, manifest_path) | ||
| if key in seen: | ||
| continue | ||
| seen.add(key) | ||
| inserts.append({ | ||
| 'username': username, | ||
| 'url': url, | ||
| 'manifest_path': manifest_path, | ||
| 'name': entry.get('name') or 'Unknown', | ||
| 'description': entry.get('description'), | ||
| 'branch': None, | ||
| 'manifest': None, | ||
| 'added_at': _parse_iso(entry.get('added_at')) or now, | ||
| 'updated_at': _parse_iso(entry.get('updated_at')), | ||
| }) | ||
|
|
||
| if inserts: | ||
| conn.execute(user_apps.insert(), inserts) | ||
|
|
||
| conn.execute( | ||
| user_preferences.delete().where(user_preferences.c.key == 'apps') | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_index('ix_user_apps_username', table_name='user_apps') | ||
| op.drop_table('user_apps') |
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.
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.
I'm finding the added code/overall flow of
submit_jobto be a little confusing. The YAML manifest is read from cache (fallback to disk) at the very start of this function, but then the repo code itself is confirmed to be cached (and re-pulled if the user selects thepull_latestoption, setting it totrue) later, at which point it's checked again whether the manifest was updated? It seems that maybe the repo cache should also be checked at the beginning, and the manifest updated ifpull_latest=trueat that point. I'm also finding the logic of the if/else statement under the #clone/pull repo into the user's cache comment hard to follow - I'm not clear why one branch sets thecd_suffixto one value and also how the value ofpulled_manifest_repois determined.