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

/* Log book sections are a type of object hence the foreign key reference to objects and    */
/* should only occur with reference to specific log books hence foreign key reference to    */
/* that table.  There are also two references to the big_strings table                      */

CREATE TABLE log_book_sections (
	log_book_section_id int NOT NULL ,
	log_book_id int NOT NULL ,
	title_big_string_id int NOT NULL ,
	introduction_big_string_id int NOT NULL ,
	ordinal int NOT NULL,
	CONSTRAINT PK_log_book_sections PRIMARY KEY
	(
		log_book_section_id
	),
	CONSTRAINT FK_log_book_secs_to_objs FOREIGN KEY
	(
		log_book_section_id
	) REFERENCES objects (
		id
	),
	CONSTRAINT FK_log_book_secs_to_lbs FOREIGN KEY
	(
		log_book_id
	) REFERENCES log_books (
		log_book_id
	),
	CONSTRAINT FK_log_book_s_t_to_bgstrs FOREIGN KEY
	(
		title_big_string_id
	) REFERENCES big_strings (
		big_string_id
	),
	CONSTRAINT FK_log_book_s_i_to_bgstrs FOREIGN KEY
	(
		title_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(50, null, null, 'log_book_sections', 'org.bodington.logbook.server.LogBookSection')
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(50, 1, 'log_book_section_id', 'setLogBookSectionId', 'getLogBookSectionId', '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(50, 2, 'log_book_id', 'setLogBookId', 'getLogBookId', '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(50, 3, 'title_big_string_id', 'setTitleBigStringId', 'getTitleBigStringId', '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(50, 4, 'introduction_big_string_id', 'setIntroductionBigStringId', 'getIntroductionBigStringId', '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(50, 5, 'ordinal', 'setOrdinal', 'getOrdinal', 'int', 'int', 0, null, null, null )
GO




