drop database galaxy;
create database galaxy;
use galaxy;
CREATE TABLE migrate_version (
	repository_id VARCHAR(255) NOT NULL, 
	repository_path TEXT, 
	version INTEGER, 
	PRIMARY KEY (repository_id)
);

CREATE TABLE galaxy_user (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	email VARCHAR(255) NOT NULL, 
	password VARCHAR(40) NOT NULL, 
	external BOOLEAN, deleted BOOLEAN, purged BOOLEAN, username VARCHAR(255), form_values_id INTEGER, 
	PRIMARY KEY (id)
);
CREATE TABLE history (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	user_id INTEGER, 
	name VARCHAR(255), 
	hid_counter INTEGER, 
	deleted BOOLEAN, 
	purged BOOLEAN, 
	genome_build VARCHAR(40), importable BOOLEAN, slug TEXT, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id)
);
CREATE TABLE galaxy_session (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	user_id INTEGER, 
	remote_host VARCHAR(255), 
	remote_addr VARCHAR(255), 
	referer TEXT, 
	current_history_id INTEGER, 
	session_key VARCHAR(255), 
	is_valid BOOLEAN, 
	prev_session_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 FOREIGN KEY(current_history_id) REFERENCES history (id)
);
CREATE TABLE job (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	history_id INTEGER, 
	tool_id VARCHAR(255), 
	tool_version TEXT, 
	state VARCHAR(64), 
	info VARCHAR(255), 
	command_line TEXT, 
	param_filename VARCHAR(1024), 
	runner_name VARCHAR(255), 
	stdout TEXT, 
	stderr TEXT, 
	traceback TEXT, 
	session_id INTEGER, 
	job_runner_name VARCHAR(255), 
	job_runner_external_id VARCHAR(255), library_folder_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(history_id) REFERENCES history (id), 
	 FOREIGN KEY(session_id) REFERENCES galaxy_session (id)
);
CREATE TABLE job_parameter (
	id INTEGER NOT NULL, 
	job_id INTEGER, 
	name VARCHAR(255), 
	value TEXT, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(job_id) REFERENCES job (id)
);
CREATE TABLE event (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	history_id INTEGER, 
	user_id INTEGER, 
	message VARCHAR(1024), 
	session_id INTEGER, 
	tool_id VARCHAR(255), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(history_id) REFERENCES history (id), 
	 FOREIGN KEY(session_id) REFERENCES galaxy_session (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id)
);
CREATE TABLE galaxy_session_to_history (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	session_id INTEGER, 
	history_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(session_id) REFERENCES galaxy_session (id), 
	 FOREIGN KEY(history_id) REFERENCES history (id)
);
CREATE TABLE stored_workflow (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	user_id INTEGER NOT NULL, 
	latest_workflow_id INTEGER, 
	name TEXT, 
	deleted BOOLEAN, importable BOOLEAN, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 CONSTRAINT stored_workflow_latest_workflow_id_fk FOREIGN KEY(latest_workflow_id) REFERENCES workflow (id)
);
CREATE TABLE stored_workflow_menu_entry (
	id INTEGER NOT NULL, 
	stored_workflow_id INTEGER, 
	user_id INTEGER, 
	order_index INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(stored_workflow_id) REFERENCES stored_workflow (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id)
);
CREATE TABLE workflow (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	stored_workflow_id INTEGER NOT NULL, 
	name TEXT, 
	has_cycles BOOLEAN, 
	has_errors BOOLEAN, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(stored_workflow_id) REFERENCES stored_workflow (id)
);
CREATE TABLE workflow_step (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	workflow_id INTEGER NOT NULL, 
	type VARCHAR(64), 
	tool_id TEXT, 
	tool_version TEXT, 
	tool_inputs BLOB, 
	tool_errors BLOB, 
	position BLOB, 
	config BLOB, 
	order_index INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(workflow_id) REFERENCES workflow (id)
);
CREATE TABLE workflow_step_connection (
	id INTEGER NOT NULL, 
	output_step_id INTEGER, 
	input_step_id INTEGER, 
	output_name TEXT, 
	input_name TEXT, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(output_step_id) REFERENCES workflow_step (id), 
	 FOREIGN KEY(input_step_id) REFERENCES workflow_step (id)
);
CREATE TABLE stored_workflow_user_share_connection (
	id INTEGER NOT NULL, 
	stored_workflow_id INTEGER, 
	user_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(stored_workflow_id) REFERENCES stored_workflow (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id)
);
CREATE TABLE dataset (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	state VARCHAR(64), 
	deleted BOOLEAN, 
	purged BOOLEAN, 
	purgable BOOLEAN, 
	external_filename TEXT, 
	_extra_files_path TEXT, 
	file_size NUMERIC(15, 0), 
	PRIMARY KEY (id)
);
CREATE TABLE history_dataset_association (
	id INTEGER NOT NULL, 
	history_id INTEGER, 
	dataset_id INTEGER, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	copied_from_history_dataset_association_id INTEGER, 
	hid INTEGER, 
	name VARCHAR(255), 
	info VARCHAR(255), 
	blurb VARCHAR(255), 
	peek TEXT, 
	extension VARCHAR(64), 
	metadata BLOB, 
	parent_id INTEGER, 
	designation VARCHAR(255), 
	deleted BOOLEAN, 
	visible BOOLEAN, copied_from_library_dataset_dataset_association_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(history_id) REFERENCES history (id), 
	 FOREIGN KEY(parent_id) REFERENCES history_dataset_association (id), 
	 FOREIGN KEY(copied_from_history_dataset_association_id) REFERENCES history_dataset_association (id), 
	 FOREIGN KEY(dataset_id) REFERENCES dataset (id)
);
CREATE TABLE job_to_input_dataset (
	id INTEGER NOT NULL, 
	job_id INTEGER, 
	dataset_id INTEGER, 
	name VARCHAR(255), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(job_id) REFERENCES job (id), 
	 FOREIGN KEY(dataset_id) REFERENCES history_dataset_association (id)
);
CREATE TABLE validation_error (
	id INTEGER NOT NULL, 
	dataset_id INTEGER, 
	message VARCHAR(255), 
	err_type VARCHAR(64), 
	attributes TEXT, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(dataset_id) REFERENCES history_dataset_association (id)
);
CREATE TABLE implicitly_converted_dataset_association (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	hda_id INTEGER, 
	hda_parent_id INTEGER, 
	deleted BOOLEAN, 
	metadata_safe BOOLEAN, 
	type VARCHAR(255), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(hda_id) REFERENCES history_dataset_association (id), 
	 FOREIGN KEY(hda_parent_id) REFERENCES history_dataset_association (id)
);
CREATE TABLE job_to_output_dataset (
	id INTEGER NOT NULL, 
	job_id INTEGER, 
	dataset_id INTEGER, 
	name VARCHAR(255), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(job_id) REFERENCES job (id), 
	 FOREIGN KEY(dataset_id) REFERENCES history_dataset_association (id)
);
CREATE TABLE metadata_file (
	id INTEGER NOT NULL, 
	name TEXT, 
	hda_id INTEGER, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	deleted BOOLEAN, 
	purged BOOLEAN, lda_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(hda_id) REFERENCES history_dataset_association (id)
);
CREATE TABLE library_folder (
	id INTEGER NOT NULL, 
	parent_id INTEGER, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	name TEXT, 
	description TEXT, 
	order_id INTEGER, 
	item_count INTEGER, 
	deleted BOOLEAN, 
	purged BOOLEAN, 
	genome_build VARCHAR(40), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(parent_id) REFERENCES library_folder (id)
);
CREATE TABLE library (
	id INTEGER NOT NULL, 
	root_folder_id INTEGER, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	name VARCHAR(255), 
	deleted BOOLEAN, 
	purged BOOLEAN, 
	description TEXT, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(root_folder_id) REFERENCES library_folder (id)
);
CREATE TABLE library_dataset (
	id INTEGER NOT NULL, 
	library_dataset_dataset_association_id INTEGER, 
	folder_id INTEGER, 
	order_id INTEGER, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	name VARCHAR(255), 
	info VARCHAR(255), 
	deleted BOOLEAN, 
	PRIMARY KEY (id), 
	 CONSTRAINT library_dataset_dataset_association_id_fk FOREIGN KEY(library_dataset_dataset_association_id) REFERENCES library_dataset_dataset_association (id), 
	 FOREIGN KEY(folder_id) REFERENCES library_folder (id)
);
CREATE TABLE library_dataset_dataset_association (
	id INTEGER NOT NULL, 
	library_dataset_id INTEGER, 
	dataset_id INTEGER, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	copied_from_history_dataset_association_id INTEGER, 
	copied_from_library_dataset_dataset_association_id INTEGER, 
	name VARCHAR(255), 
	info VARCHAR(255), 
	blurb VARCHAR(255), 
	peek TEXT, 
	extension VARCHAR(64), 
	metadata BLOB, 
	parent_id INTEGER, 
	designation VARCHAR(255), 
	deleted BOOLEAN, 
	visible BOOLEAN, 
	user_id INTEGER, 
	message VARCHAR(255), 
	PRIMARY KEY (id), 
	 CONSTRAINT history_dataset_association_dataset_id_fkey FOREIGN KEY(copied_from_history_dataset_association_id) REFERENCES history_dataset_association (id), 
	 FOREIGN KEY(library_dataset_id) REFERENCES library_dataset (id), 
	 CONSTRAINT library_dataset_dataset_association_id_fkey FOREIGN KEY(copied_from_library_dataset_dataset_association_id) REFERENCES library_dataset_dataset_association (id), 
	 FOREIGN KEY(parent_id) REFERENCES library_dataset_dataset_association (id), 
	 FOREIGN KEY(dataset_id) REFERENCES dataset (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id)
);
CREATE TABLE job_external_output_metadata (
	id INTEGER NOT NULL, 
	job_id INTEGER, 
	history_dataset_association_id INTEGER, 
	library_dataset_dataset_association_id INTEGER, 
	filename_in VARCHAR(255), 
	filename_out VARCHAR(255), 
	filename_results_code VARCHAR(255), 
	filename_kwds VARCHAR(255), 
	job_runner_external_pid VARCHAR(255), filename_override_metadata VARCHAR(255), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(job_id) REFERENCES job (id), 
	 FOREIGN KEY(history_dataset_association_id) REFERENCES history_dataset_association (id), 
	 FOREIGN KEY(library_dataset_dataset_association_id) REFERENCES library_dataset_dataset_association (id)
);
CREATE TABLE galaxy_group (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	name VARCHAR(255), 
	deleted BOOLEAN, 
	PRIMARY KEY (id)
);
CREATE TABLE user_group_association (
	id INTEGER NOT NULL, 
	user_id INTEGER, 
	group_id INTEGER, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 FOREIGN KEY(group_id) REFERENCES galaxy_group (id)
);
CREATE TABLE role (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	name VARCHAR(255), 
	description TEXT, 
	type VARCHAR(40), 
	deleted BOOLEAN, 
	PRIMARY KEY (id)
);
CREATE TABLE library_permissions (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	action TEXT, 
	library_id INTEGER, 
	role_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(library_id) REFERENCES library (id), 
	 FOREIGN KEY(role_id) REFERENCES role (id)
);
CREATE TABLE library_dataset_permissions (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	action TEXT, 
	library_dataset_id INTEGER, 
	role_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(library_dataset_id) REFERENCES library_dataset (id), 
	 FOREIGN KEY(role_id) REFERENCES role (id)
);
CREATE TABLE dataset_permissions (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	action TEXT, 
	dataset_id INTEGER, 
	role_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(dataset_id) REFERENCES dataset (id), 
	 FOREIGN KEY(role_id) REFERENCES role (id)
);
CREATE TABLE user_role_association (
	id INTEGER NOT NULL, 
	user_id INTEGER, 
	role_id INTEGER, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 FOREIGN KEY(role_id) REFERENCES role (id)
);
CREATE TABLE default_user_permissions (
	id INTEGER NOT NULL, 
	user_id INTEGER, 
	action TEXT, 
	role_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 FOREIGN KEY(role_id) REFERENCES role (id)
);
CREATE TABLE group_role_association (
	id INTEGER NOT NULL, 
	group_id INTEGER, 
	role_id INTEGER, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(group_id) REFERENCES galaxy_group (id), 
	 FOREIGN KEY(role_id) REFERENCES role (id)
);
CREATE TABLE library_folder_permissions (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	action TEXT, 
	library_folder_id INTEGER, 
	role_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(library_folder_id) REFERENCES library_folder (id), 
	 FOREIGN KEY(role_id) REFERENCES role (id)
);
CREATE TABLE default_history_permissions (
	id INTEGER NOT NULL, 
	history_id INTEGER, 
	action TEXT, 
	role_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(history_id) REFERENCES history (id), 
	 FOREIGN KEY(role_id) REFERENCES role (id)
);
CREATE TABLE library_dataset_dataset_association_permissions (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	action TEXT, 
	library_dataset_dataset_association_id INTEGER, 
	role_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(library_dataset_dataset_association_id) REFERENCES library_dataset_dataset_association (id), 
	 FOREIGN KEY(role_id) REFERENCES role (id)
);
CREATE TABLE history_user_share_association (
	id INTEGER NOT NULL, 
	history_id INTEGER, 
	user_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(history_id) REFERENCES history (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id)
);
CREATE TABLE form_definition_current (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	latest_form_id INTEGER, 
	deleted BOOLEAN, 
	PRIMARY KEY (id)
);
CREATE TABLE form_definition (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	name VARCHAR(255) NOT NULL, 
	`desc` TEXT, 
	form_definition_current_id INTEGER NOT NULL, 
	fields BLOB, type VARCHAR(255), layout BLOB, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(form_definition_current_id) REFERENCES form_definition_current (id)
);
CREATE TABLE form_values (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	form_definition_id INTEGER, 
	content BLOB, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(form_definition_id) REFERENCES form_definition (id)
);
CREATE TABLE request_type (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	name VARCHAR(255) NOT NULL, 
	`desc` TEXT, 
	request_form_id INTEGER, 
	sample_form_id INTEGER, deleted BOOLEAN, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(request_form_id) REFERENCES form_definition (id), 
	 FOREIGN KEY(sample_form_id) REFERENCES form_definition (id)
);
CREATE TABLE sample (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	name VARCHAR(255) NOT NULL, 
	`desc` TEXT, 
	form_values_id INTEGER, 
	request_id INTEGER, 
	deleted BOOLEAN, bar_code VARCHAR(255), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(form_values_id) REFERENCES form_values (id), 
	 FOREIGN KEY(request_id) REFERENCES request (id)
);
CREATE TABLE sample_state (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	name VARCHAR(255) NOT NULL, 
	`desc` TEXT, 
	request_type_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(request_type_id) REFERENCES request_type (id)
);
CREATE TABLE sample_event (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	sample_id INTEGER, 
	sample_state_id INTEGER, 
	comment TEXT, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(sample_id) REFERENCES sample (id), 
	 FOREIGN KEY(sample_state_id) REFERENCES sample_state (id)
);
CREATE TABLE history_dataset_association_display_at_authorization (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	history_dataset_association_id INTEGER, 
	user_id INTEGER, 
	site VARCHAR(255), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(history_dataset_association_id) REFERENCES history_dataset_association (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id)
);
CREATE TABLE user_address (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	user_id INTEGER, 
	`desc` TEXT, 
	name VARCHAR(255) NOT NULL, 
	institution VARCHAR(255), 
	address VARCHAR(255) NOT NULL, 
	city VARCHAR(255) NOT NULL, 
	state VARCHAR(255) NOT NULL, 
	postal_code VARCHAR(255) NOT NULL, 
	country VARCHAR(255) NOT NULL, 
	phone VARCHAR(255), 
	deleted BOOLEAN, 
	purged BOOLEAN, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id)
);
CREATE TABLE library_info_association (
	id INTEGER NOT NULL, 
	library_id INTEGER, 
	form_definition_id INTEGER, 
	form_values_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(library_id) REFERENCES library (id), 
	 FOREIGN KEY(form_values_id) REFERENCES form_values (id), 
	 FOREIGN KEY(form_definition_id) REFERENCES form_definition (id)
);
CREATE TABLE library_folder_info_association (
	id INTEGER NOT NULL, 
	library_folder_id INTEGER, 
	form_definition_id INTEGER, 
	form_values_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(library_folder_id) REFERENCES library_folder (id), 
	 FOREIGN KEY(form_values_id) REFERENCES form_values (id), 
	 FOREIGN KEY(form_definition_id) REFERENCES form_definition (id)
);
CREATE TABLE library_dataset_dataset_info_association (
	id INTEGER NOT NULL, 
	library_dataset_dataset_association_id INTEGER, 
	form_definition_id INTEGER, 
	form_values_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(library_dataset_dataset_association_id) REFERENCES library_dataset_dataset_association (id), 
	 FOREIGN KEY(form_values_id) REFERENCES form_values (id), 
	 FOREIGN KEY(form_definition_id) REFERENCES form_definition (id)
);
CREATE TABLE page (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	user_id INTEGER NOT NULL, 
	latest_revision_id INTEGER, 
	title TEXT, 
	slug TEXT, published BOOLEAN, deleted BOOLEAN, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 CONSTRAINT page_latest_revision_id_fk FOREIGN KEY(latest_revision_id) REFERENCES page_revision (id)
);
CREATE TABLE page_revision (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	page_id INTEGER NOT NULL, 
	title TEXT, 
	content TEXT, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(page_id) REFERENCES page (id)
);
CREATE TABLE tag (
	id INTEGER NOT NULL, 
	type INTEGER, 
	parent_id INTEGER, 
	name VARCHAR(255), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(parent_id) REFERENCES tag (id), 
	 UNIQUE (name)
);
CREATE TABLE history_tag_association (
	id INTEGER NOT NULL, 
	history_id INTEGER, 
	tag_id INTEGER, 
	user_tname VARCHAR(255), 
	value VARCHAR(255), 
	user_value VARCHAR(255), user_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(history_id) REFERENCES history (id), 
	 FOREIGN KEY(tag_id) REFERENCES tag (id)
);
CREATE TABLE dataset_tag_association (
	id INTEGER NOT NULL, 
	dataset_id INTEGER, 
	tag_id INTEGER, 
	user_tname VARCHAR(255), 
	value VARCHAR(255), 
	user_value VARCHAR(255), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(dataset_id) REFERENCES dataset (id), 
	 FOREIGN KEY(tag_id) REFERENCES tag (id)
);
CREATE TABLE history_dataset_association_tag_association (
	id INTEGER NOT NULL, 
	history_dataset_association_id INTEGER, 
	tag_id INTEGER, 
	user_tname VARCHAR(255), 
	value VARCHAR(255), 
	user_value VARCHAR(255), user_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(history_dataset_association_id) REFERENCES history_dataset_association (id), 
	 FOREIGN KEY(tag_id) REFERENCES tag (id)
);
CREATE TABLE page_tag_association (
	id INTEGER NOT NULL, 
	page_id INTEGER, 
	tag_id INTEGER, 
	user_tname VARCHAR(255), 
	value VARCHAR(255), 
	user_value VARCHAR(255), user_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(page_id) REFERENCES page (id), 
	 FOREIGN KEY(tag_id) REFERENCES tag (id)
);
CREATE TABLE job_to_output_library_dataset (
	id INTEGER NOT NULL, 
	job_id INTEGER, 
	ldda_id INTEGER, 
	name VARCHAR(255), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(job_id) REFERENCES job (id), 
	 FOREIGN KEY(ldda_id) REFERENCES library_dataset_dataset_association (id)
);
CREATE TABLE user_preference (
	id INTEGER NOT NULL, 
	user_id INTEGER, 
	name VARCHAR(255), 
	value VARCHAR(1024), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id)
);
CREATE TABLE visualization (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	user_id INTEGER NOT NULL, 
	latest_revision_id INTEGER, 
	title TEXT, 
	type TEXT, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 CONSTRAINT visualization_latest_revision_id_fk FOREIGN KEY(latest_revision_id) REFERENCES visualization_revision (id)
);
CREATE TABLE visualization_revision (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	visualization_id INTEGER NOT NULL, 
	title TEXT, 
	config TEXT, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(visualization_id) REFERENCES visualization (id)
);
CREATE TABLE cloud_provider (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	user_id INTEGER NOT NULL, 
	type TEXT NOT NULL, 
	name TEXT, 
	region_connection TEXT, 
	region_name TEXT, 
	region_endpoint TEXT, 
	is_secure BOOLEAN, 
	host TEXT, 
	port INTEGER, 
	proxy TEXT, 
	proxy_port TEXT, 
	proxy_user TEXT, 
	proxy_pass TEXT, 
	debug INTEGER, 
	https_connection_factory TEXT, 
	path TEXT, 
	deleted BOOLEAN, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id)
);
CREATE TABLE cloud_user_credentials (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	user_id INTEGER NOT NULL, 
	provider_id INTEGER NOT NULL, 
	name TEXT, 
	access_key TEXT, 
	secret_key TEXT, 
	deleted BOOLEAN, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 FOREIGN KEY(provider_id) REFERENCES cloud_provider (id)
);
CREATE TABLE cloud_image (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	provider_type TEXT, 
	image_id TEXT NOT NULL, 
	manifest TEXT, 
	state TEXT, 
	architecture TEXT, 
	deleted BOOLEAN, 
	PRIMARY KEY (id)
);
CREATE TABLE cloud_uci (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	user_id INTEGER NOT NULL, 
	credentials_id INTEGER, 
	key_pair_name TEXT, 
	key_pair_material TEXT, 
	name TEXT, 
	state TEXT, 
	error TEXT, 
	total_size INTEGER, 
	launch_time TIMESTAMP, 
	deleted BOOLEAN, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 FOREIGN KEY(credentials_id) REFERENCES cloud_user_credentials (id)
);
CREATE TABLE cloud_instance (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	launch_time TIMESTAMP, 
	stop_time TIMESTAMP, 
	user_id INTEGER NOT NULL, 
	uci_id INTEGER, 
	type TEXT, 
	reservation_id TEXT, 
	instance_id TEXT, 
	mi_id INTEGER, 
	state TEXT, 
	error TEXT, 
	public_dns TEXT, 
	private_dns TEXT, 
	security_group TEXT, 
	availability_zone TEXT, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 FOREIGN KEY(mi_id) REFERENCES cloud_image (id), 
	 FOREIGN KEY(uci_id) REFERENCES cloud_uci (id)
);
CREATE TABLE cloud_store (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	attach_time TIMESTAMP, 
	user_id INTEGER NOT NULL, 
	uci_id INTEGER NOT NULL, 
	volume_id TEXT, 
	size INTEGER NOT NULL, 
	availability_zone TEXT, 
	inst_id INTEGER, 
	status TEXT, 
	device TEXT, 
	space_consumed INTEGER, 
	error TEXT, 
	deleted BOOLEAN, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 FOREIGN KEY(uci_id) REFERENCES cloud_uci (id), 
	 FOREIGN KEY(inst_id) REFERENCES cloud_instance (id)
);
CREATE TABLE cloud_snapshot (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	user_id INTEGER NOT NULL, 
	uci_id INTEGER, 
	store_id INTEGER NOT NULL, 
	snapshot_id TEXT, 
	status TEXT, 
	description TEXT, 
	error TEXT, 
	deleted BOOLEAN, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 FOREIGN KEY(store_id) REFERENCES cloud_store (id), 
	 FOREIGN KEY(uci_id) REFERENCES cloud_uci (id)
);
CREATE TABLE request_event (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	request_id INTEGER, 
	state VARCHAR(255), 
	comment TEXT, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(request_id) REFERENCES request (id)
);
CREATE TABLE request (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	update_time TIMESTAMP, 
	name VARCHAR(255) NOT NULL, 
	`desc` TEXT, 
	form_values_id INTEGER, 
	request_type_id INTEGER, 
	user_id INTEGER, 
	library_id INTEGER, 
	deleted BOOLEAN, 
	folder_id INTEGER, 
	PRIMARY KEY (id), 
	 FOREIGN KEY(library_id) REFERENCES library (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 FOREIGN KEY(form_values_id) REFERENCES form_values (id), 
	 FOREIGN KEY(request_type_id) REFERENCES request_type (id)
);
CREATE TABLE user_action (
	id INTEGER NOT NULL, 
	create_time TIMESTAMP, 
	user_id INTEGER, 
	session_id INTEGER, 
	action VARCHAR(255), 
	context VARCHAR(512), 
	params VARCHAR(1024), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 FOREIGN KEY(session_id) REFERENCES galaxy_session (id)
);
CREATE TABLE stored_workflow_tag_association (
	id INTEGER NOT NULL, 
	stored_workflow_id INTEGER, 
	tag_id INTEGER, 
	user_id INTEGER, 
	user_tname VARCHAR(255), 
	value VARCHAR(255), 
	user_value VARCHAR(255), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(stored_workflow_id) REFERENCES stored_workflow (id), 
	 FOREIGN KEY(tag_id) REFERENCES tag (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id)
);
CREATE TABLE workflow_tag_association (
	id INTEGER NOT NULL, 
	workflow_id INTEGER, 
	tag_id INTEGER, 
	user_id INTEGER, 
	user_tname VARCHAR(255), 
	value VARCHAR(255), 
	user_value VARCHAR(255), 
	PRIMARY KEY (id), 
	 FOREIGN KEY(workflow_id) REFERENCES workflow (id), 
	 FOREIGN KEY(user_id) REFERENCES galaxy_user (id), 
	 FOREIGN KEY(tag_id) REFERENCES tag (id)
);


INSERT INTO migrate_version VALUES('Galaxy','lib/galaxy/model/migrate',31);

