BEGIN TRANSACTION;
CREATE TABLE t_meta (meta_app VARCHAR(20),meta_type VARCHAR(20),meta_version VARCHAR(20),meta_dbversion SMALLINT,meta_create_date DATETIME,meta_modify_date DATETIME);
INSERT INTO "t_meta" VALUES('<package>', 'risx', '<version>', 2, 'CURRENT_TIMESTAMP', 'CURRENT_TIMESTAMP');
CREATE TABLE t_refdb (refdb_id INTEGER PRIMARY KEY,refdb_citekey TEXT UNIQUE,refdb_type TEXT,refdb_pubyear SMALLINT,refdb_secyear SMALLINT,refdb_startpage TEXT,refdb_endpage TEXT,refdb_abstract TEXT,refdb_title TEXT,refdb_volume TEXT,refdb_issue TEXT,refdb_booktitle TEXT,refdb_city TEXT,refdb_publisher TEXT,refdb_title_series TEXT,refdb_address TEXT,refdb_issn TEXT,refdb_pyother_info TEXT,refdb_secother_info TEXT,refdb_periodical_id BIGINT,refdb_user1 TEXT,refdb_user2 TEXT,refdb_user3 TEXT,refdb_user4 TEXT,refdb_user5 TEXT,refdb_misc1 TEXT,refdb_misc2 TEXT,refdb_misc3 TEXT);
CREATE TABLE t_author (author_id INTEGER PRIMARY KEY,author_name TEXT NOT NULL,author_lastname TEXT,author_firstname TEXT,author_middlename TEXT,author_suffix TEXT);
CREATE TABLE t_keyword (keyword_id INTEGER PRIMARY KEY,keyword_name TEXT NOT NULL);
CREATE TABLE t_periodical (periodical_id INTEGER PRIMARY KEY,periodical_name TEXT,periodical_abbrev TEXT,periodical_custabbrev1 TEXT,periodical_custabbrev2 TEXT);
CREATE TABLE t_note (note_id INTEGER PRIMARY KEY,note_key TEXT UNIQUE,note_title TEXT,note_content_type TEXT,note_content_xmllang TEXT,note_user_id BIGINT,note_date DATE,note_share SMALLINT,note_content TEXT);
CREATE TABLE t_user (user_id INTEGER PRIMARY KEY,user_name TEXT NOT NULL);
CREATE TABLE t_link (link_id INTEGER PRIMARY KEY,link_url TEXT NOT NULL);
CREATE TABLE t_xauthor (xauthor_id INTEGER PRIMARY KEY,author_id BIGINT NOT NULL,refdb_id BIGINT NOT NULL,xauthor_type SMALLINT DEFAULT 1,xauthor_role TEXT,xauthor_position INTEGER);
CREATE TABLE t_xkeyword (xkeyword_id INTEGER PRIMARY KEY,xkeyword_type TEXT,keyword_id BIGINT NOT NULL,xref_id BIGINT NOT NULL);
CREATE TABLE t_xuser (xuser_id INTEGER PRIMARY KEY,user_id BIGINT NOT NULL,refdb_id BIGINT NOT NULL,xuser_reprint TEXT DEFAULT 'NOT IN FILE',xuser_date DATE,xuser_avail TEXT,xuser_notes TEXT);
CREATE TABLE t_xnote (xnote_id INTEGER PRIMARY KEY,note_id BIGINT NOT NULL,xref_id BIGINT NOT NULL,xnote_type TEXT DEFAULT 'REFERENCE');
CREATE TABLE t_xlink (xlink_id INTEGER PRIMARY KEY,link_id BIGINT NOT NULL,xref_id BIGINT NOT NULL,xlink_type TEXT DEFAULT 'URL',xlink_source TEXT DEFAULT 'REFERENCE');
CREATE INDEX i_refdb_pubyear ON t_refdb (refdb_pubyear);
CREATE UNIQUE INDEX i_refdb_citekey ON t_refdb (refdb_citekey);
CREATE INDEX i_author_name ON t_author (author_name);
CREATE INDEX i_keyword_name ON t_keyword (keyword_name);
CREATE INDEX i_periodical_name ON t_periodical (periodical_name);
CREATE INDEX i_periodical_abbrev ON t_periodical (periodical_abbrev);
CREATE INDEX i_periodical_custabbrev1 ON t_periodical (periodical_custabbrev1);
CREATE INDEX i_periodical_custabbrev2 ON t_periodical (periodical_custabbrev2);
CREATE INDEX i_note_title ON t_note (note_title);
CREATE INDEX i_note_note_userid ON t_note (note_user_id);
CREATE INDEX i_note_date ON t_note (note_date);
CREATE INDEX i_user_name ON t_user (user_name);
CREATE INDEX i_link_url ON t_link (link_url);
CREATE INDEX i_xauthor_autid ON t_xauthor (author_id);
CREATE INDEX i_xauthor_refid ON t_xauthor (refdb_id);
CREATE INDEX i_xkeyword_kwid ON t_xkeyword (keyword_id);
CREATE INDEX i_xkeyword_xrefid ON t_xkeyword (xref_id);
CREATE INDEX i_xuser_userid ON t_xuser (user_id);
CREATE INDEX i_xuser_refid ON t_xuser (refdb_id);
CREATE INDEX i_xnote_noteid ON t_xnote (note_id);
CREATE INDEX i_xnote_xrefid ON t_xnote (xref_id);
CREATE INDEX i_xnote_xnotetype ON t_xnote (xnote_type);
CREATE INDEX i_xlink_linkid ON t_xlink (link_id);
CREATE INDEX i_xlink_xrefid ON t_xlink (xref_id);
CREATE INDEX i_xlink_xlinktype ON t_xlink (xlink_type);
CREATE INDEX i_xlink_xlinksource ON t_xlink (xlink_source);
COMMIT;
