Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(emx2): Check if column has refBack before deleting #4379

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

harmbrugge
Copy link
Member

@harmbrugge harmbrugge commented Oct 17, 2024

Fixes #4091

What are the main changes you did:

  • Check if column has refBack before deleting in migrate function

how to test:

  • Go to the preview server and try to delete the 'patient visits' table in 'refbackTest' schema

todo:

  • check if refback column is also deleted by the query before throwing an exception.
  • updated docs in case of new feature
  • added/updated tests
  • added/updated testplan to include a test for this fix, including ref to bug using # notation

@harmbrugge harmbrugge self-assigned this Oct 17, 2024
@harmbrugge harmbrugge marked this pull request as draft October 17, 2024 15:14
Copy link
Member

@mswertz mswertz left a comment

Choose a reason for hiding this comment

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

looks okay, indeed needs a test?

offtopic for future PR, the migration is a hell piece of code and might need some change soon.
It should

  • first add tables and pkey (these things never change, pkey needed for refs)
  • then reiterate and all other columns (might be updated/deleted)
  • delete all columns last
    this relates to circular error we still have.

@harmbrugge harmbrugge marked this pull request as ready for review October 22, 2024 14:31
for (Column column : mergeTable.getColumns()) {
if (!column.isReferenceWithRefback()) continue;

Column refbackColumn = column.getReferenceRefback();
Copy link
Member

Choose a reason for hiding this comment

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

where do you check for refbacks in existing tables that are not being dropped (might even be in other schema)? I would expect that to happen in SqlTableMetadata

@@ -297,7 +289,7 @@ public void dropColumn(String name) {
throw new MolgenisException("Drop column " + name + " failed: column does not exist");
}
// if changing 'ref' then check if not refBack exists
checkNotRefback(name, column);
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to move this check so that it fires within transaction?
I expected this to be checked within 'executeRemoveColumn' so that when executeDropTable is executed it also happens.

@@ -221,7 +221,7 @@ private static SqlTableMetadata alterColumnTransaction(

// if changing 'ref' then check if not refBack exists
if (!oldColumn.getColumnType().equals(newColumn.getColumnType())) {
tm.checkNotRefback(columnName, oldColumn);
checkNotRefback(oldColumn);
Copy link
Member

Choose a reason for hiding this comment

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

maybe rename to 'checkNoRefbackExists'

if (oldColumn != null && !newColumn.isDrop()) {
if (!created.contains(newColumn.getTableName() + "." + newColumn.getName())) {
oldTable.alterColumn(oldColumn.getName(), newColumn);
}
} else
// don't forget to add the refbacks
if (oldColumn == null && newColumn.isRefback()) {
if (oldColumn == null && !newColumn.isDrop() && newColumn.isRefback()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this a different issue/fix right ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I sneaked it in here

Copy link

sonarcloud bot commented Oct 24, 2024

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.

fix: deleting table that is a refBack crashes a schema
3 participants