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

Recommendations for data migrations #29

Closed
tielur opened this issue May 25, 2017 · 6 comments
Closed

Recommendations for data migrations #29

tielur opened this issue May 25, 2017 · 6 comments

Comments

@tielur
Copy link
Contributor

tielur commented May 25, 2017

So I recently started using cloak in a project with existing data. I'm in the process of figuring out the best way to migrate that data to it's encrypted version. I ran into a few things and I'm looking for recommendations that might be worth documenting for other users. Here's a few things:

  1. I want to encrypt data in a migration.
  2. I want to use schemaless Ecto queries to future proof the migrations ( changing the model in the future would cause a schema based query to fail)

I originally went the route of #1 and just wrote a query to fetch data and then update it so that Cloak would encrypt the data. This worked ok but because it's using Schema queries if you want to update the model in the future like I am doing now, the migration will fail. This lead me down the route of schemaless queries to be used in migrations. Which everyone seems to be using anyways for this reason.

So if we go with schemaless queries, I don't think I can go the route of just updating the data and expecting Cloak to encrypt it. Here's where I need a suggestion on how to handle the encryption. Do I just use the manual encrypt methods to handle that?

Is this a common enough problem that maybe Cloak should include an example of how to handle this?

@tielur
Copy link
Contributor Author

tielur commented May 25, 2017

Another option would be to define a schema in the migration to use with a schema query?

@danielberkompas
Copy link
Owner

I agree that there should be documentation on how to migrate existing data. I think this would consist of calling the encrypt functions manually, yes.

@danielberkompas
Copy link
Owner

Guidance will be coming for this in the upcoming v0.7.0 release. Stay tuned.

@tielur
Copy link
Contributor Author

tielur commented Mar 20, 2018

For what it's worth I went with defining a schema in my migration that worked well. Ideally this probably shouldn't even be in a migration, probably makes more sense in a mix task. I'm looking forward to see what solution Cloak takes though. Thanks for the update!

@danielberkompas
Copy link
Owner

@tielur this is the guide that will be included in Cloak 0.7:

https://github.com/danielberkompas/cloak/blob/master/guides/how_to/encrypt_existing_data.md

@tielur
Copy link
Contributor Author

tielur commented Mar 20, 2018

@danielberkompas Awesome looks good. I like keeping that in a mix task as well. 👍

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

No branches or pull requests

2 participants