mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-26 00:46:22 +02:00
Collection management (#520)
* Tech spec * Refactored Cassanda knowledge graph for single table * Collection management, librarian services to manage metadata and collection deletion
This commit is contained in:
parent
48016d8fb2
commit
13ff7d765d
48 changed files with 2941 additions and 425 deletions
72
trustgraph-cli/trustgraph/cli/delete_collection.py
Normal file
72
trustgraph-cli/trustgraph/cli/delete_collection.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
"""
|
||||
Delete a collection and all its data
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from trustgraph.api import Api
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_user = "trustgraph"
|
||||
|
||||
def delete_collection(url, user, collection, confirm):
|
||||
|
||||
if not confirm:
|
||||
response = input(f"Are you sure you want to delete collection '{collection}' and all its data? (y/N): ")
|
||||
if response.lower() not in ['y', 'yes']:
|
||||
print("Operation cancelled.")
|
||||
return
|
||||
|
||||
api = Api(url).collection()
|
||||
|
||||
api.delete_collection(user=user, collection=collection)
|
||||
|
||||
print(f"Collection '{collection}' deleted successfully.")
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-delete-collection',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'collection',
|
||||
help='Collection ID to delete'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-u', '--api-url',
|
||||
default=default_url,
|
||||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-U', '--user',
|
||||
default=default_user,
|
||||
help=f'User ID (default: {default_user})'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-y', '--yes',
|
||||
action='store_true',
|
||||
help='Skip confirmation prompt'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
delete_collection(
|
||||
url = args.api_url,
|
||||
user = args.user,
|
||||
collection = args.collection,
|
||||
confirm = args.yes
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue