OpenSlides / OpenSlides/openslides-backend

Migrate all constraint names

Open
#3,568 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
9
Forks
40
Avg merge
1d 22h
Merged PRs (30d)
19

Description

We need to migrate the names of constraints properly. This needs to be done in the finalization.
The names are defined within our schema. It gets lost during table copy during the migrate step. The solution would possibly entail reimplementing the postgres naming convention and renaming the constraints in our naming convention.

Here is an example snippet to check correct the behaviour of migration 100 in the case of primary keys. You can add it to the check_data method.

                # 6.9 Recreated primary key constraints
                assert_content_not_none(
                    """SELECT 1
                    FROM information_schema.table_constraints AS tc
                    WHERE tc.constraint_type = 'PRIMARY KEY'
                        AND tc.constraint_name = 'pk_nm_chat_group_read_group_ids_group_t';"""
                )

An extension for what is being done for the foreign keys could be sufficient. (migration handler line 85)

NOT NULL, DEFAULT and GENERATED ALWAYS constraints are not named by postgres. Thus these could be taken off their names if we don't find a reason why we want to find these names in the sql file. It wouldn't need a migration for these as they are already omitted by postgres.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the migration handler around line 85 and the table-copy step in migrate, then inspect how schema constraint names reach finalization. Add the primary-key case to migration 100's check_data method using the information_schema query shown. Done means named primary-key and foreign-key constraints survive migration with the project's naming convention, while unnamed PostgreSQL constraints remain appropriately handled.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.