您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

db_setup.py 968B

12345678910111213141516171819202122232425
  1. from cassandra.cluster import Cluster
  2. import os
  3. def db_setup(config):
  4. print(" == DB SETUP SCRIPT == ")
  5. print(f"Attempting Cassandra connection @ {config['cassandra_addresses']}:{config['cassandra_port']}")
  6. cluster = Cluster(config['cassandra_addresses'], port=config['cassandra_port'])
  7. session = cluster.connect()
  8. print(f"Connection OK")
  9. print(f"Creating KEYSPACE '{config['cassandra_keyspace']}'")
  10. with open(f"{config['setup_keyspace_dir']}/CREATE.sql") as keyspace_create:
  11. session.execute(keyspace_create.read())
  12. with open(f"{config['setup_keyspace_dir']}/USE.sql") as keyspace_use:
  13. session.execute(keyspace_use.read())
  14. for folder_name in os.listdir(config['setup_tables_dir']):
  15. print(f"Creating TABLE '{folder_name}'")
  16. with open(f"{config['setup_tables_dir']}/{folder_name}/CREATE.sql") as sql_create:
  17. session.execute(sql_create.read())
  18. print("Done!")
  19. cluster.shutdown()