--version:15
CREATE TABLE IF NOT EXISTS local_software_release_root%(version)s (
  path VARCHAR(255)
);
INSERT INTO local_software_release_root%(version)s VALUES(NULL);

CREATE TABLE IF NOT EXISTS software%(version)s (
  url VARCHAR(255),
  compute_node_reference VARCHAR(255) DEFAULT '%(compute_node)s',
  requested_state VARCHAR(255) DEFAULT 'available',
  CONSTRAINT uniq PRIMARY KEY (url, compute_node_reference)
);

CREATE TABLE IF NOT EXISTS compute_node%(version)s (
  reference VARCHAR(255) DEFAULT '%(compute_node)s',
  address VARCHAR(255),
  netmask VARCHAR(255),
  CONSTRAINT uniq PRIMARY KEY (reference)
);

CREATE TABLE IF NOT EXISTS partition%(version)s (
  reference VARCHAR(255),
  compute_node_reference VARCHAR(255) DEFAULT '%(compute_node)s',
  slap_state VARCHAR(255) DEFAULT 'free',
  software_release VARCHAR(255),
  xml TEXT,
  connection_xml TEXT,
  slave_instance_list TEXT,
  software_type VARCHAR(255),
  partition_reference VARCHAR(255), -- name of the instance
  requested_by VARCHAR(255), -- only used for debugging,
                             -- slapproxy does not support proper scope
  requested_state VARCHAR(255) NOT NULL DEFAULT 'started',
  timestamp REAL,
  CONSTRAINT uniq PRIMARY KEY (reference, compute_node_reference)
);

CREATE TABLE IF NOT EXISTS slave%(version)s (
  reference VARCHAR(255), -- unique slave reference
  compute_node_reference VARCHAR(255) DEFAULT '%(compute_node)s',
  connection_xml TEXT,
  hosted_by VARCHAR(255),
  asked_by VARCHAR(255) -- only used for debugging,
                        -- slapproxy does not support proper scope
);

CREATE TABLE IF NOT EXISTS partition_network%(version)s (
  partition_reference VARCHAR(255),
  compute_node_reference VARCHAR(255) DEFAULT '%(compute_node)s',
  reference VARCHAR(255),
  address VARCHAR(255),
  netmask VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS forwarded_partition_request%(version)s (
  partition_reference VARCHAR(255), -- a.k.a source_instance_id
  master_url VARCHAR(255)
);
