/* This file was generated by ODB, object-relational mapping (ORM)
 * compiler for C++.
 */

DROP TABLE IF EXISTS "build_delay" CASCADE;

DROP TABLE IF EXISTS "build_results" CASCADE;

DROP TABLE IF EXISTS "build" CASCADE;

DROP TABLE IF EXISTS "schema_version";

CREATE TABLE "build" (
  "package_tenant" TEXT NOT NULL,
  "package_name" CITEXT NOT NULL,
  "package_version_epoch" INTEGER NOT NULL,
  "package_version_canonical_upstream" TEXT NOT NULL,
  "package_version_canonical_release" TEXT NOT NULL COLLATE "C",
  "package_version_revision" INTEGER NOT NULL,
  "configuration" TEXT NOT NULL,
  "toolchain_name" TEXT NOT NULL,
  "toolchain_version_epoch" INTEGER NOT NULL,
  "toolchain_version_canonical_upstream" TEXT NOT NULL,
  "toolchain_version_canonical_release" TEXT NOT NULL COLLATE "C",
  "toolchain_version_revision" INTEGER NOT NULL,
  "package_version_upstream" TEXT NOT NULL,
  "package_version_release" TEXT NULL,
  "toolchain_version_upstream" TEXT NOT NULL,
  "toolchain_version_release" TEXT NULL,
  "state" TEXT NOT NULL,
  "timestamp" BIGINT NOT NULL,
  "force" TEXT NOT NULL,
  "status" TEXT NULL,
  "completion_timestamp" BIGINT NOT NULL DEFAULT 0,
  "agent_fingerprint" TEXT NULL,
  "agent_challenge" TEXT NULL,
  "machine" TEXT NOT NULL,
  "machine_summary" TEXT NOT NULL,
  "target" TEXT NOT NULL,
  PRIMARY KEY ("package_tenant",
               "package_name",
               "package_version_epoch",
               "package_version_canonical_upstream",
               "package_version_canonical_release",
               "package_version_revision",
               "configuration",
               "toolchain_name",
               "toolchain_version_epoch",
               "toolchain_version_canonical_upstream",
               "toolchain_version_canonical_release",
               "toolchain_version_revision"));

CREATE INDEX "build_timestamp_i"
  ON "build" ("timestamp");

CREATE TABLE "build_results" (
  "package_tenant" TEXT NOT NULL,
  "package_name" CITEXT NOT NULL,
  "package_version_epoch" INTEGER NOT NULL,
  "package_version_canonical_upstream" TEXT NOT NULL,
  "package_version_canonical_release" TEXT NOT NULL COLLATE "C",
  "package_version_revision" INTEGER NOT NULL,
  "configuration" TEXT NOT NULL,
  "toolchain_name" TEXT NOT NULL,
  "toolchain_version_epoch" INTEGER NOT NULL,
  "toolchain_version_canonical_upstream" TEXT NOT NULL,
  "toolchain_version_canonical_release" TEXT NOT NULL COLLATE "C",
  "toolchain_version_revision" INTEGER NOT NULL,
  "index" BIGINT NOT NULL,
  "operation" TEXT NOT NULL,
  "status" TEXT NOT NULL,
  "log" TEXT NOT NULL,
  CONSTRAINT "object_id_fk"
    FOREIGN KEY ("package_tenant",
                 "package_name",
                 "package_version_epoch",
                 "package_version_canonical_upstream",
                 "package_version_canonical_release",
                 "package_version_revision",
                 "configuration",
                 "toolchain_name",
                 "toolchain_version_epoch",
                 "toolchain_version_canonical_upstream",
                 "toolchain_version_canonical_release",
                 "toolchain_version_revision")
    REFERENCES "build" ("package_tenant",
                        "package_name",
                        "package_version_epoch",
                        "package_version_canonical_upstream",
                        "package_version_canonical_release",
                        "package_version_revision",
                        "configuration",
                        "toolchain_name",
                        "toolchain_version_epoch",
                        "toolchain_version_canonical_upstream",
                        "toolchain_version_canonical_release",
                        "toolchain_version_revision")
    ON DELETE CASCADE);

CREATE INDEX "build_results_object_id_i"
  ON "build_results" (
    "package_tenant",
    "package_name",
    "package_version_epoch",
    "package_version_canonical_upstream",
    "package_version_canonical_release",
    "package_version_revision",
    "configuration",
    "toolchain_name",
    "toolchain_version_epoch",
    "toolchain_version_canonical_upstream",
    "toolchain_version_canonical_release",
    "toolchain_version_revision");

CREATE INDEX "build_results_index_i"
  ON "build_results" ("index");

CREATE TABLE "build_delay" (
  "package_tenant" TEXT NOT NULL,
  "package_name" CITEXT NOT NULL,
  "package_version_epoch" INTEGER NOT NULL,
  "package_version_canonical_upstream" TEXT NOT NULL,
  "package_version_canonical_release" TEXT NOT NULL COLLATE "C",
  "package_version_revision" INTEGER NOT NULL,
  "configuration" TEXT NOT NULL,
  "toolchain_name" TEXT NOT NULL,
  "toolchain_version_epoch" INTEGER NOT NULL,
  "toolchain_version_canonical_upstream" TEXT NOT NULL,
  "toolchain_version_canonical_release" TEXT NOT NULL COLLATE "C",
  "toolchain_version_revision" INTEGER NOT NULL,
  "package_version_upstream" TEXT NOT NULL,
  "package_version_release" TEXT NULL,
  "toolchain_version_upstream" TEXT NOT NULL,
  "toolchain_version_release" TEXT NULL,
  "report_timestamp" BIGINT NOT NULL,
  "package_timestamp" BIGINT NOT NULL,
  PRIMARY KEY ("package_tenant",
               "package_name",
               "package_version_epoch",
               "package_version_canonical_upstream",
               "package_version_canonical_release",
               "package_version_revision",
               "configuration",
               "toolchain_name",
               "toolchain_version_epoch",
               "toolchain_version_canonical_upstream",
               "toolchain_version_canonical_release",
               "toolchain_version_revision"));

CREATE TABLE "schema_version" (
  "name" TEXT NOT NULL PRIMARY KEY,
  "version" BIGINT NOT NULL,
  "migration" BOOLEAN NOT NULL);

INSERT INTO "schema_version" (
  "name", "version", "migration")
  VALUES ('build', 12, FALSE);

