Skip to content

[Dammi] Add handling - #3748

Merged
luisa-beerboom merged 32 commits into
OpenSlides:feature/dammifrom
luisa-beerboom:dammi-add-handling
Oct 15, 2026
Merged

luisa-beerboom merged 32 commits into
OpenSlides:feature/dammifrom
luisa-beerboom:dammi-add-handling

Conversation

@luisa-beerboom

@luisa-beerboom luisa-beerboom commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Does it work as far as new collections/fields are concerned? yes.
Added field attributes not handled yet.

meta changes in OpenSlides/openslides-meta#601

@luisa-beerboom luisa-beerboom added this to the 4.4 milestone Sep 7, 2026
@luisa-beerboom luisa-beerboom self-assigned this Sep 7, 2026
@luisa-beerboom
luisa-beerboom requested a review from hjanott October 1, 2026 15:40
@luisa-beerboom
luisa-beerboom marked this pull request as ready for review October 1, 2026 15:40

@hjanott hjanott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This review is still in a stage of wip. Sending so that you can continue to work on this.

@hjanott hjanott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In general a very clever solution.
I would like you to create a class like done for RemoveHelper and the like.

Comment on lines +1071 to +1080
| "text[]"
):
pass
case (
"relation"
| "relation-list"
| "generic-relation"
| "generic-relation-list"
):
pass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please write a comment why these are skipped. I have a feeling that I wanted to add the type to the string here. Or maybe not.
Also we could create central (relation) types variables which would be a tuple (maybe even of Literals) for reuse in other parts of this script.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I moved them to the default handling and added a BadCodingException since if any field with any of these types is handled via this method, something's gone seriously wrong.

@hjanott hjanott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Many good improvements. Thanks!

"generic-relation",
"generic-relation-list",
]
is_sql_field = len(field_def.get("sql", "").strip()) > 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not simple? I don't think we need to care for white spaces. If that's an error we want to treat, we should do so in validate.py.

Suggested change
is_sql_field = len(field_def.get("sql", "").strip()) > 0
is_sql_field = "sql" in field_def

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Furthermore I don't think we need to pass this through. _get_szt_for_added_relation and _handle_add_non_relation_helper can obtain this directly from field_def.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Comment on lines +903 to +906
"relation",
"relation-list",
"generic-relation",
"generic-relation-list",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See this comment. #3748 (comment)

Comment on lines +1059 to +1062
for value in [alter_table_code, trigger_code]:
after_sql += value

return constraints_sql, after_sql, is_view_field

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Even simpler. Don't know why I didn't have this idea earlier.

Suggested change
for value in [alter_table_code, trigger_code]:
after_sql += value
return constraints_sql, after_sql, is_view_field
after_sql += alter_table_code + trigger_code
return constraints_sql, after_sql, is_view_field

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

@luisa-beerboom

Copy link
Copy Markdown
Member Author

Aside from working on the CRs I also rearranged the generated SQL according to requests by @vkrasnovyd
I.e. moved generated field enums directly below meta enums and column generation before all trigger generation.

Comment on lines +56 to +61
RELATION_TYPES = [
"relation",
"relation-list",
"generic-relation",
"generic-relation-list",
]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I realized that RELATION_TYPES already exists in validate.py. Maybe a good idea to import that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

)
table_sql += table_sql2
sql += before_sql
sql += table_sql + alter_table_sql.lstrip("\n") + remainder_sql

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm against these changes. Please revert 2005a73.
I think that it makes it less logically grouped in the output this script gets more obfuscated and as long as the enum create appears before its table statement all is well.

@luisa-beerboom luisa-beerboom Oct 15, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I certainly won't revert the entirety of 2005a73

Part of the commit is necessary in order for the SQL to work.
Having the column alter tables between the new collection tables and their triggers for example.
After all, we don't want to build a trigger listening to a field on the relations other collection, if that field hasn't been added yet.

I'll also mention that the previous version wasn't "logically grouped" either.
Previous version generated

  1. all meta enums
  2. all new tables
  3. all triggers for new tables
  4. all enums for new columns
  5. all new columns (i.e. ALTER TABLE...)
  6. all triggers for new columns
    in that order. There could be 300 lines between the field-based enum and the correlating ALTER TABLE where it is used. At that point having all enums in one place (rather than two) would've made it easier to find.

There's two options now:

  1. I refactor 2005a73 to make it more readable.
  2. I rewrite the code so the field enums are generated directly before their alter table, preserving the rest of the commit.
  3. I do both. Refactor 2005a73 to make it more readable and rewrite the code so the field enums are generated directly before their alter table.

What would you prefer @hjanott

