CREATE TABLE messages (
    message_id int NOT NULL ,
	messaging_room_id int NOT NULL ,
	group_id int,
	parent_message_id int,
	replyto_message_id int,
	left_index int NOT NULL ,
	right_index int NOT NULL ,
	created_time TIMESTAMP NOT NULL ,
	updated_time TIMESTAMP NOT NULL ,
	user_id int NOT NULL ,
	author_name VARCHAR(64) NOT NULL ,
	flags int NOT NULL ,
	subject VARCHAR(255) NOT NULL ,
	style int NOT NULL ,
	big_string_id int NOT NULL ,
	/* Required for modifying posts in discussion / communication rooms. */
	editor_name  VARCHAR(64) NULL,
	edited_time  TIMESTAMP NULL,

	CONSTRAINT PK_messages PRIMARY KEY
	(
		message_id
	),
	CONSTRAINT FK_messages_to_messaging_rooms FOREIGN KEY
	(
		messaging_room_id
	) REFERENCES messaging_rooms (
		messaging_room_id
	),
	CONSTRAINT FK_messages_to_users FOREIGN KEY
	(
		user_id
	) REFERENCES users (
		user_id
	),
	CONSTRAINT FK_messages_to_big_strings FOREIGN KEY
	(
		big_string_id
	) REFERENCES big_strings (
		big_string_id
	)	
	)
GO

INSERT INTO classes (type, super_type, db_name, table_name, java_class)
	VALUES(26, NULL, 'building2', 'messages', 'org.bodington.messaging.Message')
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(26, 1, 'message_id', 'setMessageId', 'getMessageId', '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(26, 2, 'messaging_room_id', 'setMessagingRoomId', 'getMessagingRoomId', '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(26, 3, 'group_id', 'setGroupId', 'getGroupId', '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(26, 4, 'parent_message_id', 'setParentMessageId', 'getParentMessageId', '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(26, 5, 'replyto_message_id', 'setReplyToMessageId', 'getReplyToMessageId', '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(26, 6, 'left_index', 'setLeftIndex', 'getLeftIndex', '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(26, 7, 'right_index', 'setRightIndex', 'getRightIndex', '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(26, 8, 'created_time', 'setCreatedTime', 'getCreatedTime', 'java.sql.Timestamp', 'java.sql.Timestamp', 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(26, 9, 'updated_time', 'setUpdatedTime', 'getUpdatedTime', 'java.sql.Timestamp', 'java.sql.Timestamp', 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(26, 10, '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(26, 11, 'author_name', 'setAuthorName', 'getAuthorName', 'java.lang.String', 'java.lang.String', 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(26, 12, '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(26, 13, 'subject', 'setSubject', 'getSubject', 'java.lang.String', 'java.lang.String', 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(26, 14, 'style', 'setStyle', 'getStyle', '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(26, 15, 'big_string_id', 'setBigStringId', 'getBigStringId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

