aural_isle/SCHEMA.md

2.2 KiB

SCHEMA

This file represents the initial schema for the various data structures to be stored in the database.

These schema definitions target SQLite v3.

Persons Table

The Persons table will contain data about Person entities (see MODELS.md)

CREATE TABLE Persons (
	id TEXT(36),    /* UUIDv4 */
	remote_id TEXT, /* field to store an arbitrary remote identifier for this Person if they are not local */
	name TEXT,      /* "real" name */
	handle TEXT,    /* also commonly refered to as 'display_name' or 'screen_name', optional (if missing, name will be used as handle) */
	is_active INTEGER DEFAULT (1),    /* bool, default true */
	is_blocked INTEGER DEFAULT (0),   /* bool, default false */
	created_at INTEGER,               /* timestamp */
	modified_at INTEGER,              /* timestamp */
	modified_by TEXT(36),             /* UUIDv4 */
	deleted_at INTEGER,               /* timestamp */
	deleted_by TEXT(36),              /* UUIDv4 */
	last_seen INTEGER,                /* timestamp */
	shipping_address TEXT,            /* optional, should use \n between lines to keep localized format as needed */
	CONSTRAINT Persons_PK PRIMARY KEY (id),
	CONSTRAINT Persons_FK FOREIGN KEY (modified_by) REFERENCES Persons(id),
	CONSTRAINT Persons_FK_1 FOREIGN KEY (deleted_by) REFERENCES Persons(id)
);
CREATE UNIQUE INDEX Persons_remote_id_IDX ON Persons (remote_id);
CREATE INDEX Persons_name_IDX ON Persons (name);
CREATE INDEX Persons_handle_IDX ON Persons (handle);
CREATE INDEX Persons_is_active_IDX ON Persons (is_active);
CREATE INDEX Persons_is_blocked_IDX ON Persons (is_blocked);
CREATE INDEX Persons_deleted_at_IDX ON Persons (deleted_at);

PersonEmails Table

The PersonEmails table is a one-to-many lookup table relating a Person to zero or more email addresses

CREATE TABLE PersonEmails (
	person_id TEXT(36),
	email TEXT,
	is_verified INTEGER DEFAULT (0),
	is_primary INTEGER DEFAULT (0),
	CONSTRAINT PersonEmails_PK PRIMARY KEY (email),
	CONSTRAINT PersonEmails_FK FOREIGN KEY (person_id) REFERENCES Persons(id) ON DELETE CASCADE
);
CREATE INDEX PersonEmails_person_id_IDX ON PersonEmails (person_id);
CREATE INDEX PersonEmails_is_verified_IDX ON PersonEmails (is_verified);
CREATE INDEX PersonEmails_is_primary_IDX ON PersonEmails (is_primary);