use test;
drop table if exists ruleset;

CREATE TABLE ruleset (
presentity VARCHAR(255) NOT NULL,
ruleid VARCHAR(255) NOT NULL, 
sphere VARCHAR(255), 
validity_from DATETIME,
validity_to DATETIME,        
subhandling enum('block','confirm','polite-block','allow') NOT NULL default 'block', 
provide_all_services TINYINT(1) NOT NULL default 0,
provide_all_devices TINYINT(1) NOT NULL default 0,
provide_all_persons TINYINT(1) NOT NULL default 0, 
provide_activities TINYINT(1) NOT NULL default 0, 
provide_class TINYINT(1) NOT NULL default 0, 
provide_device_id TINYINT(1) NOT NULL default 0, 
provide_mood TINYINT(1) NOT NULL default 0, 
provide_place_type TINYINT(1) NOT NULL default 0, 
provide_place_is TINYINT(1) NOT NULL default 0, 
provide_privacy TINYINT(1) NOT NULL default 0, 
provide_relationship TINYINT(1) NOT NULL default 0, 
provide_status_icon TINYINT(1) NOT NULL default 0, 
provide_sphere TINYINT(1) NOT NULL default 0, 
provide_time_offset TINYINT(1) NOT NULL default 0, 
provide_user_input enum('false','bare','thresholds','full') NOT NULL default 'false', 
provide_note TINYINT(1) NOT NULL default 0, 
provide_unknown_attribute TINYINT(1) NOT NULL default 0, 
unknown_attribute_name VARCHAR(255),
PRIMARY KEY(presentity,ruleid));

drop table if exists ruleidentity;

CREATE TABLE ruleidentity (
presentity VARCHAR(255) NOT NULL,
ruleid VARCHAR(255) NOT NULL,
one_id VARCHAR(255), 
scheme VARCHAR(255), 
except_id VARCHAR(255),
except_scheme VARCHAR(255), 
except_domain VARCHAR(255),
many_domain VARCHAR(255));

drop table if exists servicepermission;

CREATE TABLE servicepermission ( 
presentity VARCHAR(255) NOT NULL,
ruleid VARCHAR(255) NOT NULL, 
service_type VARCHAR(255) NOT NULL, 
service_value  VARCHAR(255) NOT NULL);

drop table if exists devicepermission;

CREATE TABLE devicepermission ( 
presentity VARCHAR(255) NOT NULL,
ruleid VARCHAR(255) NOT NULL, 
device_type VARCHAR(255) NOT NULL, 
device_value  VARCHAR(255) NOT NULL);

drop table if exists personpermission;

CREATE TABLE personpermission ( 
presentity VARCHAR(255) NOT NULL,
ruleid VARCHAR(255) NOT NULL, 
person_type VARCHAR(255) NOT NULL, 
person_value  VARCHAR(255) NOT NULL);


