· 8 years ago · Feb 15, 2018, 06:52 PM
1from cassandra.cluster import Cluster
2
3cluster = Cluster(['172.17.0.2'])
4session = cluster.connect()
5session.execute("""
6 CREATE KEYSPACE IF NOT EXISTS cinemadb
7 WITH REPLICATION = {
8 'class' : 'SimpleStrategy',
9 'replication_factor' : 1 };
10 """)
11session.set_keyspace('cinemadb')
12session.execute("""
13 CREATE TABLE IF NOT EXISTS cinemas (
14 id uuid,
15 name text,
16 PRIMARY KEY (id)
17 );
18 """)
19session.execute("""
20 CREATE TABLE IF NOT EXISTS movies (
21 id uuid,
22 name text,
23 description text,
24 cover blob,
25 PRIMARY KEY (id)
26 );
27 """)
28session.execute("""
29 CREATE TABLE IF NOT EXISTS sessions (
30 movie_id uuid,
31 cinema_id uuid,
32 date timestamp,
33 id uuid,
34 hall_id text,
35 hall_name text,
36 hall_capacity int,
37 PRIMARY KEY ((movie_id), cinema_id, date, id)
38 );
39 """)
40session.execute("""
41 CREATE TABLE IF NOT EXISTS tickets (
42 session_id uuid,
43 timestamp timestamp,
44 user text,
45 PRIMARY KEY ((session_id), timestamp)
46 );
47 """)
48cluster.shutdown()