Jump to content

User:DWalden (WMF)/IPInfo/Preference Combinations

From mediawiki.org

This returns a table with all the possible values of the IP Info user preferences. Each row in the table represents a single possible way a user can set their preferences.

It includes setting them as a local and global preference.

It deals with the logic such as:

  • You cannot set ipinfo-enabled without first setting ipinfo-beta-feature-enable.
  • You cannot set a local override unless the preference is set as a global preference.
CREATE DATABASE ipinfo;
USE ipinfo;

CREATE TABLE individual_preference_combinations AS
SELECT * FROM
(SELECT "n/a" AS "global" UNION SELECT 0 AS "global" UNION SELECT 1 AS "global") AS Global,
(SELECT "n/a" AS "local" UNION SELECT 0 AS "local" UNION SELECT 1 AS "local") AS Local,
(SELECT "n/a" AS "override" UNION SELECT 0 AS "override" UNION SELECT 1 AS "override") AS Override;

CREATE TABLE valid_individual_preference_combinations AS
SELECT * FROM individual_preference_combinations
WHERE (global = "n/a" AND override = "n/a" AND local != "n/a")
OR (global != "n/a" AND local = "n/a");

-- Combinations we want to test
SELECT * FROM valid_individual_preference_combinations AS beta
LEFT JOIN (SELECT "n/a" AS "agreement" UNION SELECT 1 AS "agreement") AS agreement
ON (beta.global = "n/a" AND beta.local = 1) OR (beta.global = 1 AND beta.override = "n/a") OR (beta.global != "n/a" AND beta.override = 1);

Currently, this outputs:

+--------+-------+----------+-----------+
| global | local | override | agreement |
+--------+-------+----------+-----------+
| 1      | n/a   | n/a      | n/a       |
| n/a    | 1     | n/a      | n/a       |
| 0      | n/a   | 1        | n/a       |
| 1      | n/a   | 1        | n/a       |
| 1      | n/a   | n/a      | 1         |
| n/a    | 1     | n/a      | 1         |
| 0      | n/a   | 1        | 1         |
| 1      | n/a   | 1        | 1         |
| 0      | n/a   | n/a      | NULL      |
| n/a    | 0     | n/a      | NULL      |
| 0      | n/a   | 0        | NULL      |
| 1      | n/a   | 0        | NULL      |
+--------+-------+----------+-----------+