Skip to content

Conversation

@Imat00
Copy link
Contributor

@Imat00 Imat00 commented Nov 5, 2025

Addresses #3863

  • Add column mgm_id INT with foreign key reference to management

  • Remove rule_uid unique constraint and its fk(temporarily)

  • Upgrade script:

    • set mgm_id in rule_metadata using existing mapping (rule_metadata.rule_uid -> rule.rule_uid)
  • Post-processing:

    • Set mgm_id as NOT NULL
    • Add unique constraint on (mgm_id, rule_uid) in rule_metadata
    • Add rule_uid unique constraint and its fk
  • update:

    • create table
    • create foreign-keys
    • create constraints
    • replace_metadata(Permissions mgm_id in rule_metadata and tracking fk for mgm_id)

- add mgm_id column to rule_metadata
- delete and add fk(not ready yet)
- delete and add Unique from rule_uid to (rule_uid, mgm,id)
- get data from rule table for mgm_ids in rule_metadata
@Imat00 Imat00 self-assigned this Nov 5, 2025
@Imat00 Imat00 requested a review from tpurschke November 5, 2025 13:40
Copy link
Contributor

@tpurschke tpurschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good but I need some more time for testing this. Die you try both a clean install and an upgrade?

@Imat00
Copy link
Contributor Author

Imat00 commented Nov 5, 2025

I performed a clean installation and tested the upgrade script several times.
I will also test the upgrade path.
If any issues occur, I will report them.

Copy link
Contributor

@tpurschke tpurschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constraint does not seem correct yet.
multiple versions of a rule with the same uid is not an issue as long as all of these occur on the same management.

Copy link
Contributor

@tpurschke tpurschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found an error in import caused by the change here, so I guess we have to adapt the importer at the same time:

