From 5d17b7c01ea31fd845019cb411336b9b722184e8 Mon Sep 17 00:00:00 2001 From: leonoverweel Date: Sun, 26 Feb 2017 23:52:54 +0100 Subject: Insert database rows individually in SQLite schema The Windows version of Python SQLite said multiple insertions at once was a syntax error. --- database/schema.sql | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/database/schema.sql b/database/schema.sql index 5604d419..7c17e48f 100644 --- a/database/schema.sql +++ b/database/schema.sql @@ -36,7 +36,9 @@ CREATE UNIQUE INDEX authorizations_index ON authorizations ( CREATE TABLE IF NOT EXISTS authorization_levels ( level TEXT PRIMARY KEY NOT NULL ); -INSERT INTO authorization_levels (level) VALUES ("OWN"), ("EDIT"), ("VIEW"); +INSERT INTO authorization_levels (level) VALUES ("OWN"); +INSERT INTO authorization_levels (level) VALUES ("EDIT"); +INSERT INTO authorization_levels (level) VALUES ("VIEW"); /* * A Simulation has several Paths, which define the topology of the datacenter at different times. A Simulation also @@ -205,7 +207,11 @@ CREATE TABLE IF NOT EXISTS rooms ( CREATE TABLE IF NOT EXISTS room_types ( name TEXT PRIMARY KEY NOT NULL ); -INSERT INTO room_types (name) VALUES ('SERVER'), ('HALLWAY'), ('OFFICE'), ('POWER'), ('COOLING'); +INSERT INTO room_types (name) VALUES ('SERVER'); +INSERT INTO room_types (name) VALUES ('HALLWAY'); +INSERT INTO room_types (name) VALUES ('OFFICE'); +INSERT INTO room_types (name) VALUES ('POWER'); +INSERT INTO room_types (name) VALUES ('COOLING'); /* * A room consists of tiles that have a quantized (x,y) position. The same tile can't be in multiple rooms. All tiles @@ -293,7 +299,9 @@ CREATE TABLE IF NOT EXISTS objects ( CREATE TABLE IF NOT EXISTS object_types ( name TEXT PRIMARY KEY NOT NULL ); -INSERT INTO object_types (name) VALUES ('PSU'), ('COOLING_ITEM'), ('RACK'); +INSERT INTO object_types (name) VALUES ('PSU'); +INSERT INTO object_types (name) VALUES ('COOLING_ITEM'); +INSERT INTO object_types (name) VALUES ('RACK'); -- Allowed objects table CREATE TABLE IF NOT EXISTS allowed_objects ( -- cgit v1.2.3 From 5990c005edb42a5e064224a03fed32522a66047e Mon Sep 17 00:00:00 2001 From: leonoverweel Date: Mon, 27 Feb 2017 00:08:58 +0100 Subject: Add Python database rebuilder This one allows you to specify the location of the database. --- database/rebuild-database.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 database/rebuild-database.py diff --git a/database/rebuild-database.py b/database/rebuild-database.py new file mode 100644 index 00000000..6e10b646 --- /dev/null +++ b/database/rebuild-database.py @@ -0,0 +1,31 @@ +import os +import sqlite3 +import sys + +sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) + +try: + BASE_DIR = directory_name=sys.argv[1] +except: + BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +db_location = os.path.join(BASE_DIR, 'opendc.db') + +print "Removing old database..." +os.remove(db_location) + +print "Connecting to new database..." +conn = sqlite3.connect(db_location) +c = conn.cursor() + +print "Importing schema..." +with open('schema.sql') as schema: + c.executescript(schema.read()) + +print "Importing test data..." +with open('test.sql') as test: + c.executescript(test.read()) + +conn.commit() +conn.close() + +print "Done." -- cgit v1.2.3 From 8e2c8d669aa547cf8749fa774160f4d05fff121a Mon Sep 17 00:00:00 2001 From: leonoverweel Date: Mon, 27 Feb 2017 02:14:04 +0100 Subject: Add Python script to view a table in the db --- database/view-table.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 database/view-table.py diff --git a/database/view-table.py b/database/view-table.py new file mode 100644 index 00000000..615b4081 --- /dev/null +++ b/database/view-table.py @@ -0,0 +1,17 @@ +import os +import sqlite3 +import sys + +try: + BASE_DIR = directory_name=sys.argv[1] +except: + BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +db_location = os.path.join(BASE_DIR, 'opendc.db') + +conn = sqlite3.connect(db_location) +c = conn.cursor() + +rows = c.execute('SELECT * FROM ' + sys.argv[2]) + +for row in rows: + print row -- cgit v1.2.3 From 9aba4c3591f8549cd02084b05ce7e1a456de8899 Mon Sep 17 00:00:00 2001 From: leonoverweel Date: Mon, 27 Feb 2017 02:14:15 +0100 Subject: Add README.md for /database --- database/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 database/README.md diff --git a/database/README.md b/database/README.md new file mode 100644 index 00000000..9fba2d5c --- /dev/null +++ b/database/README.md @@ -0,0 +1,13 @@ +# OpenDC Database + +To rebuild the database at a location (or in this directory if none is specified): + +```bash +python rebuild-database.py "path/to/database/directory" +``` + +To view a table in the database: + +```bash +python view-table.py "path/to/database/directory" table_name +``` -- cgit v1.2.3 From efb1a88fbf7c7993af0aff4b6eeac22232f72bcc Mon Sep 17 00:00:00 2001 From: leonoverweel Date: Mon, 27 Feb 2017 02:40:19 +0100 Subject: Fix bug creating new experiments Also update all other submodules. --- opendc-frontend | 2 +- opendc-simulator | 2 +- opendc-web-server | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/opendc-frontend b/opendc-frontend index 50fcb063..df654496 160000 --- a/opendc-frontend +++ b/opendc-frontend @@ -1 +1 @@ -Subproject commit 50fcb0634c9ebe894988103184d50d372bc76907 +Subproject commit df65449694e17a367e59b112c0cc12d66c387ca9 diff --git a/opendc-simulator b/opendc-simulator index 0759126f..0709a812 160000 --- a/opendc-simulator +++ b/opendc-simulator @@ -1 +1 @@ -Subproject commit 0759126fcf9b1e58341b95a0181678d337fca370 +Subproject commit 0709a81231b695caecb2269fe23d8dadeb764892 diff --git a/opendc-web-server b/opendc-web-server index 1b942d9e..855b6549 160000 --- a/opendc-web-server +++ b/opendc-web-server @@ -1 +1 @@ -Subproject commit 1b942d9e9d5b2c08d09fb8f294437ea99a889962 +Subproject commit 855b654942d400204ea3ce952b5fe0cebf8492c2 -- cgit v1.2.3