CREATE TABLE conversations(
	account_id TEXT NOT NULL,
	age_restricted INTEGER(1) DEFAULT 0,
	alias TEXT,
	conversation_id TEXT NOT NULL,
	created_on TEXT,
	creator_id TEXT,
	description TEXT,
	drafting INTEGER(1) DEFAULT 0,
	error_domain TEXT,
	error_code INTEGER,
	error_message TEXT,
	favorite INTEGER(1) DEFAULT 0,
	federated INTEGER(1) DEFAULT 0,
	logging INTEGER(1) DEFAULT 0,
	needs_attention INTEGER(1) 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)
);

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)
);

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)
);

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)
);

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)
);
