-
Notifications
You must be signed in to change notification settings - Fork 413
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
feat: give users the option to run the json migration asyncly #495
Conversation
41b3c7d
to
42b868b
Compare
Thanks @aqeelat for your effort! I assume that users who want to migrate normally, just run The general approach is ok for me we need to document it. @alieh-rymasheuski do you have any idea here? |
auditlog/diff.py
Outdated
@@ -189,3 +192,25 @@ def model_instance_diff( | |||
diff = None | |||
|
|||
return diff | |||
|
|||
|
|||
def _changes_func() -> Callable[["LogEntry"], Dict]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it better to move these codes to models.py
?
help="If provided, we will use native db operations.", | ||
dest="db", | ||
type=str, | ||
choices=["postgres", "mysql", "oracle", "sqllite3"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't support sqllite3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it's sqlite3
, single l
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. I saw it included in #407 (comment) and I thought it was supported.
@hramezani would you be able to write the documentation for it? Maybe in a "migration to version 3 guide" in the docs, or as a readme section. I could write the bullet points as a comment to this PR but I'm not familiar with reStructuredText enough to write a good document. Also, how do you recommend we write the tests for this pr? |
Ok, Please write them down in this PR and I will take care of documentation later
Please consider to add them in separate class to be able to remove them easily later or add some note regarding the removal |
9b8a6cc
to
fe8985f
Compare
I added a few tests but I'll come back later to polish them and add the changelog entry |
Codecov Report
@@ Coverage Diff @@
## master #495 +/- ##
==========================================
+ Coverage 94.56% 94.93% +0.37%
==========================================
Files 30 31 +1
Lines 902 988 +86
==========================================
+ Hits 853 938 +85
- Misses 49 50 +1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
a114d01
to
2fe9614
Compare
Now that I think of it, should I attach this PR to the current changelog entry? |
parser.add_argument( | ||
"-b", | ||
"--bactch-size", | ||
default=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it better to have a default batch size?
I assume if the batch size is None
it will process all the records in one shot am afraid it put pressure on databases with a lot of records.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Batching here is use to save memory not reduce the transaction size because bulk_update does batching by default. So, instead of storing a billion record in an array and then uploading batch by batch, passing -b will get each batch, process it, garbage collect it, then repeat.
But good comment. I added a default batch size of 50, with the option of not using batches.
"-b", | ||
"--bactch-size", | ||
default=None, | ||
help="Split the migration into multiple batches", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mention that this works just in case -d
is not provided.
("auditlog", "0014_logentry_cid"), | ||
] | ||
|
||
atomic = not settings.AUDITLOG_TWO_STEP_MIGRATION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the usage of this line here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I knew was that if atomic=True
(which is the default), we won't be able to rename the field type and then create another field with the same name in the same migration because they will be run in a transaction.
But after your comment, I tested it out and it worked regardless.
|
||
from auditlog import models | ||
|
||
models.changes_func = models._changes_func() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move it to auditlog/models.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I had it in the models, it was throwing an error saying that the conf is not found. Do you have any suggestions on how to fix it?
@aqeelat Thanks for your update.
Yes
It's because of your |
Good catch. I didn't know that the paginator reevaluates the qs in each iteration. I replaced it with a for-loop and it seems to be working fine now. |
@hramezani I updated the PR with the comments you suggested. |
Thanks @aqeelat LGTM 👍 Now, you need to write down the required steps for migration (as a comment to this PR). Then I will create a PR out of them later. |
Version 3.0.0 introduces breaking changes. Please review the migration guide below before upgrading. The major change in the version is that we're finally storing changes as json instead of json-text. To convert the existing records, this version has a database migration that does just that. However, this migration will take a long time if you have a huge amount of records, causing your database and application to be out of sync until the migration is complete. To avoid this, follow these steps:
|
Feel free to reword this as you see fit. |
Any updates here? @hramezani |
@aqeelat Not yet! I am too busy nowadays and as this is required for V3, it's not very urgent for me. |
Can you at least release the cid bits as a 2.x version?Sent from my iPhoneOn Apr 14, 2023, at 11:36 AM, Hasan Ramezani ***@***.***> wrote:
@aqeelat Not yet!
I am too busy nowadays and as this is required for V3, it's not very urgent for me.
I also need to add documentation for this.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@aqeelat I am ok to release it in V2, we need to:
Would you like to work on it? |
@hramezani When would you be able to approve the PR? |
@aqeelat we need to document how to do the migration. You already provided the required step for that and we have an issue. |
@hramezani I'll get something out this weekend ISA. |
Great! Please add the documentation to this PR |
890a3d8
to
4725550
Compare
@hramezani pushed |
4725550
to
1ca495e
Compare
log_entry.refresh_from_db() | ||
|
||
# Assert | ||
msg = "Not yet implemented. Run this management commad without passing a -d/--database argument." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msg = "Not yet implemented. Run this management commad without passing a -d/--database argument." | |
msg = "Not yet implemented. Run this management command without passing a -d/--database argument." |
1ca495e
to
1a3ebca
Compare
No description provided.