Class: RailsNewsfeed::InitGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/rails_newsfeed/init_generator.rb

Instance Method Summary collapse

Instance Method Details

#processObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/rails_newsfeed/init_generator.rb', line 10

def process
  cfg = RailsNewsfeed::Connection.config
  connection = Cassandra.cluster(cfg || {}).connect('system')
  connection.execute("DROP KEYSPACE IF EXISTS #{cfg['keyspace']}")
  connection.execute("CREATE KEYSPACE #{cfg['keyspace']}
  WITH REPLICATION={ 'class': 'SimpleStrategy', 'replication_factor': 3 }")
  connection.execute("USE #{cfg['keyspace']}")
  connection.execute("CREATE TABLE #{RailsNewsfeed::Activity.table_name}
  (id uuid, content text, time timestamp, object text, PRIMARY KEY (id))")
  connection.execute("CREATE TABLE #{RailsNewsfeed::Activity.index_table_name}
  (id uuid, content text, time timestamp, object text, PRIMARY KEY ((object), id))
  WITH CLUSTERING ORDER BY (id DESC)")
  connection.execute("CREATE TABLE #{RailsNewsfeed::FeedTable.table_name}
  (table_class text, PRIMARY KEY (table_class))")
  connection.execute("CREATE TABLE #{RailsNewsfeed::Relation.table_name}
  (id uuid, from_class text, from_id text, to_class text, to_id text, PRIMARY KEY ((from_class, from_id), id))")
  connection.execute("CREATE TABLE #{RailsNewsfeed::Relation.index_table_name}
  (id uuid, from_class text, from_id text, to_class text, to_id text,
  PRIMARY KEY ((from_class, from_id, to_class, to_id)))")
end