-
Notifications
You must be signed in to change notification settings - Fork 1
Entity management #17
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
6 commits
Select commit
Hold shift + click to select a range
ee99153
Checkpoint
CannonLock 4dada87
Add Managed endpoints
CannonLock 6063845
Merge branch 'main' into entity-management
CannonLock 6bec26f
Potential fix for pull request finding
CannonLock 53f9d29
Fix user project managed_by defaults
Copilot 7fee2a2
Update enum and fix group listing test
CannonLock 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
186 changes: 186 additions & 0 deletions
186
alembic/versions/f2ec55925c4c_external_management_update.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,186 @@ | ||
| """External management update | ||
|
|
||
| Revision ID: f2ec55925c4c | ||
| Revises: 47f8adc9859b | ||
| Create Date: 2026-05-15 12:54:31.384728 | ||
|
|
||
| """ | ||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| from sqlalchemy.dialects import postgresql | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = 'f2ec55925c4c' | ||
| down_revision: Union[str, Sequence[str], None] = '47f8adc9859b' | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
| entity_manager_enum = postgresql.ENUM('APPLICATION', 'MANIFEST', 'MORGRIDGE_AD', name='entity_manager_enum', create_type=False) | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Upgrade schema.""" | ||
| bind = op.get_bind() | ||
| entity_manager_enum.create(bind, checkfirst=True) | ||
|
|
||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.add_column('user_groups', sa.Column('managed_by', entity_manager_enum, nullable=False, server_default='APPLICATION')) | ||
| op.add_column('user_groups', sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('now()'), nullable=False)) | ||
| op.add_column('user_groups', sa.Column('updated_at', sa.TIMESTAMP(), server_default=sa.text('now()'), nullable=False)) | ||
| op.create_index('idx_user_group_managed_by', 'user_groups', ['group_id', 'managed_by', 'user_id'], unique=False) | ||
| op.add_column('user_projects', sa.Column('managed_by', entity_manager_enum, nullable=False, server_default='APPLICATION')) | ||
| op.add_column('user_projects', sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('now()'), nullable=False)) | ||
| op.add_column('user_projects', sa.Column('updated_at', sa.TIMESTAMP(), server_default=sa.text('now()'), nullable=False)) | ||
| op.create_index('idx_user_project_managed_by', 'user_projects', ['project_id', 'managed_by', 'user_id'], unique=False) | ||
| op.add_column('users', sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('now()'), nullable=False)) | ||
| op.add_column('users', sa.Column('updated_at', sa.TIMESTAMP(), server_default=sa.text('now()'), nullable=False)) | ||
| # ### end Alembic commands ### | ||
|
|
||
| # ### commands generated by human ### | ||
| op.execute('DROP VIEW IF EXISTS joined_projects') | ||
| op.execute(""" | ||
| CREATE VIEW joined_projects AS | ||
| SELECT | ||
| u.id, | ||
| p.id AS project_id, | ||
| p.name AS project_name, | ||
| p.staff1 AS project_staff1, | ||
| p.staff2 AS project_staff2, | ||
| p.status AS project_status, | ||
| p.last_contact AS project_last_contact, | ||
| p.accounting_group AS project_accounting_group, | ||
| up.is_primary AS is_primary, | ||
| up.managed_by, | ||
| up.created_at, | ||
| up.updated_at, | ||
| u.name, | ||
| u.username, | ||
| u.email1, | ||
| u.email2, | ||
| u.netid, | ||
| u.netid_exp_datetime, | ||
| u.phone1, | ||
| u.phone2, | ||
| u.is_admin, | ||
| u.active, | ||
| u.date, | ||
| u.unix_uid, | ||
| u.position, | ||
| up.role, | ||
| ( | ||
| SELECT n.ticket | ||
| FROM notes n | ||
| LEFT JOIN user_notes un ON n.id = un.note_id | ||
| WHERE un.user_id = up.user_id AND un.project_id = up.project_id | ||
| ORDER BY n.id DESC | ||
| LIMIT 1 | ||
| ) AS last_note_ticket | ||
| FROM user_projects up | ||
| JOIN users u ON up.user_id = u.id | ||
| JOIN projects p ON up.project_id = p.id | ||
| """) | ||
| op.execute(""" | ||
| CREATE OR REPLACE VIEW group_users AS | ||
| SELECT | ||
| ug.group_id, | ||
| ug.user_id, | ||
| ug.managed_by, | ||
| ug.created_at, | ||
| ug.updated_at, | ||
| u.name, | ||
| u.netid, | ||
| u.username, | ||
| u.is_admin, | ||
| u.active, | ||
| u.unix_uid | ||
| FROM user_groups ug | ||
| JOIN users u ON ug.user_id = u.id | ||
| """) | ||
| op.execute(""" | ||
| CREATE VIEW user_group_memberships AS | ||
| SELECT | ||
| ug.group_id, | ||
| ug.user_id, | ||
| ug.managed_by, | ||
| ug.created_at, | ||
| ug.updated_at, | ||
| g.name, | ||
| g.point_of_contact, | ||
| g.unix_gid, | ||
| g.has_groupdir | ||
| FROM user_groups ug | ||
| JOIN groups g ON ug.group_id = g.id | ||
| """) | ||
| # Update the created_at date to the previous date field value | ||
| op.execute("UPDATE users SET created_at = date WHERE date IS NOT NULL") | ||
| # ### end commands generated by human ### | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| """Downgrade schema.""" | ||
| # ### commands generated by human ### | ||
| op.execute("DROP VIEW IF EXISTS user_group_memberships") | ||
| op.execute("DROP VIEW IF EXISTS group_users") | ||
| op.execute("DROP VIEW IF EXISTS joined_projects") | ||
| # ### end commands generated by human ### | ||
|
|
||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_column('users', 'updated_at') | ||
| op.drop_column('users', 'created_at') | ||
| op.drop_index('idx_user_project_managed_by', table_name='user_projects') | ||
| op.drop_column('user_projects', 'updated_at') | ||
| op.drop_column('user_projects', 'created_at') | ||
| op.drop_column('user_projects', 'managed_by') | ||
| op.drop_index('idx_user_group_managed_by', table_name='user_groups') | ||
| op.drop_column('user_groups', 'updated_at') | ||
| op.drop_column('user_groups', 'created_at') | ||
| op.drop_column('user_groups', 'managed_by') | ||
| # ### end Alembic commands ### | ||
|
|
||
| # ### commands generated by human ### | ||
| op.execute(""" | ||
| CREATE VIEW joined_projects AS | ||
| SELECT | ||
| u.id, | ||
| p.id AS project_id, | ||
| p.name AS project_name, | ||
| p.staff1 AS project_staff1, | ||
| p.staff2 AS project_staff2, | ||
| p.status AS project_status, | ||
| p.last_contact AS project_last_contact, | ||
| p.accounting_group AS project_accounting_group, | ||
| up.is_primary AS is_primary, | ||
| u.name, | ||
| u.username, | ||
| u.email1, | ||
| u.email2, | ||
| u.netid, | ||
| u.netid_exp_datetime, | ||
| u.phone1, | ||
| u.phone2, | ||
| u.is_admin, | ||
| u.active, | ||
| u.date, | ||
| u.unix_uid, | ||
| u.position, | ||
| up.role, | ||
| ( | ||
| SELECT n.ticket | ||
| FROM notes n | ||
| LEFT JOIN user_notes un ON n.id = un.note_id | ||
| WHERE un.user_id = up.user_id AND un.project_id = up.project_id | ||
| ORDER BY n.id DESC | ||
| LIMIT 1 | ||
| ) AS last_note_ticket | ||
| FROM user_projects up | ||
| JOIN users u ON up.user_id = u.id | ||
| JOIN projects p ON up.project_id = p.id | ||
| """) | ||
| # ### end commands generated by human ### | ||
|
|
||
| bind = op.get_bind() | ||
| entity_manager_enum.drop(bind, checkfirst=True) | ||
|
|
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,9 @@ | ||
| from fastapi import APIRouter | ||
|
|
||
| from .manifest import router as manifest_router | ||
| from .morgridge_ad import router as morgridge_ad_router | ||
|
|
||
| router = APIRouter(prefix="/managed") | ||
| router.include_router(manifest_router) | ||
| router.include_router(morgridge_ad_router) | ||
|
|
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.