Skip to content

[vote][dammi] Migration for the new Vote Service - #3737

Open
vkrasnovyd wants to merge 140 commits into
OpenSlides:feature/votefrom
vkrasnovyd:vote-dammi
Open

vkrasnovyd wants to merge 140 commits into
OpenSlides:feature/votefrom
vkrasnovyd:vote-dammi

Conversation

@vkrasnovyd

@vkrasnovyd vkrasnovyd commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator

Needs OpenSlides/openslides-meta#584

How the collections should be migrated is described in Migration.md

schema_diff.sql for this migration is not fully generated: it contains multiple manual edits.

PR includes changes to the migration framework:

  1. check_prerequisites() got split into 2 separate methods:
  • check_env_prerequisites: checks the environment (like in migration 100). check_env_prerequisites() of all the pending migrations are executed before the migrations just like before.
  • check_db_prerequisites: check the data consistency (used in the vote service migration). Executed separately for each migration as they may rely on the tables/columns created in the previous migration.
  1. Adds new route "pre-check": to execute only the check_prerequisites:
  • check_env_prerequisites of all the pending migrations
  • check_db_prerequisites of the first pending migration
  1. Cursor (along with the logger) is passed to the migration class on init. Both cursor and logger are used in the new method execute_query that also logs the executed query witht the arguments for the debugging purposes.

  2. Introduces 2 new generated files (both used in the new migration):

  • diff_mixin.py‎ - contains dictionary for generating the migration tables: collection and column names along with the new types if type change is required for simplifying the operations in data_manipulation (currently relevant only for enum-columns)
  • cleanup_statements.sql‎ - for the queries that change the schema but must be executed only after data_manipulation
  1. Fixes multiple errors in sql_diff_generator.

Still WIP: tests for the new migration route pre-check.

hjanott and others added 15 commits July 1, 2026 13:49
* 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
 * 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
 * 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>
…ides#3711)

* generate from CodeBlocks call

* centralize code block information

* implement rename inline constraints and other constraints and triggers

 * move rename code to RenameHelper
@vkrasnovyd
vkrasnovyd marked this pull request as draft August 31, 2026 10:07
@vkrasnovyd vkrasnovyd self-assigned this Aug 31, 2026
@vkrasnovyd
vkrasnovyd force-pushed the vote-dammi branch 5 times, most recently from 16910e8 to c768043 Compare September 4, 2026 16:44
@bastianjoel
bastianjoel changed the base branch from main to feature/vote December 2, 2026 12:12
Comment thread setup.cfg
fail_under = 95
omit =
tests/*
migrations/*

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Directory does not exist since rel-db.

Comment thread tests/conftest_helper.py
Comment on lines +15 to +17
if table == "public.truncate_tables":
continue

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

store_table_names() inserts into public.truncate_tables.

Attempt to run action/presenter tests right after the migration tests in the dev-setup triggered recursive writing into truncate_tables which led to the database error. This check fixes this problem.

@vkrasnovyd
vkrasnovyd marked this pull request as ready for review December 4, 2026 14:09
@vkrasnovyd vkrasnovyd added migration Introduces a new migration enhancement General enhancement which is neither bug nor feature labels Dec 4, 2026

@luisa-beerboom luisa-beerboom 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.

Will finish reviewing next week

Comment on lines +148 to +154
poll.content_object_id LIKE 'motion/%%'
OR (
poll.content_object_id LIKE 'assignment/%%'
AND (
option.content_object_id LIKE 'poll_candidate_list/%%'
OR (
option.content_object_id LIKE 'user/%%'

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.

Since % stands for 0 or more characters, %% would also stand for 0 or more characters.
Were these supposed to be _%?

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.

There are also a bunch more places like it below

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In short, I'm using the first % as an escape sign for the second % in a query built as sql.SQL().format().

Because of using the format, single % is interpreted as a broken placeholder, while %% is interpreted as %. So filter poll.content_object_id LIKE 'motion/%%' is interpreted as poll.content_object_id LIKE 'motion/%' and the query is executed correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement General enhancement which is neither bug nor feature migration Introduces a new migration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants