- 
                Notifications
    You must be signed in to change notification settings 
- Fork 32
          WIP: ♻️ Use projects_nodes table instead of projects.workbench (🗃️)
          #8141
        
          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
          
     Draft
      
      
            giancarloromeo
  wants to merge
  227
  commits into
  ITISFoundation:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
giancarloromeo:is5646/use-project-nodes-table-instead-of-workbench
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
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.
          
          
      
        
          +1,863
        
        
          −1,093
        
        
          
        
      
    
  
  
     Draft
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            227 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      d2b2e6f
              
                Remove workbench column from projects_table
              
              
                giancarloromeo d78aa5c
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                giancarloromeo 47072ad
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                giancarloromeo 6cc38ae
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                giancarloromeo f6ae1d7
              
                fix: remove workbench from faker factory
              
              
                giancarloromeo 20cef27
              
                fix: remove workbench references from catalog
              
              
                giancarloromeo b9cc19c
              
                Merge branch 'master' into pr/giancarloromeo/8141
              
              
                pcrespov e920c1f
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                pcrespov 2637c2c
              
                Merge branch 'is5646/use-project-nodes-table-instead-of-workbench' of…
              
              
                pcrespov 77d26ec
              
                fixes projecst repo
              
              
                pcrespov c209c6b
              
                fixes tests modules
              
              
                pcrespov 5b7935a
              
                faker
              
              
                pcrespov 019e04b
              
                fixing nodes
              
              
                pcrespov 9c0640e
              
                fixing fakes
              
              
                pcrespov f7cf17b
              
                fixing fakes
              
              
                pcrespov 17f60de
              
                fixes update
              
              
                pcrespov 1c9de98
              
                minor
              
              
                pcrespov 764a386
              
                Merge branch 'master' into pr/giancarloromeo/8141
              
              
                pcrespov 360dcb4
              
                fixes migration tests
              
              
                pcrespov 86e02d6
              
                fixes
              
              
                pcrespov d1510e5
              
                simplified fixture
              
              
                pcrespov 791e8b3
              
                comment
              
              
                pcrespov 00370e5
              
                fix: create_node fixture
              
              
                giancarloromeo 398866c
              
                Merge branch 'is5646/use-project-nodes-table-instead-of-workbench' of…
              
              
                giancarloromeo 54028fb
              
                fix: move project_exists
              
              
                giancarloromeo 5f6f274
              
                Merge branch 'is5646/use-project-nodes-table-instead-of-workbench' of…
              
              
                pcrespov caa2799
              
                rename
              
              
                pcrespov 6615e9b
              
                rm project dependency
              
              
                pcrespov 8181580
              
                Updates Node model and cleanup
              
              
                pcrespov 7e1fb26
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                pcrespov cce82cb
              
                Merge branch 'is5646/use-project-nodes-table-instead-of-workbench' of…
              
              
                pcrespov 86846a6
              
                Merge remote-tracking branch 'upstream/master' into is5646/use-projec…
              
              
                giancarloromeo e33be86
              
                fix: use annotated functional validators
              
              
                giancarloromeo 5bce45d
              
                fix: fixtures still using workbench
              
              
                giancarloromeo a0d89e4
              
                fix: paths with problematic names
              
              
                giancarloromeo b58f26f
              
                fix: RPC tests
              
              
                giancarloromeo 2700ee6
              
                fix: minor
              
              
                giancarloromeo 14f50e6
              
                fix: frontend data generator
              
              
                giancarloromeo 43630d5
              
                fix: project_id type
              
              
                giancarloromeo 243c5e8
              
                fix: unpack created project/nodes
              
              
                giancarloromeo 427f998
              
                fix: unpack
              
              
                giancarloromeo 841593d
              
                fix: clone test
              
              
                giancarloromeo dbf42b6
              
                fix: project_nodes
              
              
                giancarloromeo 3b8a3ba
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                giancarloromeo 1adee7e
              
                fix: node names mapping
              
              
                giancarloromeo 2961b6f
              
                fix: nullable workbench
              
              
                giancarloromeo f5ae1c5
              
                fix: exclude workbench from validation
              
              
                giancarloromeo d9881a1
              
                fix: validate ignoring workbench
              
              
                giancarloromeo 1ceff4d
              
                fix: temp include workbench on a validation
              
              
                giancarloromeo a47e4c8
              
                fix: folder body
              
              
                giancarloromeo 45a07b8
              
                fix: workbench
              
              
                giancarloromeo 03acbd8
              
                fix: remove workbench
              
              
                giancarloromeo b16810c
              
                fix: workbench
              
              
                giancarloromeo 6558b5a
              
                fix: webserver
              
              
                giancarloromeo 2bc186d
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                giancarloromeo adb9897
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                giancarloromeo 67c2183
              
                fix: workbench
              
              
                giancarloromeo 6048085
              
                Merge branch 'is5646/use-project-nodes-table-instead-of-workbench' of…
              
              
                giancarloromeo 4455d50
              
                fix: use batch call
              
              
                giancarloromeo 2954940
              
                Merge remote-tracking branch 'upstream/master' into is5646/use-projec…
              
              
                giancarloromeo 0eec938
              
                storage: returns minimal tuple
              
              
                pcrespov d52d3e7
              
                proper migration project.workbench
              
              
                pcrespov 30b2b7f
              
                using insert_and_get_row
              
              
                pcrespov 38da394
              
                fixes logs
              
              
                pcrespov a0b71bb
              
                doc
              
              
                pcrespov ab0a810
              
                fix: projects states handlers
              
              
                giancarloromeo e86fe27
              
                fix: typecheck
              
              
                giancarloromeo ae80167
              
                fix: typecheck
              
              
                giancarloromeo 5dde879
              
                fix: relative import
              
              
                giancarloromeo a2a8a27
              
                fix: typecheck
              
              
                giancarloromeo f4fd950
              
                fix: extract workbench
              
              
                giancarloromeo 3a25b02
              
                fix: use workbench subquery
              
              
                giancarloromeo a4cbb9a
              
                fix: use workbench subquery
              
              
                giancarloromeo e5de7b1
              
                fix: get project with workbench
              
              
                giancarloromeo 907708b
              
                fix: imports
              
              
                giancarloromeo 3156531
              
                fix: inputs required nullability
              
              
                giancarloromeo 7b07b66
              
                fix: typecheck
              
              
                giancarloromeo 0a3d8d7
              
                fix: project cancellation
              
              
                giancarloromeo 4f43294
              
                Merge branch 'is5646/use-project-nodes-table-instead-of-workbench' of…
              
              
                pcrespov e327c6b
              
                model_dump_as_node
              
              
                pcrespov ded3e8d
              
                fixes fixture
              
              
                pcrespov 9c23c06
              
                cleanup
              
              
                pcrespov 994cc0d
              
                fixes workbench retrieval
              
              
                pcrespov 2ce1cc6
              
                fixes insert batch
              
              
                pcrespov b0f1626
              
                Merge branch 'master' into pr/giancarloromeo/8141
              
              
                pcrespov a9b80b2
              
                no need to restor workbench
              
              
                pcrespov 087ec30
              
                remove define `_projects_service.get_project_for_user`
              
              
                pcrespov 7b2639c
              
                fix: validate workbench against nodes
              
              
                giancarloromeo 1770502
              
                fix: return project with workbench when creating
              
              
                giancarloromeo 5b213c0
              
                fix: create project fixture
              
              
                giancarloromeo ea67751
              
                fix: workbench when share workpace
              
              
                giancarloromeo 9295602
              
                fix: workbench when getting workspaces
              
              
                giancarloromeo 58549f7
              
                fix: include None
              
              
                giancarloromeo 41d4182
              
                fix: extract only not nulls
              
              
                giancarloromeo 9b892c1
              
                Merge remote-tracking branch 'upstream/master' into is5646/use-projec…
              
              
                giancarloromeo 6ac876d
              
                Merge remote-tracking branch 'upstream/master' into is5646/use-projec…
              
              
                giancarloromeo d4b90ff
              
                Add trigger/function when updating project nodes
              
              
                giancarloromeo d95331f
              
                Fix script
              
              
                giancarloromeo a797222
              
                fix: delete project_node
              
              
                giancarloromeo bf033d2
              
                remove unused
              
              
                giancarloromeo c9c6a1e
              
                fix: script downgrade order
              
              
                giancarloromeo 73e8ca1
              
                fix: test
              
              
                giancarloromeo 9e0e95f
              
                fix: lastChangeDate assert
              
              
                giancarloromeo 790feaf
              
                fix: test
              
              
                giancarloromeo b81f5b2
              
                fix: node creation
              
              
                giancarloromeo f41304c
              
                typecheck
              
              
                giancarloromeo 86c5a75
              
                typecheck
              
              
                giancarloromeo b0b2667
              
                remove old
              
              
                giancarloromeo 726cdc3
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                giancarloromeo 0a16f40
              
                remove unused
              
              
                giancarloromeo fba3af1
              
                use new repo
              
              
                giancarloromeo 9a7c654
              
                remove get project
              
              
                giancarloromeo 725be27
              
                update nodes
              
              
                giancarloromeo 5e14001
              
                fix document creation
              
              
                giancarloromeo 0cecabd
              
                fix tests
              
              
                giancarloromeo f8fa9e6
              
                fix test
              
              
                giancarloromeo 8ffa91b
              
                fix tests
              
              
                giancarloromeo e5a9b5f
              
                fix
              
              
                giancarloromeo 42ee9d1
              
                fix deepdiff
              
              
                giancarloromeo 661b5a5
              
                remove tests
              
              
                giancarloromeo 325608c
              
                fix model_dump
              
              
                giancarloromeo 127e90a
              
                fix
              
              
                giancarloromeo df2e204
              
                fix test
              
              
                giancarloromeo 824200a
              
                fix int test
              
              
                giancarloromeo c69df79
              
                tests: ignore order
              
              
                giancarloromeo 6c0431f
              
                fix: inputs required
              
              
                giancarloromeo ee01c01
              
                fix: node outputs
              
              
                giancarloromeo 6a51b9a
              
                fix: more efficient  get product
              
              
                giancarloromeo 77762b3
              
                refactor: remove access to workbench
              
              
                giancarloromeo 289544c
              
                Fix bug
              
              
                matusdrobuliak66 c8d26b5
              
                Merge remote-tracking branch 'matusdrobuliak66/fix-access-rights-work…
              
              
                giancarloromeo 7db6618
              
                fix: project node states
              
              
                giancarloromeo 9fb1220
              
                fix: project states
              
              
                giancarloromeo 5757eb8
              
                fix: validator
              
              
                giancarloromeo 19834d2
              
                fix: get project with None
              
              
                giancarloromeo bbc6560
              
                fix: get project
              
              
                giancarloromeo 393e7db
              
                fix: tags
              
              
                giancarloromeo 546003f
              
                fix: workbench
              
              
                giancarloromeo 21a4ed0
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                giancarloromeo e2df3dd
              
                fix: get project response
              
              
                giancarloromeo 2f611c3
              
                Merge branch 'is5646/use-project-nodes-table-instead-of-workbench' of…
              
              
                giancarloromeo 20f70f6
              
                fix: workbench
              
              
                giancarloromeo 1319020
              
                fix: node state
              
              
                giancarloromeo bfa1685
              
                remove workbench
              
              
                giancarloromeo 044edc5
              
                fix: repo
              
              
                giancarloromeo de831c4
              
                fix: new syntax
              
              
                giancarloromeo 9dada93
              
                fix: include unset
              
              
                giancarloromeo d453f76
              
                tests: prettify deepdiff
              
              
                giancarloromeo f29cf8c
              
                fix: test
              
              
                giancarloromeo 7928dfb
              
                fix: model dump without aliases
              
              
                giancarloromeo 88c3159
              
                typecheck
              
              
                giancarloromeo d01e3c3
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                giancarloromeo 5dd1c82
              
                fix: node creation
              
              
                giancarloromeo c1826f8
              
                fix: typecheck
              
              
                giancarloromeo ae75ac1
              
                fix: node creation
              
              
                giancarloromeo 3547a21
              
                typecheck
              
              
                giancarloromeo 6104f45
              
                fix: response
              
              
                giancarloromeo 994adda
              
                fix: match
              
              
                giancarloromeo f6ba587
              
                fix: nullability
              
              
                giancarloromeo da63986
              
                fix test
              
              
                giancarloromeo 0df85db
              
                remove workbench
              
              
                giancarloromeo e9793e1
              
                fix: project creation with nodes
              
              
                giancarloromeo 198bb4b
              
                clean
              
              
                giancarloromeo 2748c5a
              
                remove unused
              
              
                giancarloromeo f4655a9
              
                remove fixme
              
              
                giancarloromeo b8c966e
              
                fix: streams
              
              
                giancarloromeo 8eabd50
              
                fix relative
              
              
                giancarloromeo a415e87
              
                fix: revert casing
              
              
                giancarloromeo 13bbe34
              
                fix random
              
              
                giancarloromeo 99c2eb7
              
                rename
              
              
                giancarloromeo 7e3bbe9
              
                fix helper
              
              
                giancarloromeo 7d71e9f
              
                fix
              
              
                giancarloromeo c946376
              
                fix
              
              
                giancarloromeo 6972a84
              
                fix
              
              
                giancarloromeo 3bf0399
              
                fix
              
              
                giancarloromeo 6f2dbf3
              
                fix warnings logs
              
              
                giancarloromeo f325339
              
                remove position
              
              
                giancarloromeo 3464789
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                giancarloromeo bb16e26
              
                fix
              
              
                giancarloromeo e918dce
              
                Merge branches 'is5646/use-project-nodes-table-instead-of-workbench' …
              
              
                giancarloromeo df073b1
              
                fix tests
              
              
                giancarloromeo 89404b9
              
                fix
              
              
                giancarloromeo 669b4a8
              
                fix
              
              
                giancarloromeo 6105bda
              
                fix logs
              
              
                giancarloromeo 22d39ed
              
                fix
              
              
                giancarloromeo 1b53a30
              
                fix
              
              
                giancarloromeo 75d7e55
              
                fix
              
              
                giancarloromeo b82302f
              
                fix
              
              
                giancarloromeo e12c40b
              
                fix
              
              
                giancarloromeo 9dfe2df
              
                revert models
              
              
                giancarloromeo 88f91f5
              
                fix: improve listing
              
              
                giancarloromeo db156e4
              
                fix: script
              
              
                giancarloromeo 6e17b80
              
                fix: connection
              
              
                giancarloromeo c5a12a0
              
                Merge remote-tracking branch 'upstream/master' into is5646/use-projec…
              
              
                giancarloromeo b7bb036
              
                fix
              
              
                giancarloromeo ec1d762
              
                fix: model dump
              
              
                giancarloromeo 5718e92
              
                try to fix
              
              
                giancarloromeo 260c4ab
              
                try to fix 2.0
              
              
                giancarloromeo cc86d53
              
                fix: workbench nulls
              
              
                giancarloromeo 413f4dc
              
                fix: test
              
              
                giancarloromeo 6780a88
              
                Merge branch 'master' into pr/giancarloromeo/8141
              
              
                pcrespov fb3179e
              
                fix: alembic
              
              
                giancarloromeo ed060af
              
                fix: typecheck
              
              
                giancarloromeo ac12cba
              
                fix: duplicate by_alias
              
              
                giancarloromeo eafc2d3
              
                updates webserver OAS
              
              
                pcrespov f9483cb
              
                fixes update node's states
              
              
                pcrespov 6b0048f
              
                fixes mypy
              
              
                pcrespov c93168a
              
                fixes test listerner
              
              
                pcrespov c66590d
              
                fixes test helper
              
              
                pcrespov f3512b3
              
                db returns None. sa.func.json_strip_nulls -> sa.func.json
              
              
                pcrespov 08f1138
              
                Merge branch 'master' into is5646/use-project-nodes-table-instead-of-…
              
              
                pcrespov fb73d03
              
                type
              
              
                pcrespov 4217743
              
                Merge branch 'master' into pr/giancarloromeo/8141
              
              
                pcrespov 7c6197d
              
                Adapts revisitons
              
              
                pcrespov 4b70868
              
                fix
              
              
                pcrespov a74ec78
              
                Merge branch 'master' into pr/giancarloromeo/8141
              
              
                pcrespov a928398
              
                Merge branch 'master' into pr/giancarloromeo/8141
              
              
                pcrespov 55da438
              
                uses adapters
              
              
                pcrespov 1e52c3c
              
                minor
              
              
                pcrespov 2ec1124
              
                bad sort
              
              
                pcrespov a4bc47c
              
                Merge branch 'master' into pr/giancarloromeo/8141
              
              
                pcrespov 22ddd71
              
                its really a float
              
              
                pcrespov 4ef9dd2
              
                updates OAS
              
              
                pcrespov 037272b
              
                updates down revision in pg migration
              
              
                pcrespov 13b42f6
              
                Merge branch 'master' into pr/giancarloromeo/8141
              
              
                pcrespov 75ccc59
              
                Merge branch 'master' into pr/giancarloromeo/8141
              
              
                pcrespov ad73dff
              
                updates migration head
              
              
                pcrespov 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
          Some comments aren't visible on the classic Files Changed page.
        
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
    
  
  
    
              
        
          
  
    
      
          
            337 changes: 337 additions & 0 deletions
          
          337 
        
  ...stgres_database/migration/versions/201aa37f4d9a_remove_workbench_column_from_projects_.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,337 @@ | ||
