CREATE TABLE IF NOT EXISTS inventory (
	"Iid" INTEGER PRIMARY KEY AUTOINCREMENT,
	"Name" TEXT NOT NULL,
	"Vcenter" TEXT NOT NULL,
	"VmId" TEXT,
	"EventKey" TEXT,
	"CloudId" TEXT,
	"CreationTime" INTEGER,
	"DeletionTime" INTEGER,
	"ResourcePool" TEXT,
	"VmType" TEXT,
	"Datacenter" TEXT,
	"Cluster" TEXT,
	"Folder" TEXT,
	"ProvisionedDisk" REAL,
	"InitialVcpus" INTEGER,
	"InitialRam" INTEGER,
	"IsTemplate" TEXT NOT NULL DEFAULT "FALSE",
	"PoweredOn" TEXT NOT NULL DEFAULT "FALSE",
	"SrmPlaceholder" TEXT NOT NULL DEFAULT "FALSE",
	"VmUuid" TEXT
);

CREATE TABLE IF NOT EXISTS updates (
	"Uid" INTEGER PRIMARY KEY AUTOINCREMENT,
	"InventoryId" INTEGER,
	"UpdateTime" INTEGER,
	"UpdateType" TEXT NOT NULL,
	"NewVcpus" INTEGER,
	"NewRam" INTEGER,
	"NewResourcePool" TEXT,
	"EventKey" TEXT,
	"EventId" TEXT,
	"NewProvisionedDisk" REAL,
	"UserName" TEXT,
	"PlaceholderChange" TEXT,
	"Name" TEXT,
	"RawChangeString" BLOB
);

CREATE TABLE IF NOT EXISTS events (
	"Eid" INTEGER PRIMARY KEY AUTOINCREMENT,
	"CloudId" TEXT NOT NULL,
	"Source" TEXT NOT NULL,
	"EventTime" INTEGER,
	"ChainId" TEXT NOT NULL,
	"VmId" TEXT,
	"EventKey" TEXT,
	"DatacenterName" TEXT,
	"ComputeResourceName" TEXT,
	"UserName" TEXT,
	"Processed" INTEGER NOT NULL DEFAULT 0,
	"DatacenterId" TEXT,
	"ComputeResourceId" TEXT,
	"VmName" TEXT,
	"EventType" TEXT
);

CREATE TABLE IF NOT EXISTS inventory_history (
	"Hid" INTEGER PRIMARY KEY AUTOINCREMENT,
	"InventoryId" INTEGER,
	"ReportDate" INTEGER,
	"UpdateTime" INTEGER,
	"PreviousVcpus" INTEGER,
	"PreviousRam" INTEGER,
	"PreviousResourcePool" TEXT,
	"PreviousProvisionedDisk" REAL
);