@luisa-beerboom luisa-beerboom Oct 15, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did no. 3. I also moved every remaining bit of add code, that wasn't in the helper class yet, into the helper class. Refactored it a bit too. It's all in on place now.

@hjanott hjanott assigned luisa-beerboom and unassigned hjanott Oct 14, 2026
@luisa-beerboom

Copy link
Copy Markdown
Member Author

Create tables did not get field enums yet. Made sure they're generated as well.

@hjanott hjanott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@luisa-beerboom
luisa-beerboom enabled auto-merge (squash) October 15, 2026 11:36
@luisa-beerboom
luisa-beerboom merged commit 3f12773 into OpenSlides:feature/dammi Oct 15, 2026
9 of 10 checks passed
luisa-beerboom added a commit that referenced this pull request Nov 17, 2026
* Sql diff generator (#3625)

* [dammi] Remove mig tables (#3641)

* apply sql diff
* change base test
* cleanup get_stats/count method
* improve exception stats output
* handle listdir patching in migrate_previous
* fix create_schema
* implement new directory structure for migration module and schema_diff
* add migration_number to basemigtestcase
* remove finalization states and add migration finished state
* decuple BaseMigration and BaseMigrationRouteTestCase
* remove finalize command
* use only empty values within replace tables
* fix followup errors due to failing tests and continuing migration thread
* deactivate notify triggers during migration and reactivate on reset
* Move copy table to migration helper.
* improve exception handling

* [dammi]Add data preparation step and reimplement reset route (#3660)

* use deprecated  model registry (#3662)

* improve schema diff file handling (#3669)

* improve migration lookup (#3671)

* [Dammi] Split off version table writing for migrations (#3643)

* [dammi] More ground work for sql diff (#3679)

 * improve file handling
 * generate whole new collections
 * more constraint cases and new function for altered fields
 * Handle remove and rename tree
 * safely access GenerateCodeBlocks variables

* [dammi] Remove deferred (#3687)

* [dammi] view diff generation (#3699)

 * centralize models variables
 * collect alter_views conditionally and recreate in the end
 * extract get_view_field_state_write_fields
 * debug main functions with make test-file
 * improve variable names and reuse code in cli util
 * centralize and restructure RENAME

---------

Co-authored-by: Viktoriia Krasnovyd <114735598+vkrasnovyd@users.noreply.github.com>

* [dammi] reintroduce migrations subfolder (#3708)

* [dammi] Handle remove (#3686)

* [dammi] rename triggers, constraints, indexes and field enums (#3711)

* generate from CodeBlocks call

* centralize code block information

* implement rename inline constraints and other constraints and triggers

 * move rename code to RenameHelper

* [dammi] Remove secondary_edits (#3736)

* [dammi] sql diff edit part (#3729)

* [dammi] Sql diff edit: equal fields, constant, max, min and minLength (#3773)

* edit case generate equal fields and restructure EqualFieldsHelper a bit
* sqlfluffing output + sorting 
* handle min, max, minLength, unique, constant
* recreate renamed intermediate table and respect that in equal fields generation

---------

Co-authored-by: luisa-beerboom <101706784+luisa-beerboom@users.noreply.github.com>

* [dammi] Handle edit for meta enums (#3791)

* handle edit for meta enums
* handle remove field case correctly
* rename enum right way around
* drop enum default if existed
* respect changes from meta enum to field based enum and reverse
* respect items
* rename meta enums
* drop and recreate view

* [Dammi] Add handling (#3748)

* Fix RemoveHelper (#3816)

* handle reference
* remove calculated field from diff control
* delete fk and idx just cascadingly

* Fix stuff in dammi (#3820)

* Fix equal fields removal

* Fix trigger generation for relation field adding

* Fixes for DaMMi (#3824)

* Fix more dammi stuff (#3823)

* Fix case new enum constraint

* Implement generic relation expansions

* Fix even more dammi stuff (#3826)

* Fix not remove field trigger generation

* Alter field types when changing global enums

* Drop triggers before changing type to enum, return them after (#3842)

* Add new consultation sequence enabling setting (#3843)

* Add migration for trigger naming scheme change (#3853)

* Add migration for trigger naming scheme change

* Also handle missing log triggers in user-committee calc relation

* Always apply the new settings default in migration 102

* Fix flaky migration tests

* Add changes for fix of generated array field log triggers

* Make changes for trigger names

* Update test_0100_init_reldb.py

---------

Co-authored-by: luisa-beerboom <101706784+luisa-beerboom@users.noreply.github.com>
Co-authored-by: Viktoriia Krasnovyd <114735598+vkrasnovyd@users.noreply.github.com>
Co-authored-by: vkrasnovyd <viktoriia.krasnovyd@intevation.de>
Co-authored-by: Luisa <luisa.beerboom@intevation.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants