Repository navigation
[Dammi] Add handling - #3748
[Dammi] Add handling#3748
Conversation
0f0641d to
f4ab822
Compare
hjanott
left a comment
There was a problem hiding this comment.
This review is still in a stage of wip. Sending so that you can continue to work on this.
hjanott
left a comment
There was a problem hiding this comment.
In general a very clever solution.
I would like you to create a class like done for RemoveHelper and the like.
| | "text[]" | ||
| ): | ||
| pass | ||
| case ( | ||
| "relation" | ||
| | "relation-list" | ||
| | "generic-relation" | ||
| | "generic-relation-list" | ||
| ): | ||
| pass |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Many good improvements. Thanks!
| "generic-relation", | ||
| "generic-relation-list", | ||
| ] | ||
| is_sql_field = len(field_def.get("sql", "").strip()) > 0 |
There was a problem hiding this comment.
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.
| is_sql_field = len(field_def.get("sql", "").strip()) > 0 | |
| is_sql_field = "sql" in field_def |
There was a problem hiding this comment.
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.
| "relation", | ||
| "relation-list", | ||
| "generic-relation", | ||
| "generic-relation-list", |
| for value in [alter_table_code, trigger_code]: | ||
| after_sql += value | ||
|
|
||
| return constraints_sql, after_sql, is_view_field |
There was a problem hiding this comment.
Even simpler. Don't know why I didn't have this idea earlier.
| 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 |
|
Aside from working on the CRs I also rearranged the generated SQL according to requests by @vkrasnovyd |
| RELATION_TYPES = [ | ||
| "relation", | ||
| "relation-list", | ||
| "generic-relation", | ||
| "generic-relation-list", | ||
| ] |
There was a problem hiding this comment.
I realized that RELATION_TYPES already exists in validate.py. Maybe a good idea to import that.
| ) | ||
| table_sql += table_sql2 | ||
| sql += before_sql | ||
| sql += table_sql + alter_table_sql.lstrip("\n") + remainder_sql |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
- all meta enums
- all new tables
- all triggers for new tables
- all enums for new columns
- all new columns (i.e.
ALTER TABLE...) - all triggers for new columns
in that order. There could be 300 lines between the field-based enum and the correlatingALTER TABLEwhere 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:
- I refactor 2005a73 to make it more readable.
- I rewrite the code so the field enums are generated directly before their alter table, preserving the rest of the commit.
- 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
There was a problem hiding this comment.
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.
|
Create tables did not get field enums yet. Made sure they're generated as well. |
7c0c162 to
a5539d9
Compare
3f12773
into
OpenSlides:feature/dammi
* 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>
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