| """Remove workbench column from projects_table | ||
|  | ||
| Revision ID: 201aa37f4d9a | ||
| Revises: 06eafd25d004 | ||
| Create Date: 2025-07-22 19:25:42.125196+00:00 | ||
|  | ||
| """ | ||
|  | ||
| import json | ||
| from typing import Any | ||
|  | ||
| import sqlalchemy as sa | ||
| from alembic import op | ||
| from sqlalchemy.dialects import postgresql | ||
|  | ||
| # revision identifiers, used by Alembic. | ||
| revision = "201aa37f4d9a" | ||
| down_revision = "9dddb16914a4" | ||
| branch_labels = None | ||
| depends_on = None | ||
|  | ||
|  | ||
| def _migrate_workbench_to_projects_nodes() -> None: | ||
| """Migrate nodes from projects.workbench to projects_nodes table.""" | ||
|  | ||
| # Get database connection | ||
| connection = op.get_bind() | ||
|  | ||
| # Fetch all projects with workbench data | ||
| projects_result = connection.execute( | ||
| sa.text("SELECT uuid, workbench FROM projects WHERE workbench IS NOT NULL") | ||
| ) | ||
|  | ||
| errors: list[str] = [] | ||
| updated_nodes_count = 0 | ||
| inserted_nodes_count = 0 | ||
|  | ||
| for project_uuid, workbench_json in projects_result: | ||
| if not workbench_json: | ||
| continue | ||
|  | ||
| try: | ||
| workbench_data = ( | ||
| workbench_json | ||
| if isinstance(workbench_json, dict) | ||
| else json.loads(workbench_json) | ||
| ) | ||
| except (json.JSONDecodeError, TypeError) as e: | ||
| errors.append(f"Project {project_uuid}: Invalid workbench JSON - {e}") | ||
| continue | ||
|  | ||
| if not isinstance(workbench_data, dict): | ||
| errors.append(f"Project {project_uuid}: Workbench is not a dictionary") | ||
| continue | ||
|  | ||
| for node_id, node_data in workbench_data.items(): | ||
| if not isinstance(node_data, dict): | ||
| errors.append( | ||
| f"Project {project_uuid}, Node {node_id}: Node data is not a dictionary" | ||
| ) | ||
| continue | ||
|  | ||
| # Validate required fields | ||
| missing_fields = [] | ||
| if not node_data.get("key"): | ||
| missing_fields.append("key") | ||
| if not node_data.get("version"): | ||
| missing_fields.append("version") | ||
| if not node_data.get("label"): | ||
| missing_fields.append("label") | ||
|  | ||
| if missing_fields: | ||
| errors.append( | ||
| f"Project {project_uuid}, Node {node_id}: Missing required fields: {', '.join(missing_fields)}" | ||
| ) | ||
| continue | ||
|  | ||
| # Check if node already exists | ||
| existing_node = connection.execute( | ||
| sa.text( | ||
| "SELECT project_node_id FROM projects_nodes WHERE project_uuid = :project_uuid AND node_id = :node_id" | ||
| ), | ||
| {"project_uuid": project_uuid, "node_id": node_id}, | ||
| ).fetchone() | ||
|  | ||
| # Prepare node data for insertion/update | ||
| node_values = { | ||
| "project_uuid": project_uuid, | ||
| "node_id": node_id, | ||
| "key": node_data["key"], | ||
| "version": node_data["version"], | ||
| "label": node_data["label"], | ||
| "progress": node_data.get("progress"), | ||
| "thumbnail": node_data.get("thumbnail"), | ||
| "input_access": ( | ||
| json.dumps(node_data["input_access"]) | ||
| if node_data.get("input_access") | ||
| else None | ||
| ), | ||
| "input_nodes": ( | ||
| json.dumps(node_data["input_nodes"]) | ||
| if node_data.get("input_nodes") | ||
| else None | ||
| ), | ||
| "inputs": ( | ||
| json.dumps(node_data["inputs"]) if node_data.get("inputs") else None | ||
| ), | ||
| "inputs_required": ( | ||
| json.dumps(node_data["inputs_required"]) | ||
| if node_data.get("inputs_required") | ||
| else None | ||
| ), | ||
| "inputs_units": ( | ||
| json.dumps(node_data["inputs_units"]) | ||
| if node_data.get("inputs_units") | ||
| else None | ||
| ), | ||
| "output_nodes": ( | ||
| json.dumps(node_data["output_nodes"]) | ||
| if node_data.get("output_nodes") | ||
| else None | ||
| ), | ||
| "outputs": ( | ||
| json.dumps(node_data["outputs"]) | ||
| if node_data.get("outputs") | ||
| else None | ||
| ), | ||
| "run_hash": node_data.get( | ||
| "run_hash", node_data.get("runHash") | ||
| ), # Handle both camelCase and snake_case | ||
| "state": ( | ||
| json.dumps(node_data["state"]) if node_data.get("state") else None | ||
| ), | ||
| "parent": node_data.get("parent"), | ||
| "boot_options": ( | ||
| json.dumps(node_data["boot_options"]) | ||
| if node_data.get("boot_options", node_data.get("bootOptions")) | ||
| else None | ||
| ), | ||
| } | ||
|  | ||
| if existing_node: | ||
| # Update existing node | ||
| update_sql = """ | ||
| UPDATE projects_nodes SET | ||
| key = :key, | ||
| version = :version, | ||
| label = :label, | ||
| progress = :progress, | ||
| thumbnail = :thumbnail, | ||
| input_access = :input_access::jsonb, | ||
| input_nodes = :input_nodes::jsonb, | ||
| inputs = :inputs::jsonb, | ||
| inputs_required = :inputs_required::jsonb, | ||
| inputs_units = :inputs_units::jsonb, | ||
| output_nodes = :output_nodes::jsonb, | ||
| outputs = :outputs::jsonb, | ||
| run_hash = :run_hash, | ||
| state = :state::jsonb, | ||
| parent = :parent, | ||
| boot_options = :boot_options::jsonb, | ||
| modified_datetime = NOW() | ||
| WHERE project_uuid = :project_uuid AND node_id = :node_id | ||
| """ | ||
| connection.execute(sa.text(update_sql), node_values) | ||
| updated_nodes_count += 1 | ||
| print(f"Updated existing node {node_id} in project {project_uuid}") | ||
|  | ||
| else: | ||
| # Insert new node | ||
| insert_sql = """ | ||
| INSERT INTO projects_nodes ( | ||
| project_uuid, node_id, key, version, label, progress, thumbnail, | ||
| input_access, input_nodes, inputs, inputs_required, inputs_units, | ||
| output_nodes, outputs, run_hash, state, parent, boot_options, | ||
| required_resources, created_datetime, modified_datetime | ||
| ) VALUES ( | ||
| :project_uuid, :node_id, :key, :version, :label, :progress, :thumbnail, | ||
| :input_access::jsonb, :input_nodes::jsonb, :inputs::jsonb, | ||
| :inputs_required::jsonb, :inputs_units::jsonb, :output_nodes::jsonb, | ||
| :outputs::jsonb, :run_hash, :state::jsonb, :parent, :boot_options::jsonb, | ||
| '{}'::jsonb, NOW(), NOW() | ||
| ) | ||
| """ | ||
| connection.execute(sa.text(insert_sql), node_values) | ||
| inserted_nodes_count += 1 | ||
|  | ||
| print( | ||
| f"Migration summary: {inserted_nodes_count} nodes inserted, {updated_nodes_count} nodes updated" | ||
| ) | ||
|  | ||
| if errors: | ||
| error_message = f"Migration failed with {len(errors)} errors:\n" + "\n".join( | ||
| errors | ||
| ) | ||
| print(error_message) | ||
| raise RuntimeError(error_message) | ||
|  | ||
|  | ||
| def _restore_workbench_from_projects_nodes() -> None: | ||
| """Restore workbench data from projects_nodes table to projects.workbench column.""" | ||
|  | ||
| # Get database connection | ||
| connection = op.get_bind() | ||
|  | ||
| # Get all projects that have nodes in projects_nodes | ||
| projects_with_nodes = connection.execute( | ||
| sa.text( | ||
| """ | ||
| SELECT DISTINCT project_uuid | ||
| FROM projects_nodes | ||
| ORDER BY project_uuid | ||
| """ | ||
| ) | ||
| ) | ||
|  | ||
| errors: list[str] = [] | ||
| restored_projects_count = 0 | ||
|  | ||
| for (project_uuid,) in projects_with_nodes: | ||
| # Fetch all nodes for this project | ||
| nodes_result = connection.execute( | ||
| sa.text( | ||
| """ | ||
| SELECT node_id, key, version, label, progress, thumbnail, | ||
| input_access, input_nodes, inputs, inputs_required, inputs_units, | ||
| output_nodes, outputs, run_hash, state, parent, boot_options | ||
| FROM projects_nodes | ||
| WHERE project_uuid = :project_uuid | ||
| ORDER BY node_id | ||
| """ | ||
| ), | ||
| {"project_uuid": project_uuid}, | ||
| ) | ||
|  | ||
| workbench_data: dict[str, Any] = {} | ||
|  | ||
| for row in nodes_result: | ||
| node_id = row.node_id | ||
|  | ||
| # Build node data dictionary | ||
| node_data: dict[str, Any] = { | ||
| "key": row.key, | ||
| "version": row.version, | ||
| "label": row.label, | ||
| } | ||
|  | ||
| # Add optional fields if they exist | ||
| if row.progress is not None: | ||
| node_data["progress"] = float(row.progress) | ||
| if row.thumbnail: | ||
| node_data["thumbnail"] = row.thumbnail | ||
| if row.input_access: | ||
| node_data["inputAccess"] = row.input_access | ||
| if row.input_nodes: | ||
| node_data["inputNodes"] = row.input_nodes | ||
| if row.inputs: | ||
| node_data["inputs"] = row.inputs | ||
| if row.inputs_required: | ||
| node_data["inputsRequired"] = row.inputs_required | ||
| if row.inputs_units: | ||
| node_data["inputsUnits"] = row.inputs_units | ||
| if row.output_nodes: | ||
| node_data["outputNodes"] = row.output_nodes | ||
| if row.outputs: | ||
| node_data["outputs"] = row.outputs | ||
| if row.run_hash: | ||
| node_data["runHash"] = row.run_hash | ||
| if row.state: | ||
| node_data["state"] = row.state | ||
| if row.parent: | ||
| node_data["parent"] = row.parent | ||
| if row.boot_options: | ||
| node_data["bootOptions"] = row.boot_options | ||
|  | ||
| workbench_data[node_id] = node_data | ||
|  | ||
| if workbench_data: | ||
| try: | ||
| # Update the project with the restored workbench data | ||
| connection.execute( | ||
| sa.text( | ||
| """ | ||
| UPDATE projects | ||
| SET workbench = :workbench_data | ||
| WHERE uuid = :project_uuid | ||
| """ | ||
| ), | ||
| { | ||
| "project_uuid": project_uuid, | ||
| "workbench_data": json.dumps(workbench_data), | ||
| }, | ||
| ) | ||
| restored_projects_count += 1 | ||
|  | ||
| except Exception as e: | ||
| errors.append( | ||
| f"Project {project_uuid}: Failed to restore workbench data - {e}" | ||
| ) | ||
|  | ||
| print( | ||
| f"Downgrade summary: {restored_projects_count} projects restored with workbench data" | ||
| ) | ||
|  | ||
| if errors: | ||
| error_message = f"Downgrade failed with {len(errors)} errors:\n" + "\n".join( | ||
| errors | ||
| ) | ||
| print(error_message) | ||
| raise RuntimeError(error_message) | ||
|  | ||
|  | ||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
|  | ||
| # Migrate workbench data to projects_nodes before dropping the column | ||
| _migrate_workbench_to_projects_nodes() | ||
|  | ||
| op.drop_column("projects", "workbench") | ||
| 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. are you sure about doing this right away? what if there is one thing missing in your migration? | ||
| # ### end Alembic commands ### | ||
|  | ||
|  | ||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.add_column( | ||
| "projects", | ||
| sa.Column( | ||
| "workbench", | ||
| postgresql.JSON(astext_type=sa.Text()), | ||
| autoincrement=False, | ||
| nullable=False, | ||
| ), | ||
| ) | ||
|  | ||
| # Restore workbench data from projects_nodes table | ||
| _restore_workbench_from_projects_nodes() | ||
| # ### end Alembic commands ### | ||
      
      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.
so if I get it correctly the migration will run whatever happens right, and you will get some error printed in the logs. or do you rollback?
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.
not sure if drop of the table will be included in this PR, this code was kindly suggested by AI... we still have to check it