CREATE TABLE contacts(
	account_id TEXT NOT NULL,
	alias TEXT,
	color TEXT,
	contact_id TEXT NOT NULL,
	display_name TEXT,
	email TEXT,
	external INTEGER DEFAULT 0,
	favorite INTEGER DEFAULT 0,
	note TEXT,
	permission INTEGER DEFAULT 0,
	phone_number TEXT,
	sid TEXT,
	time_zone TEXT,

	PRIMARY KEY(account_id, contact_id)
) STRICT;

CREATE TABLE contact_tags(
	account_id TEXT NOT NULL,
	contact_id TEXT NOT NULL,
	tag TEXT NOT NULL,

	PRIMARY KEY (account_id, contact_id, tag)
) STRICT;

CREATE TABLE contact_badges(
	account_id TEXT NOT NULL,
	contact_id TEXT NOT NULL,
	badge_id TEXT NOT NULL,

	PRIMARY KEY (account_id, contact_id, badge_id)
) STRICT;

CREATE TABLE person(
	alias TEXT,
	color TEXT,
	person_id TEXT NOT NULL PRIMARY KEY,
	priority_contact_account_id TEXT,
	priority_contact_contact_id TEXT
) STRICT;

CREATE TABLE person_tags(
	person_id TEXT NOT NULL,
	tag TEXT NOT NULL,

	PRIMARY KEY(person_id, tag)
) STRICT;

CREATE TABLE person_contacts(
	person_id TEXT NOT NULL,
	contact_account_id TEXT NOT NULL,
	contact_contact_id TEXT NOT NULL,

	PRIMARY KEY(person_id, contact_account_id, contact_contact_id)
) STRICT;
