From 981ba5c5f30549dbd233fab1e52bb774fd3eebe1 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 4 Aug 2015 23:24:46 +0200 Subject: o Adding Trireme setup to support migrating the Cassandra schema. --- .gitignore | 2 ++ README.md | 42 +++-------------------- init.cql | 5 +++ trireme/config.py | 9 +++++ trireme/db/migrations/2015-08-04_0_sm_by_day.cql | 10 ++++++ trireme/db/migrations/2015-08-04_1_raw_record.cql | 9 +++++ trireme/tasks.py | 4 +++ 7 files changed, 44 insertions(+), 37 deletions(-) create mode 100644 init.cql create mode 100644 trireme/config.py create mode 100644 trireme/db/migrations/2015-08-04_0_sm_by_day.cql create mode 100644 trireme/db/migrations/2015-08-04_1_raw_record.cql create mode 100644 trireme/tasks.py diff --git a/.gitignore b/.gitignore index 2291abb..bc828e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .idea *.iml build + +*.pyc diff --git a/README.md b/README.md index 5d39e63..4ff94fc 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,9 @@ -# Soil Moisture Schema +# Initialization Cassandra - CREATE TABLE sm_by_day ( - device text, - day text, - timestamp timestamp, - sensors list>>, - PRIMARY KEY ( - (device, day), - timestamp - ) - ); +This creates the `soil_moisture` schema and `migrations` table for Trireme. -# Raw Schema + $ cqlsh -f init.cql - CREATE TABLE raw_record ( - day text, - timestamp timestamp, - records list>>, - PRIMARY KEY ( - (day), - timestamp - ) - ); +# Update Cassandra with new migrations -# Create Schema - - $ bin/cqlsh - cqlsh> create keyspace soil_moisture WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}; - cqlsh> use soil_moisture; - cqlsh:soil_moisture> - create table sm_by_day( - device text, - day text, - timestamp timestamp, - sensors list>>, - primary key( - (device, day), - timestamp - ) - ); + $ inv trireme.cassandra.migrate diff --git a/init.cql b/init.cql new file mode 100644 index 0000000..cf5865e --- /dev/null +++ b/init.cql @@ -0,0 +1,5 @@ +CREATE KEYSPACE soil_moisture WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true; + +CREATE TABLE soil_moisture.migrations ( + migration text PRIMARY KEY +); diff --git a/trireme/config.py b/trireme/config.py new file mode 100644 index 0000000..e198dbe --- /dev/null +++ b/trireme/config.py @@ -0,0 +1,9 @@ +contact_points = ['127.0.0.1'] +keyspace = 'soil_moisture' + +username = None +password = None + +migration_master = True + +solr_url = 'http://127.0.0.1:8983/solr' diff --git a/trireme/db/migrations/2015-08-04_0_sm_by_day.cql b/trireme/db/migrations/2015-08-04_0_sm_by_day.cql new file mode 100644 index 0000000..776cd23 --- /dev/null +++ b/trireme/db/migrations/2015-08-04_0_sm_by_day.cql @@ -0,0 +1,10 @@ +CREATE TABLE sm_by_day ( + device text, + day text, + timestamp timestamp, + sensors list>>, + PRIMARY KEY ( + (device, day), + timestamp + ) +); diff --git a/trireme/db/migrations/2015-08-04_1_raw_record.cql b/trireme/db/migrations/2015-08-04_1_raw_record.cql new file mode 100644 index 0000000..85c4ecb --- /dev/null +++ b/trireme/db/migrations/2015-08-04_1_raw_record.cql @@ -0,0 +1,9 @@ +CREATE TABLE raw_record ( + day text, + timestamp timestamp, + records list>>, + PRIMARY KEY ( + (day), + timestamp + ) +); diff --git a/trireme/tasks.py b/trireme/tasks.py new file mode 100644 index 0000000..de586ef --- /dev/null +++ b/trireme/tasks.py @@ -0,0 +1,4 @@ +from invoke import Collection +from trireme import trireme + +namespace = Collection(trireme) -- cgit v1.2.3