2025-11-10T17:28:07+0100 [INFO ] [fwo_api.py               :_call_chunked            : 217] Processing chunked API call (upsertRuleMetadata)...
2025-11-10T17:28:07+0100 [DEBUG] [fwo_api.py               :_call_chunked            : 257] Chunk 1: 1000/9295 processed elements.
2025-11-10T17:28:07+0100 [ERROR] [fwo_api.py               :_handle_chunked_calls_res: 289] encountered error while handling chunked call: [{'message': 'Not-NULL violation. null value in column "mgm_id" of relation "rule_metadata" violates not-null constraint', 'extensions': {'path': '$.selectionSet.insert_rule_metadata.args.objects', 'code': 'constraint-violation'}}]
2025-11-10T17:28:07+0100 [ERROR] [fwo_api.py               :call                     :  84] FwoImporterError during API call: encountered error while handling chunked call: [{'message': 'Not-NULL violation. null value in column "mgm_id" of relation "rule_metadata" violates not-null constraint', 'extensions': {'path': '$.selectionSet.insert_rule_metadata.args.objects', 'code': 'constraint-violation'}}]
2025-11-10T17:28:07+0100 [ERROR] [common.py                :rollBackExceptionHandler : 185] Exception: FwoApiWriteError
2025-11-10T17:28:09+0100 [INFO ] [rollback.py              :rollbackCurrentImport    :  37] import 435 has been rolled back successfully
2025-11-10T17:28:09+0100 [INFO ] [import_state_controller.p:delete_import            : 435] removed import with id 435 completely
2025-11-10T17:28:09+0100 [INFO ] [fwo_api_call.py          :complete_import          : 329] import_management: import no. 435 for management fwmgmt01-f (id=252) threw errors, total change count: 22074, rule change count: 0, duration: 256s, ERRORS: ['FwoApiWriteError or FwoImporterError: ('failed to write new RulesMetadata: Traceback (most recent call last):\n  File "/usr/local/fworch/importer/model_controllers/fwconfig_import_rule.py", line 612, in addNewRuleMetadata\n    import_result = self.import_details.api_call.call(addNewRuleMetadataMutation, query_variables=query_variables, debug_level=self.import_details.DebugLevel, analyze_payload=True)\n                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/usr/local/fworch/importer/fwo_api.py", line 65, in call\n    return_object = self._call_chunked(session, query, query_variables, fwo_globals.debug_level)\n                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/usr/local/fworch/importer/fwo_api.py", line 252, in _call_chunked\n    return_object = self._handle_chunked_calls_response(return_object, response)\n                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/usr/local/fworch/importer/fwo_api.py", line 290, in _handle_chunked_calls_response\n    raise FwoImporterError(error_txt)\nfwo_exceptions.FwoImporterError: encountered error while handling chunked call: [{\'message\': \'Not-NULL violation. null value in column "mgm_id" of relation "rule_metadata" violates not-null constraint\', \'extensions\': {\'path\': \'$.selectionSet.insert_rule_metadata.args.objects\', \'code\': \'constraint-violation\'}}]\n',) - aborting import']
(importer-venv) fworch@FWORCH1:~/importer$

@tpurschke tpurschke marked this pull request as draft November 10, 2025 16:46
@Imat00
Copy link
Contributor Author

Imat00 commented Nov 11, 2025

found an error in import caused by the change here, so I guess we have to adapt the importer at the same time:

2025-11-10T17:28:07+0100 [INFO ] [fwo_api.py               :_call_chunked            : 217] Processing chunked API call (upsertRuleMetadata)...
2025-11-10T17:28:07+0100 [DEBUG] [fwo_api.py               :_call_chunked            : 257] Chunk 1: 1000/9295 processed elements.
2025-11-10T17:28:07+0100 [ERROR] [fwo_api.py               :_handle_chunked_calls_res: 289] encountered error while handling chunked call: [{'message': 'Not-NULL violation. null value in column "mgm_id" of relation "rule_metadata" violates not-null constraint', 'extensions': {'path': '$.selectionSet.insert_rule_metadata.args.objects', 'code': 'constraint-violation'}}]
2025-11-10T17:28:07+0100 [ERROR] [fwo_api.py               :call                     :  84] FwoImporterError during API call: encountered error while handling chunked call: [{'message': 'Not-NULL violation. null value in column "mgm_id" of relation "rule_metadata" violates not-null constraint', 'extensions': {'path': '$.selectionSet.insert_rule_metadata.args.objects', 'code': 'constraint-violation'}}]
2025-11-10T17:28:07+0100 [ERROR] [common.py                :rollBackExceptionHandler : 185] Exception: FwoApiWriteError
2025-11-10T17:28:09+0100 [INFO ] [rollback.py              :rollbackCurrentImport    :  37] import 435 has been rolled back successfully
2025-11-10T17:28:09+0100 [INFO ] [import_state_controller.p:delete_import            : 435] removed import with id 435 completely
2025-11-10T17:28:09+0100 [INFO ] [fwo_api_call.py          :complete_import          : 329] import_management: import no. 435 for management fwmgmt01-f (id=252) threw errors, total change count: 22074, rule change count: 0, duration: 256s, ERRORS: ['FwoApiWriteError or FwoImporterError: ('failed to write new RulesMetadata: Traceback (most recent call last):\n  File "/usr/local/fworch/importer/model_controllers/fwconfig_import_rule.py", line 612, in addNewRuleMetadata\n    import_result = self.import_details.api_call.call(addNewRuleMetadataMutation, query_variables=query_variables, debug_level=self.import_details.DebugLevel, analyze_payload=True)\n                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/usr/local/fworch/importer/fwo_api.py", line 65, in call\n    return_object = self._call_chunked(session, query, query_variables, fwo_globals.debug_level)\n                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/usr/local/fworch/importer/fwo_api.py", line 252, in _call_chunked\n    return_object = self._handle_chunked_calls_response(return_object, response)\n                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/usr/local/fworch/importer/fwo_api.py", line 290, in _handle_chunked_calls_response\n    raise FwoImporterError(error_txt)\nfwo_exceptions.FwoImporterError: encountered error while handling chunked call: [{\'message\': \'Not-NULL violation. null value in column "mgm_id" of relation "rule_metadata" violates not-null constraint\', \'extensions\': {\'path\': \'$.selectionSet.insert_rule_metadata.args.objects\', \'code\': \'constraint-violation\'}}]\n',) - aborting import']
(importer-venv) fworch@FWORCH1:~/importer$

'Not-NULL violation. null value in column "mgm_id" of relation "rule_metadata" violates not-null constraint' is caused by the change that made mgm_id in rule_metadata NOT NULL. We can discuss how to handle it.

@Imat00 Imat00 marked this pull request as ready for review November 11, 2025 15:06
Copy link
Contributor

@tpurschke tpurschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see below - displaying violations that prevent an update would be helpful

- missing Rule_uid from rule_metadata on rule
-  of Rule_uid and multiple mgm_id(s)
@sonarqubecloud
Copy link

@Imat00 Imat00 requested review from Y4nnikH and tpurschke November 12, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants