From 135fe2b1f6d59f6978f7fd8555bfbb86aa49d8e9 Mon Sep 17 00:00:00 2001 From: Daniel Hladek Date: Tue, 28 Feb 2023 12:55:44 +0100 Subject: [PATCH] zz --- websucker/cli.py | 9 ++++++--- websucker/schema.py | 16 ++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/websucker/cli.py b/websucker/cli.py index 006b20a..32a1a41 100644 --- a/websucker/cli.py +++ b/websucker/cli.py @@ -11,7 +11,7 @@ import pprint import greenstalk import os -from websucker import schema +import websucker.schema def create_database_from_context(ctx): @@ -197,10 +197,13 @@ def summary(ctx): def create_database(ctx,replication,strategy): cluster = websucker.db.connect_cluster(ctx.obj["cassandra_host"],ctx.obj["cassandra_port"],ctx.obj["cassandra_username"],ctx.obj["cassandra_password"]) with cluster.connect() as session: - query = "CREATE KEYSPACE {} WITH replication = {'class':'{}', 'replication_factor' : {}}".format(ctx.obj["cassandra_keyspace"],strategy,replication) + session.execute("DROP keyspace IF EXISTS {}".format(ctx.obj["cassandra_keyspace"])) + repo = "{{'class':'{}','replication_factor':{}}}".format(strategy,replication) + query = "CREATE KEYSPACE {} WITH replication = {}".format(ctx.obj["cassandra_keyspace"],repo) + print(query) session.execute(query) session.set_keyspace(ctx.obj["cassandra_keyspace"]) - model.create_database() + websucker.schema.create_database(ctx.obj["cassandra_keyspace"],session) @cli.command(help="Print keyspace schema") def schema(): diff --git a/websucker/schema.py b/websucker/schema.py index 0525ea6..8a15b2c 100644 --- a/websucker/schema.py +++ b/websucker/schema.py @@ -91,11 +91,11 @@ class DomainConnections(Model): domain_name = columns.Text(primary_key=True) linked_domain = columns.Text(primary_key=True) -def create_db(): - sync_table(Links) - sync_table(DailyLinks) - sync_table(DomainQuality) - sync_table(Content) - sync_table(ParagraphChecksums) - sync_table(Html) - sync_table(DomainConnections) +def create_database(keyspace,session): + sync_table(Links,keyspaces=[keyspace],connections=[session]) + sync_table(DailyLinks,keyspaces=[keyspace],connections=[session]) + sync_table(DomainQuality,keyspaces=[keyspace],connections=[session]) + sync_table(Content,keyspaces=[keyspace],connections=[session]) + sync_table(ParagraphChecksums,keyspaces=[keyspace],connections=[session]) + sync_table(Html,keyspaces=[keyspace],connections=[session]) + sync_table(DomainConnections,keyspaces=[keyspace],connections=[session])