CREATE TABLE "channels" (
	"id"	TEXT NOT NULL,
	"name"	TEXT NOT NULL,
	"locales"	TEXT NOT NULL,
	PRIMARY KEY("id")
)

CREATE TABLE "edges" (
	"id"	TEXT,
	"from"	TEXT NOT NULL,
	"to"	TEXT NOT NULL,
	"field_id"	TEXT NOT NULL,
	"rank"	INTEGER NOT NULL,
	"locale"	TEXT NOT NULL,
	"mode"	TEXT NOT NULL,
	""	INTEGER,
	UNIQUE("from","to","field_id","locale","mode"),
	PRIMARY KEY("id")
)

CREATE TABLE "fields" (
	"id"	TEXT NOT NULL,
	"name"	TEXT NOT NULL,
	"type"	TEXT NOT NULL,
	"props"	TEXT NOT NULL,
	"schema_id"	TEXT NOT NULL,
	"alias"	TEXT NOT NULL,
	"rank"	INTEGER NOT NULL DEFAULT 0,
	"translatable"	INTEGER NOT NULL DEFAULT 0,
	"help"	TEXT NOT NULL DEFAULT "",
	"required"	INTEGER NOT NULL DEFAULT 0,
	"readonly"	INTEGER NOT NULL DEFAULT 0,
	"hidden"	INTEGER NOT NULL DEFAULT 0,
	PRIMARY KEY("id")
)

CREATE TABLE "files" (
	"id"	TEXT NOT NULL,
	"name"	TEXT NOT NULL,
	"size"	INTEGER NOT NULL,
	"width"	INTEGER NOT NULL DEFAULT 0,
	"height"	INTEGER NOT NULL DEFAULT 0,
	"mime"	TEXT NOT NULL,
	"checksum"	TEXT NOT NULL,
	"record_id"	TEXT,
	"is_shared"	INTEGER NOT NULL DEFAULT 0,
	PRIMARY KEY("id")
)

CREATE TABLE "records" (
	"id"	TEXT NOT NULL,
	"schema_id"	TEXT NOT NULL,
	"created_at"	TEXT NOT NULL,
	"created_by"	TEXT NOT NULL,
	"published_at"	TEXT,
	"published_by"	TEXT,
	"trashed_at"	TEXT,
	"trashed_by"	INTEGER,
	"scheduled_at"	TEXT,
	"scheduled_by"	TEXT,
	"title_field_id"	TEXT NOT NULL DEFAULT 'as',
	PRIMARY KEY("id")
)

CREATE TABLE "records_data" (
	"id"	TEXT NOT NULL,
	"locale"	TEXT NOT NULL,
	"value"	TEXT NOT NULL,
	"updated_at"	TEXT NOT NULL,
	"updated_by"	TEXT NOT NULL,
	"mode"	TEXT NOT NULL,
	"record_id"	TEXT NOT NULL,
	"field_id"	TEXT NOT NULL,
	PRIMARY KEY("id"),
	UNIQUE("locale","mode","record_id","field_id")
)

CREATE TABLE "records_files" (
	"id"	TEXT NOT NULL,
	"record_id"	TEXT NOT NULL,
	"file_id"	TEXT NOT NULL,
	"mode"	TEXT NOT NULL,
	"locale"	TEXT NOT NULL,
	"rank"	INTEGER NOT NULL,
	"field_id"	TEXT NOT NULL,
	PRIMARY KEY("id"),
	UNIQUE("record_id","file_id","mode","locale")
)

CREATE TABLE "schemas" (
	"id"	TEXT NOT NULL,
	"name"	TEXT NOT NULL,
	"revisions"	INTEGER NOT NULL,
	"alias"	TEXT NOT NULL,
	"title_id"	TEXT NOT NULL,
	PRIMARY KEY("id")
)

CREATE TABLE "users" (
	"id"	varchar NOT NULL,
	"name"	varchar,
	"email"	varchar NOT NULL,
	"password"	varchar,
	"status"	varchar NOT NULL,
	"roles"	TEXT NOT NULL,
	"createdAt"	varchar NOT NULL,
	"updatedAt"	varchar NOT NULL,
	"loggedInAt"	varchar,
	"mailToken"	varchar,
	PRIMARY KEY("id")
)
