Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Remove soft-deletion pattern #2327

Merged
merged 8 commits into from
Oct 22, 2020

Conversation

nyanshak
Copy link
Contributor

  • Perform migration to delete any entries with deleted set, and
    subsequently drop columns deleted and deleted_at.
  • Remove deleted and deleted_at references.

@nyanshak
Copy link
Contributor Author

Addresses #2146

@nyanshak
Copy link
Contributor Author

@zwass I took a stab at solving #2146 here. It's still a bit of a work in progress, but I could use some help with the migrations since I haven't worked with that before.

I'm following the instructions in docs/development/database-migrations.md, but having a bit of trouble.

When I run ./build/fleet prepare db, my migration file is called (added debug prints in init), but the Up function doesn't seem to ever be called.

Could you take a look and see if I'm doing something wrong?

Copy link
Contributor

@zwass zwass left a comment

Choose a reason for hiding this comment

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

Thank you for tackling this!

)

func init() {
goose.AddMigration(Up20201011162341, Down20201011162341)
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be MigrationClient.AddMigration. That will solve your issue with the migration not running. Do we need to update the docs about this?

Copy link
Contributor Author

@nyanshak nyanshak Oct 16, 2020

Choose a reason for hiding this comment

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

The docs say to run goose create AddColumnFooToUsers, then 'edit it', but is less clear on what needs to be done.

I see two things that must be edited (as far as I can tell) each time you run the goose create command:

  1. delete the import line for goose: github.com/pressly/goose
  2. change goose.AddMigration(...) to `MigrationClient.AddMigration(...)

I can add a note to the docs to fix both of these if you'd like.

It would also be good to have the goose create command generate this file as close to 'correctly' as possible, so it might be worth updating the goose library to do this.

Also while I was looking into this, I was a bit confused on what the kolide goose fork did, but it seemed like the fork hasn't been updated since 2018, while the pressly source is still actively maintained. Long-term - should we consider moving back to pressly upstream?

Copy link
Contributor

@zwass zwass left a comment

Choose a reason for hiding this comment

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

It seems there are a couple of test failures that need to be updated.

In regards to your comment about Goose (Github no longer seems to allow me to reply to that comment), please do update the documentation with what you found.

We had initially forked Goose for at least one reason: We needed to be able to make the separate migration "clients" for tables and data, and needed to refactor Goose from using a single, global, migration client. I cannot remember if there were other motivations for the fork.

I did look recently at the activity on Goose and did not get the impression that the core had changed in a way that would allow us to achieve the goal of separate clients. That said, I do think it could be worthwhile to try to rebase the fork onto the new changes.

In regards to making the command generate a migration closer to what we need, that definitely seems worthwhile.

* Perform migration to delete any entries with `deleted` set, and
subsequently drop columns `deleted` and `deleted_at`.
* Remove `deleted` and `deleted_at` references.
* Change `goose.AddMigration` to `MigrationClient.AddMigration`
* If columns don't exist, skip instead of failing the migration. This
might happen in the case of a partial or broken migration.
* Specify changes that need to be made after running the goose create
command.
@nyanshak
Copy link
Contributor Author

One of the test failures is when deleting hosts. There is an existing test for testIdempotentDeleteHost that creates a host and tries to delete it twice. In the 'soft-deleted' pattern, this was fine (just set deleted to true each time). There are lots of places that call deleteEntity but DeleteHost was the only one with a test expecting this to be idempotent.

I'm not sure what the reasoning is behind that, but I'm going to put up a commit that removes this test, as deleting is not actually idempotent any more. Give me a shout if this doesn't work.

* Without soft-delete, host deleting is no longer idempotent. Removing
the test for this.
* Replace definitions with the mysqlerr package constants instead of
defining them here.
* Return appropriate error message when attempting to insert a query by
ID that already exists in the DB.
@nyanshak nyanshak force-pushed the issue-2146-remove-soft-deletion branch from 5e13345 to 102ea1b Compare October 19, 2020 18:55
@zwass
Copy link
Contributor

zwass commented Oct 19, 2020

I am totally on board with removing tests that no longer make sense. Thank you. I will give this some more review and testing when I have a chance.

Copy link
Contributor

@zwass zwass left a comment

Choose a reason for hiding this comment

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

I just pushed a commit to remove the debug prints. Thank you for sorting this out!

@zwass zwass changed the title WIP: Remove soft-deletion pattern Remove soft-deletion pattern Oct 21, 2020
@zwass zwass merged commit c6b285c into kolide:master Oct 22, 2020
zwass added a commit to fleetdm/fleet that referenced this pull request Nov 4, 2020
Changes in kolide/fleet#2327 broke the MySQL
syntax for listing hosts with online status. This was not caught due to
the lack of a unit test for the functionality. This PR adds a unit test
and fixes the regression.
zwass added a commit to fleetdm/fleet that referenced this pull request Nov 4, 2020
Changes in kolide/fleet#2327 broke the MySQL
syntax for listing hosts with online status. This was not caught due to
the lack of a unit test for the functionality. This PR adds a unit test
and fixes the regression.
zwass added a commit to zwass/fleet that referenced this pull request Nov 5, 2020
This is another error introduced in
kolide/fleet#2327 we did not catch previously
due to insufficient unit test coverage. Test is now added
zwass added a commit to fleetdm/fleet that referenced this pull request Nov 5, 2020
This is another error introduced in
kolide/fleet#2327 we did not catch previously
due to insufficient unit test coverage. Test is now added.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants