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])