fix: Normalize PKs to not null#13557
Conversation
|
Ah, for some reason those tests are passing locally for me |
|
Tests fixed in a429640 |
| plugin.WriterTestSuiteTests{ | ||
| SafeMigrations: plugin.SafeMigrations{ | ||
| AddColumn: true, | ||
| AddColumnNotNull: false, |
There was a problem hiding this comment.
I think it just needs the true options, the false is the default.
| func (c *Client) normalizeTable(table *schema.Table) *schema.Table { | ||
| columns := make([]schema.Column, len(table.Columns)) | ||
| for i, col := range table.Columns { | ||
| if col.PrimaryKey { |
There was a problem hiding this comment.
Maybe just col.NotNull = col.NotNull || col.PrimaryKey ?
| columns := make([]schema.Column, len(table.Columns)) | ||
| for i, col := range table.Columns { | ||
| // In MySQL primary keys are implicitly not null | ||
| col.NotNull = col.NotNull || col.PrimaryKey |
There was a problem hiding this comment.
I'm a bit worried that we modify column here instead of working on the copy.
Could we move it to
normalizedCol := schema.NewColumnFromArrowField(*normalized)
normalizedCol.NotNull = normalizedCol.NotNull || normalizedCol.PrimaryKey
columns[i] = normalizedColor something similar?
There was a problem hiding this comment.
Cleaned up the PR. Also thought about removing the conversion to arrow and back to column, but probably safer to keep it so we remove any non relevant column fields.
Also moved the tests change to #13565
8bf0482 to
a43b486
Compare
| Name: field.Name, | ||
| Type: normalizedType, | ||
| Nullable: field.Nullable, | ||
| Nullable: !notNull, |
There was a problem hiding this comment.
| Nullable: !notNull, | |
| Nullable: !(col.NotNull || col.PrimaryKey), // In MySQL primary keys are implicitly not null |
| // In MySQL primary keys are implicitly not null | ||
| notNull := col.NotNull || col.PrimaryKey |
There was a problem hiding this comment.
| // In MySQL primary keys are implicitly not null | |
| notNull := col.NotNull || col.PrimaryKey |
🤖 I have created a release *beep* *boop* --- ## [3.0.5](plugins-destination-mysql-v3.0.4...plugins-destination-mysql-v3.0.5) (2023-09-01) ### Bug Fixes * **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.6.0 ([#13492](#13492)) ([c305876](c305876)) * Normalize PKs to not null ([#13557](#13557)) ([2230538](2230538)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Summary
Saw this while working on #13486. If you run migration twice on the same spec it fails. The reason is that MySQL Implicitly sets PKs to non null in the DB, so we have to account for that.
We had this in the code and it seems it got lost in the migration to v3 or v4.
I also cleaned up the tests as those are passing without that loop on test options.Tests cleanup moved to #13565Not sure why the double migration tests didn't catch this