-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add the delete_missing_records option. #47
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
.pytest_cache/ | ||
*.py[cod] | ||
*$py.class | ||
.venv/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,18 @@ | |
from .kinto2yaml import introspect_server | ||
|
||
|
||
async def initialize_server(async_client, config, bucket=None, collection=None, force=False): | ||
async def initialize_server(async_client, config, bucket=None, collection=None, | ||
force=False, delete_missing_records=False): | ||
logger.debug("Converting YAML config into a server batch.") | ||
bid = bucket | ||
cid = collection | ||
# 1. Introspect current server state. | ||
if not force: | ||
if not force or delete_missing_records: | ||
current_server_status = await introspect_server( | ||
async_client, | ||
bucket=bucket, | ||
collection=collection | ||
collection=collection, | ||
records=delete_missing_records | ||
) | ||
else: | ||
# We don't need to load it because we will override it nevertheless. | ||
|
@@ -143,5 +145,24 @@ async def initialize_server(async_client, config, bucket=None, collection=None, | |
data=record_data, | ||
permissions=record_permissions) | ||
|
||
if delete_missing_records and collection_records: | ||
# Fetch all records IDs | ||
file_records_ids = set(collection_records.keys()) | ||
server_records_ids = set(current_collection['records'].keys()) | ||
|
||
to_delete = server_records_ids - file_records_ids | ||
if not force: | ||
message = ("Are you sure that you want to delete the " | ||
"following {} records?".format(len(list(to_delete)))) | ||
value = input(message) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember but we may have an option to always accept prompts, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We currently don't have any prompts. We might want to add a |
||
print(to_delete) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want this print? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured it would give extra information about the records that are going to be deleted. But I could do it only in verbose mode maybe? |
||
if value.lower() not in ['y', 'yes']: | ||
print("Exiting") | ||
exit(1) | ||
for record_id in to_delete: | ||
batch.delete_record(id=record_id, | ||
bucket=bucket_id, | ||
collection=collection_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice if we could generalize it to bucket/collections/groups There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For groups it might make sense, but for buckets and collections I would rather not trust kinto-wizard for such a dangerous task 😂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have created #48 for that purpose. I believe we might need specifics option for each There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why would be buckets so different? If we prompt, I don't see the problem... |
||
|
||
logger.debug('Sending batch:\n\n%s' % batch.session.requests) | ||
logger.info("Batch uploaded") |
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.
Something like To delete the existing records that are not in the YAML file would be better maybe ?