-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task/WG-295-WG-179-WG-185: fix and improve projects with duplicate sy…
…stem path constraints (#216) * Update docker command * Update project update route * Refactor to remove ObservableDataProject * Fix test * Add restart nginx command * Refactor the watch method into two methods We can refresh users more often so setting that to every 30 minutes. * Add script to check projects * Rework namings of variables for iterating over users/project-users * Rename variable * Rename some variables * Rename refresh methods * Rename proj to project * Fix rename * Fix liting error * Set Access-Control-Max-Age to 86400 as mas value for Firefox Firefox had the longest max among browsers. * Refactor project creation * Add note about what project attributes can be updated * Rework migrations so that they have date and name * Improve checking script
- Loading branch information
1 parent
1f37cad
commit 7c10073
Showing
23 changed files
with
515 additions
and
363 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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
68 changes: 68 additions & 0 deletions
68
geoapi/migrations/versions/20240916_1855-968f358e102a_add_watch_variables_to_project.py
This file contains 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,68 @@ | ||
"""add_watch_variables_to_project | ||
Revision ID: 968f358e102a | ||
Revises: 4eeeeea72dbc | ||
Create Date: 2024-09-16 18:55:13.685590 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.orm import Session | ||
from geoapi.log import logger | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '968f358e102a' | ||
down_revision = '4eeeeea72dbc' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# Add new columns | ||
op.add_column('projects', sa.Column('watch_content', sa.Boolean(), nullable=True)) | ||
op.add_column('projects', sa.Column('watch_users', sa.Boolean(), nullable=True)) | ||
|
||
bind = op.get_bind() | ||
session = Session(bind=bind) | ||
|
||
try: | ||
# Query all projects and their related observable data projects in order | ||
# to set the watch_content and watch_users | ||
projects_query = sa.text(""" | ||
SELECT p.id, odp.id as odp_id, odp.watch_content | ||
FROM projects p | ||
LEFT JOIN observable_data_projects odp ON p.id = odp.project_id | ||
""") | ||
results = session.execute(projects_query) | ||
|
||
# Update projects based on the query results | ||
for project_id, odp_id, odp_watch_content in results: | ||
update_query = sa.text(""" | ||
UPDATE projects | ||
SET watch_content = :watch_content, watch_users = :watch_users | ||
WHERE id = :project_id | ||
""") | ||
session.execute(update_query, { | ||
'watch_content': odp_watch_content if odp_id is not None else False, | ||
'watch_users': odp_id is not None, | ||
'project_id': project_id | ||
}) | ||
session.commit() | ||
logger.info(f"Data migration of project/observable completed successfully") | ||
|
||
except Exception as e: | ||
session.rollback() | ||
logger.exception(f"An error occurred during project/observable data migration: {str(e)}") | ||
raise | ||
finally: | ||
session.close() | ||
|
||
# Drop the unique constraint | ||
op.drop_constraint('observable_data_projects_system_id_path_key', 'observable_data_projects') | ||
|
||
|
||
def downgrade(): | ||
op.drop_column('projects', 'watch_users') | ||
op.drop_column('projects', 'watch_content') | ||
op.create_unique_constraint('observable_data_projects_system_id_path_key', 'observable_data_projects', ['system_id', 'path']) |
This file contains 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 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 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.