/* Table contains data fields, a primary key constraint and a foreign key constraints       */
/* The constraints are designed to limit damage to data integrity in the event of           */ 
/* programmer error or other unforeseen circumstances.                                      */

/* Log book pages are a type of object hence the foreign key reference to objects and        */
/* should only occur with reference to specific log books and specific users hence foreign   */
/* key reference to those tables.                                                            */

CREATE TABLE log_book_entries (
	log_book_entry_id int NOT NULL ,
	log_book_page_id int NOT NULL ,
	log_book_question_id int NOT NULL ,
	user_id int NOT NULL ,
	entry_big_string_id int NOT NULL ,
	flags int NOT NULL,
	when_modified TIMESTAMP NOT NULL ,
	CONSTRAINT PK_log_book_entries PRIMARY KEY
	(
		log_book_entry_id
	),
	CONSTRAINT FK_log_book_ent_to_objects FOREIGN KEY
	(
		log_book_entry_id
	) REFERENCES objects (
		id
	),
	CONSTRAINT FK_log_book_ent_to_pag FOREIGN KEY
	(
		log_book_page_id
	) REFERENCES log_book_pages (
		log_book_page_id
	),
	CONSTRAINT FK_log_book_ent_to_qs FOREIGN KEY
	(
		log_book_question_id
	) REFERENCES log_book_questions (
		log_book_question_id
	),
	CONSTRAINT FK_log_book_ent_to_usrs FOREIGN KEY
	(
		user_id
	) REFERENCES users (
		user_id
	),
	CONSTRAINT FK_log_book_ent_to_bstrgs FOREIGN KEY
	(
		entry_big_string_id
	) REFERENCES big_strings (
		big_string_id
	)
)
GO

/* The rest of this SQL is deployment information as described in LogBook.sql */


INSERT INTO classes (type, super_type, db_name, table_name, java_class)
	VALUES(53, null, null, 'log_book_entries', 'org.bodington.logbook.server.LogBookEntry')
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(53, 1, 'log_book_entry_id', 'setLogBookEntryId', 'getLogBookEntryId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 1, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(53, 2, 'log_book_page_id', 'setLogBookPageId', 'getLogBookPageId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(53, 3, 'log_book_question_id', 'setLogBookQuestionId', 'getLogBookQuestionId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(53, 4, 'user_id', 'setUserId', 'getUserId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(53, 5, 'entry_big_string_id', 'setEntryBigStringId', 'getEntryBigStringId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(53, 6, 'flags', 'setFlags', 'getFlags', 'int', 'int', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(53, 7, 'when_modified', 'setWhenModified', 'getWhenModified', 'java.sql.Timestamp', 'java.sql.Timestamp', 0, null, null, null )
GO



