Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

teardown.py 797B

123456789101112131415161718192021
  1. from settings import cassandra_addresses, cassandra_port, cassandra_keyspace, setup_tables_dir, setup_db_dir
  2. from cassandra.cluster import Cluster
  3. import os
  4. print(" == DB TEARDOWN SCRIPT == ")
  5. print(f"Attempting Cassandra connection @ {cassandra_addresses}:{cassandra_port}")
  6. cluster = Cluster(cassandra_addresses, port=cassandra_port)
  7. session = cluster.connect(cassandra_keyspace)
  8. print(f"Connection OK")
  9. for folder_name in os.listdir(setup_tables_dir):
  10. print(f"Dropping table {folder_name}")
  11. with open(f'{setup_tables_dir}/{folder_name}/DROP.sql') as sql_drop:
  12. session.execute(sql_drop.read())
  13. with open(f"{setup_db_dir}/keyspace/DROP.sql") as keyspace_create:
  14. print(f"Dropping keyspace {cassandra_keyspace}")
  15. session.execute(keyspace_create.read())
  16. print("Done!")