Skip to content

Conversation

@mbrandonw
Copy link
Member

This is an alternative fix to #362

When performing a migration of the form "ADD COLUMN … DEFAULT _" (i.e. a nullable column), then we want the default to be inserted into the local database and stay there after the sync engine has fully started up. Currently there is a bug where that data gets NULL'd out after start up, and this PR fixes that.

@mbrandonw
Copy link
Member Author

@hishnash Can you check if this fixes the problem you were fixing in #362 ?

@hishnash
Copy link

what about the UPSERT operation that is called when another device makes a change.

What would happen if a device on an older version makes a change and it is synced to a device with the new schema.

What column names are passed to private func upsert<T> would it include the column name for the column that the other device does not have any value for and thus result in overwriting null or would it skip that column in the update portion of the on conflict?

@mbrandonw
Copy link
Member Author

Hi @hishnash, good catch. We pushed a few more changes to cover another edge case and wrote some tests to demonstrate it. Can you let us know if this works for you?

else {
return ""
}
let hasNonPrimaryKeyColumns = columnNames.contains { $0 != T.primaryKey.name }

Choose a reason for hiding this comment

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

is it possible that columnNames here somehow ends up with the column name that is not in the filtered allColumnNames and thus would result in a SQL error as columnNames is used in the ON CONFLICT DO SET option. Maybe columnNames need to drop any names that are not found in allColumnNames (I know there is some other method doing this further up before upsert is called but that method does not consider the hasSet(key: $0) )

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that seems theoretically possible, but haven't thought of the exact scenario where that might happen. I pushed an updated.

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.

3 participants