Skip to content

Commit

Permalink
#1962: setup_tables.py, remove 'db_query.py' dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff1evesque committed Aug 17, 2015
1 parent 4bb9ef0 commit e409d64
Showing 1 changed file with 48 additions and 51 deletions.
99 changes: 48 additions & 51 deletions puppet/scripts/setup_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,57 @@
#
# @tbl_observation_label, record every unique observation label, with respect to a
# given 'id_entity'.
from brain.database.db_query import SQL
import MySQLdb as DB

## local variables
sql = SQL(user='provisioner', passwd='password')
## create connection
conn = DB.connect('localhost', 'provisioner', 'password', 'db_machine_learning')

## connect to database
sql.sql_connect('db_machine_learning')
with conn:
## create cursor object
cur = conn.cursor()

## create 'tbl_feature_count'
sql_statement = '''\
CREATE TABLE IF NOT EXISTS tbl_feature_count (
id_size INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_entity INT NOT NULL,
count_features INT NOT NULL
);
'''
sql.sql_command(sql_statement, 'create')
## create 'tbl_feature_count'
sql_statement = '''\
CREATE TABLE IF NOT EXISTS tbl_feature_count (
id_size INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_entity INT NOT NULL,
count_features INT NOT NULL
);
'''
cur.execute(sql_statement)

## create 'tbl_dataset_entity'
sql_statement = '''\
CREATE TABLE IF NOT EXISTS tbl_dataset_entity (
id_entity INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR (50) NOT NULL,
uid_created INT NOT NULL,
datetime_created DATETIME NOT NULL,
uid_modified INT NULL,
datetime_modified DATETIME NULL
);
'''
sql.sql_command(sql_statement, 'create')
## create 'tbl_dataset_entity'
sql_statement = '''\
CREATE TABLE IF NOT EXISTS tbl_dataset_entity (
id_entity INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR (50) NOT NULL,
uid_created INT NOT NULL,
datetime_created DATETIME NOT NULL,
uid_modified INT NULL,
datetime_modified DATETIME NULL
);
'''
cur.execute(sql_statement)

## create 'tbl_observation_label'
sql_statement = '''\
CREATE TABLE IF NOT EXISTS tbl_observation_label (
id_label INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_entity INT NOT NULL,
dep_variable_label VARCHAR(75) NOT NULL
);
'''
sql.sql_command(sql_statement, 'create')
## create 'tbl_observation_label'
sql_statement = '''\
CREATE TABLE IF NOT EXISTS tbl_observation_label (
id_label INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_entity INT NOT NULL,
dep_variable_label VARCHAR(75) NOT NULL
);
'''
cur.execute(sql_statement)

## create 'tbl_feature_value'
sql_statement = '''\
CREATE TABLE IF NOT EXISTS tbl_feature_value (
id_value INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_entity INT NOT NULL,
dep_variable_label VARCHAR (50) NOT NULL,
indep_variable_label VARCHAR (50) NOT NULL,
indep_variable_value FLOAT NOT NULL,
CONSTRAINT FK_dataset_entity FOREIGN KEY (id_entity) REFERENCES tbl_dataset_entity (id_entity)
);
'''
sql.sql_command(sql_statement, 'create')

# retrieve any error(s), disconnect from database
if sql.get_errors(): print sql.return_error()
sql.sql_disconnect()
## create 'tbl_feature_value'
sql_statement = '''\
CREATE TABLE IF NOT EXISTS tbl_feature_value (
id_value INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_entity INT NOT NULL,
dep_variable_label VARCHAR (50) NOT NULL,
indep_variable_label VARCHAR (50) NOT NULL,
indep_variable_value FLOAT NOT NULL,
CONSTRAINT FK_dataset_entity FOREIGN KEY (id_entity) REFERENCES tbl_dataset_entity (id_entity)
);
'''
cur.execute(sql_statement)

0 comments on commit e409d64

Please sign in to comment.