Commit 9ea0ac34 authored by Beth Rennie's avatar Beth Rennie Committed by brennie@mozilla.com
Browse files

Bug 1956080 - Add a table for Nimbus enrollments...

Bug 1956080 - Add a table for Nimbus enrollments r=jhirsch,nimbus-reviewers,profiles-reviewers,relud,mossop

Differential Revision: https://phabricator.services.mozilla.com/D249466
parent 91672f1b
Loading
Loading
Loading
Loading
+28 −2
Changes for toolkit/profile/ProfilesDatastoreService.sys.mjs: 28 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ class ProfilesDatastoreServiceClass {
  async createTables() {
    // TODO: (Bug 1902320) Handle exceptions on connection opening
    let currentVersion = await this.#connection.getSchemaVersion();
    if (currentVersion == 1) {
    if (currentVersion == 2) {
      return;
    }

@@ -93,11 +93,37 @@ class ProfilesDatastoreServiceClass {

        await this.#connection.execute(createSharedPrefsTable);
      });
    }

      await this.#connection.setSchemaVersion(1);
    }

    if (currentVersion < 2) {
      await this.#connection.executeTransaction(async () => {
        const createEnrollmentsTable = `
          CREATE TABLE IF NOT EXISTS "NimbusEnrollments" (
            id             INTEGER NOT NULL,
            profileId      INTEGER NOT NULL,
            slug           TEXT NOT NULL,
            branchSlug     TEXT NOT NULL,
            recipe         JSONB,
            active         BOOLEAN NOT NULL,
            unenrollReason TEXT,
            lastSeen       TEXT NOT NULL,
            setPrefs       JSONB,
            prefFlips      JSONB,
            source         TEXT NOT NULL,
            PRIMARY KEY(id),
            UNIQUE (profileId, slug) ON CONFLICT FAIL
          );
        `;

        await this.#connection.execute(createEnrollmentsTable);
      });

      await this.#connection.setSchemaVersion(2);
    }
  }

  /**
   * Trigger an async cross-instance notification that the data in the
   * datastore has been changed.