-- Make the conversations table strict.
ALTER TABLE conversations RENAME TO conversations_old;
CREATE TABLE conversations(
	account_id TEXT NOT NULL,
	age_restricted INTEGER DEFAULT 0,
	alias TEXT,
	conversation_id TEXT NOT NULL,
	created_on TEXT,
	creator_id TEXT,
	description TEXT,
	drafting INTEGER DEFAULT 0,
	error_domain TEXT,
	error_code INTEGER,
	error_message TEXT,
	favorite INTEGER DEFAULT 0,
	federated INTEGER DEFAULT 0,
	logging INTEGER DEFAULT 0,
	needs_attention INTEGER DEFAULT 0,
	title TEXT,
	topic TEXT,
	topic_author_id TEXT,
	topic_updated TEXT,
	type INTEGER,
	url TEXT,
	user_nickname TEXT,

	PRIMARY KEY(account_id, conversation_id)
) STRICT;
INSERT INTO conversations SELECT * FROM conversations_old;
DROP TABLE conversations_old;

-- Make the conversation_tags table strict.
ALTER TABLE conversation_tags RENAME TO conversation_tags_old;
CREATE TABLE conversation_tags(
	account_id TEXT NOT NULL,
	conversation_id TEXT NOT NULL,
	tag TEXT NOT NULL,

	PRIMARY KEY(account_id, conversation_id, tag)
) STRICT;
INSERT INTO conversation_tags SELECT * FROM conversation_tags_old;
DROP TABLE conversation_tags_old;

-- Make the conversation_members table strict.
ALTER TABLE conversation_members RENAME TO conversation_members_old;
CREATE TABLE conversation_members(
	account_id TEXT NOT NULL,
	contact_id TEXT NOT NULL,
	conversation_id TEXT NOT NULL,
	nickname TEXT,

	PRIMARY KEY(account_id, conversation_id, contact_id)
) STRICT;
INSERT INTO conversation_members SELECT * FROM conversation_members_old;
DROP TABLE conversation_members_old;

-- Make the conversation_member_tags table strict.
ALTER TABLE conversation_member_tags RENAME TO conversation_member_tags_old;
CREATE TABLE conversation_member_tags(
	account_id TEXT NOT NULL,
	contact_id TEXT NOT NULL,
	conversation_id TEXT NOT NULL,
	tag TEXT NOT NULL,

	PRIMARY KEY(account_id, conversation_id, contact_id, tag)
) STRICT;
INSERT INTO conversation_member_tags SELECT * FROM conversation_member_tags_old;
DROP TABLE conversation_member_tags_old;

-- Make the conversation member badges table strict.
ALTER TABLE conversation_member_badges RENAME TO conversation_member_badges_old;
CREATE TABLE conversation_member_badges(
	account_id TEXT NOT NULL,
	contact_id TEXT NOT NULL,
	conversation_id TEXT NOT NULL,
	badge_id TEXT NOT NULL,

	PRIMARY KEY(account_id, conversation_id, contact_id, badge_id)
) STRICT;
INSERT INTO conversation_member_badges SELECT * FROM conversation_member_badges_old;
DROP TABLE conversation_member_badges_old;
