/* The 'Drop Primary Key Support' option is unavailable. */;

DROP TABLE wiwo_name_space CASCADE;

DROP TABLE wiwo_name_space_2_wiwo_user CASCADE;

DROP TABLE wiwo_name_space_definition CASCADE;

DROP TABLE wiwo_name_space_definition_2_wiwo_page CASCADE;

DROP TABLE wiwo_page CASCADE;

DROP TABLE wiwo_user CASCADE;

CREATE SEQUENCE wiwo_name_space_seq_id;
CREATE TABLE wiwo_name_space (DESCRIPTION varchar NOT NULL, ID int4 NOT NULL, NAME varchar NOT NULL);

CREATE SEQUENCE wiwo_name_space_2_wiwo_user_seq_id;
CREATE TABLE wiwo_name_space_2_wiwo_user (wiwo_name_space_id int4 NOT NULL, wiwo_user_id int4 NOT NULL);

CREATE SEQUENCE wiwo_name_space_definition_seq_id;
CREATE TABLE wiwo_name_space_definition (DESCRIPTION varchar NOT NULL, ID int4 NOT NULL, NAME varchar NOT NULL);

CREATE SEQUENCE wiwo_name_space_definition_2_wiwo_page_seq_id;
CREATE TABLE wiwo_name_space_definition_2_wiwo_page (name_space_definition_id int4 NOT NULL, user_page_id int4 NOT NULL);

CREATE SEQUENCE wiwo_page_seq_id;
CREATE TABLE wiwo_page (LAST_LOGIN date, ID int4 NOT NULL, NAME varchar(50) NOT NULL, PREVIOUS_VERSION_ID int4, USER_ID int4 NOT NULL, VERSION_DATE date NOT NULL, VERSION_TAG int4 NOT NULL, WIKI_MARKUP varchar NOT NULL);

CREATE SEQUENCE wiwo_user_seq_id;
CREATE TABLE wiwo_user (ID int4 NOT NULL, LOGIN varchar NOT NULL, PASSWORD varchar NOT NULL, USER_ROLE varchar NOT NULL);

/* The 'Create Primary Key Support' option is unavailable. */;

ALTER TABLE wiwo_name_space ADD PRIMARY KEY (ID);

ALTER TABLE wiwo_name_space_2_wiwo_user ADD PRIMARY KEY (wiwo_name_space_id, wiwo_user_id);

ALTER TABLE wiwo_name_space_definition ADD PRIMARY KEY (ID);

ALTER TABLE wiwo_name_space_definition_2_wiwo_page ADD PRIMARY KEY (name_space_definition_id, user_page_id);

ALTER TABLE wiwo_page ADD PRIMARY KEY (ID);

ALTER TABLE wiwo_user ADD PRIMARY KEY (ID);

ALTER TABLE wiwo_name_space_2_wiwo_user ADD CONSTRAINT wiwo_name_space_2_wiwo_user_wiwoUser_FK FOREIGN KEY (wiwo_user_id) REFERENCES wiwo_user (ID) INITIALLY DEFERRED;

ALTER TABLE wiwo_name_space_2_wiwo_user ADD CONSTRAINT wiwo_name_space_2_wiwo_user_wiwoNameSpace_FK FOREIGN KEY (wiwo_name_space_id) REFERENCES wiwo_name_space (ID) INITIALLY DEFERRED;

ALTER TABLE wiwo_name_space_definition_2_wiwo_page ADD CONSTRAINT wiwo_name_space_definition_2_wiwo_page_wiwoPage_FK FOREIGN KEY (user_page_id) REFERENCES wiwo_page (ID) INITIALLY DEFERRED;

ALTER TABLE wiwo_name_space_definition_2_wiwo_page ADD CONSTRAINT wiwo_name_space_definition_2_wiwo_page_nameSpaceDefinition_FK FOREIGN KEY (name_space_definition_id) REFERENCES wiwo_name_space_definition (ID) INITIALLY DEFERRED;

ALTER TABLE wiwo_page ADD CONSTRAINT wiwo_page_user_FK FOREIGN KEY (USER_ID) REFERENCES wiwo_user (ID) INITIALLY DEFERRED;

ALTER TABLE wiwo_page ADD CONSTRAINT wiwo_page_previousVersion_FK FOREIGN KEY (PREVIOUS_VERSION_ID) REFERENCES wiwo_page (ID) INITIALLY DEFERRED;

insert into wiwo_user values (nextval('wiwo_user_seq_id'), 'wiwo', 'wiwo', 'MASTER');