Skip to content

Conversation

@yevgenypats
Copy link
Contributor

@yevgenypats yevgenypats commented Feb 15, 2023

Migration detection APIs take 2.

  • This creates one API that returns all the changes instead of multiple growing APIs for different set of changes.
  • Improves Migration tests for different use-cases

This will come up also with a Postgres PR and documentation PR:

Basically each destination plugin would have the following table:

Migrations Logic

Change Behaviour
Add Column Auto Migrate/Drop Table
Add Column with Not Null Auto Migrate/Drop Table
Remove Column Auto Migrate/Drop Table
Remove Column with Not Null Auto Migrate/Drop Table
Change Column Auto Migrate/Drop Table

and we can easily expand it in the code, tests and documentations.

Example of usage in cloudquery/cloudquery#7819

@github-actions
Copy link

github-actions bot commented Feb 15, 2023

⏱️ Benchmark results

  • DefaultConcurrencyDFS-2 resources/s: 9,394
  • DefaultConcurrencyRoundRobin-2 resources/s: 12,447
  • Glob-2 ns/op: 255.1
  • TablesWithChildrenDFS-2 resources/s: 26,926
  • TablesWithChildrenRoundRobin-2 resources/s: 26,193
  • TablesWithRateLimitingDFS-2 resources/s: 28.38
  • TablesWithRateLimitingRoundRobin-2 resources/s: 817.2
  • BufferedScanner-2 ns/op: 11.73
  • LogReader-2 ns/op: 38.06

Copy link
Member

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Added a few comments, I don't think any are blocking

schema/table.go Outdated

// changed pks: drop table // table.IsPrimaryKeyEqual(other)

func (t *Table) GetChanges(other *Table) []TableColumnChange {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func (t *Table) GetChanges(other *Table) []TableColumnChange {
func (new *Table) GetChanges(old *Table) []TableColumnChange {

Maybe this will make it easier to follow? Non blocking

Copy link
Member

Choose a reason for hiding this comment

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

new being a reserved word probably can't be used, but the old change is 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

yevgenypats and others added 5 commits February 16, 2023 12:54
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
Comment on lines 20 to 25
// type MigrateResult int

// const (
// MigrateResultSuccess MigrateResult = iota
// MigrateResultDropTable
// )
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this can be removed?

yevgenypats and others added 2 commits February 16, 2023 13:23
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Feb 16, 2023

Codecov Report

Base: 47.19% // Head: 47.08% // Decreases project coverage by -0.12% ⚠️

Coverage data is based on head (8f4d92b) compared to base (1b52253).
Patch coverage: 54.16% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #688      +/-   ##
==========================================
- Coverage   47.19%   47.08%   -0.12%     
==========================================
  Files          70       70              
  Lines        6831     6845      +14     
==========================================
- Hits         3224     3223       -1     
- Misses       3156     3171      +15     
  Partials      451      451              
Impacted Files Coverage Δ
schema/column.go 50.00% <0.00%> (ø)
schema/table.go 42.85% <47.22%> (-4.49%) ⬇️
internal/memdb/memdb.go 85.23% <81.81%> (-0.48%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment on lines +29 to +35
type MigrateStrategy struct {
AddColumn specs.MigrateMode
AddColumnNotNull specs.MigrateMode
RemoveColumn specs.MigrateMode
RemoveColumnNotNull specs.MigrateMode
ChangeColumn specs.MigrateMode
}
Copy link
Member

Choose a reason for hiding this comment

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

It might be just semantics, but I'm a bit confused by the options here 🤔

The table in the PR description has two options for each entry: Auto Migrate / Drop Table. I think it would be clearer if we used that terminology here, rather than MigrateMode = forced or MigrateMode = safe. forced/safe doesn't convey the same meaning to me drop/auto, but I think that is the intention of this configuration, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I had the same dilemma if to introduce another type, but then it would be quite annoying as we will have OverwriteForceStrategy OverwriteAutoMigrateStrategy and the same for append so I preferred for now just to do one for each mode and then we can understand if it is being dropped or not.

But I think that yes, we potentially will need to change it, I just didn't want to make it even more complex right now as I think we will need to learn a bit more about this API and usage and then do another iteration on the testing API at least.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe a comment would help for now. Something like forced == drop table, safe == do not drop table

Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Copy link
Member

@hermanschaaf hermanschaaf left a comment

Choose a reason for hiding this comment

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

Nice, looks good 👍 If we want to split hairs I'd probably change the naming of the options a bit to make them clearer (IMO), and I spotted a few error messages we may want to fix, but other than that all good :)

yevgenypats and others added 2 commits February 16, 2023 13:38
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
@kodiakhq kodiakhq bot merged commit dc3bedf into main Feb 16, 2023
@kodiakhq kodiakhq bot deleted the fix/migration_sdk branch February 16, 2023 11:42
kodiakhq bot pushed a commit that referenced this pull request Feb 16, 2023
🤖 I have created a release *beep* *boop*
---


## [1.38.0](v1.37.1...v1.38.0) (2023-02-16)


### Features

* Improve migration detection APIs ([#688](#688)) ([dc3bedf](dc3bedf))


### Bug Fixes

* Better string methods for TableColumnChange ([#690](#690)) ([a0ec52c](a0ec52c))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
kodiakhq bot pushed a commit to cloudquery/cloudquery that referenced this pull request Feb 16, 2023
Blocked by cloudquery/plugin-sdk#668

This streamlines migrations, introduce force option and in general should speed up migrations substantially as we only do now one query instead of query per table. 

Blocked by another take in SDK - cloudquery/plugin-sdk#688
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants