This commit is contained in:
Daniel Hládek 2023-02-28 12:55:44 +01:00
parent eb69ad8b7c
commit 135fe2b1f6
2 changed files with 14 additions and 11 deletions

View File

@ -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():

View File

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