From 402d802ff5d8ad38e4d5ca6cba16a91f8b4f1c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Wed, 4 Oct 2017 14:58:37 +0200 Subject: [PATCH 01/37] Move dataset_version to just after dataset --- sql/swefreq.sql | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sql/swefreq.sql b/sql/swefreq.sql index ee70fc1c7..cce0f5d98 100644 --- a/sql/swefreq.sql +++ b/sql/swefreq.sql @@ -40,6 +40,18 @@ CREATE TABLE IF NOT EXISTS dataset ( CONSTRAINT FOREIGN KEY (study_pk) REFERENCES study(study_pk) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; +CREATE TABLE IF NOT EXISTS dataset_version ( + dataset_version_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, + dataset_pk INTEGER NOT NULL, + version VARCHAR(20) NOT NULL, + description TEXT NOT NULL, + terms TEXT NOT NULL, + var_call_ref VARCHAR(50) DEFAULT NULL, + available_from TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + ref_doi VARCHAR(100) DEFAULT NULL, + CONSTRAINT FOREIGN KEY (dataset_pk) REFERENCES dataset(dataset_pk) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + CREATE TABLE IF NOT EXISTS collection ( collection_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100) NOT NULL, @@ -149,18 +161,6 @@ CREATE OR REPLACE VIEW dataset_access_pending AS GROUP BY requested.user_pk, requested.dataset_pk, requested.action ); -CREATE TABLE IF NOT EXISTS dataset_version ( - dataset_version_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, - dataset_pk INTEGER NOT NULL, - version VARCHAR(20) NOT NULL, - description TEXT NOT NULL, - terms TEXT NOT NULL, - var_call_ref VARCHAR(50) DEFAULT NULL, - available_from TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - ref_doi VARCHAR(100) DEFAULT NULL, - CONSTRAINT FOREIGN KEY (dataset_pk) REFERENCES dataset(dataset_pk) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; - CREATE TABLE IF NOT EXISTS dataset_file ( dataset_file_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, dataset_version_pk INTEGER NOT NULL, From 1496b405d2e8fbe255d65138866da0383076b71b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Wed, 4 Oct 2017 15:18:40 +0200 Subject: [PATCH 02/37] Change user_log.dataset_pk to user_log.dataset_version_pk --- sql/swefreq.sql | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/sql/swefreq.sql b/sql/swefreq.sql index cce0f5d98..968229c82 100644 --- a/sql/swefreq.sql +++ b/sql/swefreq.sql @@ -71,18 +71,19 @@ CREATE TABLE IF NOT EXISTS sample_set ( CREATE TABLE IF NOT EXISTS user_log ( user_log_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, user_pk INTEGER NOT NULL, - dataset_pk INTEGER NOT NULL, + dataset_version_pk INTEGER NOT NULL, action ENUM ('consent','download', 'access_requested','access_granted','access_revoked', 'private_link') DEFAULT NULL, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT FOREIGN KEY (user_pk) REFERENCES user(user_pk), - CONSTRAINT FOREIGN KEY (dataset_pk) REFERENCES dataset(dataset_pk) + CONSTRAINT FOREIGN KEY (dataset_version_pk) + REFERENCES dataset(dataset_version_pk) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE OR REPLACE VIEW _user_log_summary AS - SELECT MAX(user_log_pk) AS user_log_pk, user_pk, dataset_pk, action, - MAX(ts) AS ts + SELECT MAX(user_log_pk) AS user_log_pk, user_pk, dataset_version_pk, + action, MAX(ts) AS ts FROM user_log GROUP BY user_pk, dataset_pk, action; @@ -104,27 +105,27 @@ CREATE OR REPLACE VIEW dataset_access_current AS (consent.action IS NOT NULL) AS has_consented, request.ts AS access_requested FROM dataset_access AS access - JOIN ( SELECT user_pk, dataset_pk, MAX(ts) AS ts + JOIN ( SELECT user_pk, dataset_version_pk, MAX(ts) AS ts FROM user_log WHERE action = "access_requested" - GROUP BY user_pk, dataset_pk ) AS request + GROUP BY user_pk, dataset_version_pk ) AS request ON access.user_pk = request.user_pk AND - access.dataset_pk = request.dataset_pk + access.dataset_version_pk = request.dataset_version_pk LEFT JOIN user_log AS consent ON access.user_pk = consent.user_pk AND - access.dataset_pk = consent.dataset_pk AND + access.dataset_version_pk = consent.dataset_version_pk AND consent.action = 'consent' - WHERE (access.user_pk, access.dataset_pk) IN ( + WHERE (access.user_pk, access.dataset_version_pk) IN ( -- gets user_pk for all users with current access -- from https://stackoverflow.com/a/39190423/4941495 - SELECT granted.user_pk, granted.dataset_pk + SELECT granted.user_pk, granted.dataset_version_pk FROM _user_log_summary AS granted LEFT JOIN _user_log_summary AS revoked ON granted.user_pk = revoked.user_pk AND - granted.dataset_pk = revoked.dataset_pk AND + granted.dataset_version_pk = revoked.dataset_version_pk AND revoked.action = 'access_revoked' WHERE granted.action = 'access_granted' AND (revoked.user_pk IS NULL OR granted.ts > revoked.ts) - GROUP BY granted.user_pk, granted.dataset_pk, granted.action + GROUP BY granted.user_pk, granted.dataset_version_pk, granted.action ); CREATE OR REPLACE VIEW dataset_access_pending AS @@ -134,31 +135,33 @@ CREATE OR REPLACE VIEW dataset_access_pending AS (consent.action IS NOT NULL) AS has_consented, request.ts AS access_requested FROM dataset_access AS access - JOIN ( SELECT user_pk, dataset_pk, MAX(ts) AS ts + JOIN ( SELECT user_pk, dataset_version_pk, MAX(ts) AS ts FROM user_log WHERE action = "access_requested" - GROUP BY user_pk, dataset_pk ) AS request + GROUP BY user_pk, dataset_version_pk ) AS request ON access.user_pk = request.user_pk AND - access.dataset_pk = request.dataset_pk + access.dataset_version_pk = request.dataset_version_pk LEFT JOIN user_log AS consent ON access.user_pk = consent.user_pk AND - access.dataset_pk = consent.dataset_pk AND + access.dataset_version_pk = consent.dataset_version_pk AND consent.action = 'consent' - WHERE (access.user_pk, access.dataset_pk) IN ( + WHERE (access.user_pk, access.dataset_version_pk) IN ( -- get user_pk for all users that have pending access requests - SELECT requested.user_pk, requested.dataset_pk + SELECT requested.user_pk, requested.dataset_version_pk FROM _user_log_summary AS requested LEFT JOIN _user_log_summary AS granted ON requested.user_pk = granted.user_pk AND - requested.dataset_pk = granted.dataset_pk AND + requested.dataset_version_pk = granted.dataset_version_pk AND granted.action = 'access_granted' LEFT JOIN _user_log_summary AS revoked ON requested.user_pk = revoked.user_pk AND - requested.dataset_pk = revoked.dataset_pk AND + requested.dataset_version_pk = revoked.dataset_version_pk AND revoked.action = 'access_revoked' WHERE requested.action = 'access_requested' AND (granted.user_pk IS NULL OR requested.ts > granted.ts) AND (revoked.user_pk IS NULL OR requested.ts > revoked.ts) - GROUP BY requested.user_pk, requested.dataset_pk, requested.action + GROUP BY requested.user_pk, + requested.dataset_version_pk, + requested.action ); CREATE TABLE IF NOT EXISTS dataset_file ( From f2281608511a4f96b091584bd41e2f158a0b4847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Wed, 4 Oct 2017 15:31:56 +0200 Subject: [PATCH 03/37] Forgot one dataset_pk --> dataset_version_pk --- sql/swefreq.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/swefreq.sql b/sql/swefreq.sql index 968229c82..38dfda564 100644 --- a/sql/swefreq.sql +++ b/sql/swefreq.sql @@ -85,7 +85,7 @@ CREATE OR REPLACE VIEW _user_log_summary AS SELECT MAX(user_log_pk) AS user_log_pk, user_pk, dataset_version_pk, action, MAX(ts) AS ts FROM user_log - GROUP BY user_pk, dataset_pk, action; + GROUP BY user_pk, dataset_version_pk, action; CREATE TABLE IF NOT EXISTS dataset_access ( dataset_access_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, From 98aec7cbf00b623036bbb9e8da09db7a478a98b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Wed, 4 Oct 2017 15:44:03 +0200 Subject: [PATCH 04/37] Empty the patch --- sql/patch-master-db.sql | 212 ---------------------------------------- 1 file changed, 212 deletions(-) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 6a8887ec0..270af26c5 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -1,215 +1,3 @@ -- Patches a database that is using the master checkout of the -- swefreq.sql schema definition to the develop version. --- Add the three new meta data tables. - -CREATE TABLE IF NOT EXISTS study ( - study_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, - pi_name VARCHAR(100) NOT NULL, - pi_email VARCHAR(100) NOT NULL, - contact_name VARCHAR(100) NOT NULL, - contact_email VARCHAR(100) NOT NULL, - title VARCHAR(100) NOT NULL, - description TEXT DEFAULT NULL, - publication_date DATE NOT NULL, - ref_doi VARCHAR(100) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=latin1; - -CREATE TABLE IF NOT EXISTS collection ( - collection_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, - name VARCHAR(100) NOT NULL, - ethnicity VARCHAR(50) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=latin1; - -CREATE TABLE IF NOT EXISTS sample_set ( - sample_set_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, - dataset_pk INTEGER NOT NULL, - collection_pk INTEGER NOT NULL, - sample_size INTEGER NOT NULL, - phenotype VARCHAR(50) NOT NULL, - CONSTRAINT FOREIGN KEY (dataset_pk) REFERENCES dataset(dataset_pk), - CONSTRAINT FOREIGN KEY (collection_pk) REFERENCES collection(collection_pk) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; - --- Insert data into study, sample_set and collection: - -INSERT INTO study - (study_pk, pi_name, pi_email, contact_name, contact_email, title, - publication_date, ref_doi) -VALUES (1, "Ulf Gyllensten", "Ulf.Gyllensten@igp.uu.se", - "the SweGen project", "swegen@scilifelab.se", - "SweGen", '2016-12-23', "10.1038/ejhg.2017.130"); - -INSERT INTO collection (collection_pk, name, ethnicity) -VALUES (1, "Swedish Twin Registry", "Swedish"); - -INSERT INTO sample_set - (sample_set_pk, dataset_pk, collection_pk, sample_size, phenotype) -VALUES (1, 1, 1, 1000, "None"); - -UPDATE dataset SET browser_uri="https://swegen-exac.nbis.se/" WHERE dataset_pk=1; - --- Add the new columns to the dataset table. We don't care about --- ordering the columns in the same order as in the schema file. - -ALTER TABLE dataset ADD COLUMN ( - study_pk INTEGER NOT NULL, - avg_seq_depth FLOAT DEFAULT NULL, - seq_type VARCHAR(50) DEFAULT NULL, - seq_tech VARCHAR(50) DEFAULT NULL, - seq_center VARCHAR(100) DEFAULT NULL, - dataset_size INTEGER UNSIGNED DEFAULT NULL ); - --- Insert correct values into dataset.dataset_size. - -UPDATE dataset SET dataset_size = 1000, seq_type = "WGS", - seq_tech = "Illumina HiSeq X", avg_seq_depth= 36.7, - seq_center = "NGI, Scilifelab"; - --- Correct the dataset.dataset_size column. - -ALTER TABLE dataset MODIFY COLUMN dataset_size INTEGER UNSIGNED NOT NULL; - --- Insert reference to the sample set. - --- FIXME: (is this correct?) -UPDATE dataset SET study_pk = 1; - --- New foreign key in the dataset table. - -ALTER TABLE dataset ADD CONSTRAINT - FOREIGN KEY (study_pk) REFERENCES study(study_pk); - --- Add new column to dataset_version. - -ALTER TABLE dataset_version ADD COLUMN - var_call_ref VARCHAR(50) DEFAULT NULL; - -UPDATE dataset_version SET var_call_ref="hg19"; - --- Add the linkhash table - -CREATE TABLE IF NOT EXISTS linkhash ( - linkhash_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, - dataset_version_pk INTEGER NOT NULL, - user_pk INTEGER NOT NULL, - hash VARCHAR(64) NOT NULL, - expires_on TIMESTAMP NOT NULL, - CONSTRAINT FOREIGN KEY (dataset_version_pk) - REFERENCES dataset_version(dataset_version_pk), - CONSTRAINT FOREIGN KEY (user_pk) REFERENCES user(user_pk) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; - --- There's a new action ENUM in user_log too. - -ALTER TABLE user_log MODIFY COLUMN - action ENUM ('consent','download', - 'access_requested','access_granted','access_revoked', - 'private_link') DEFAULT NULL; - --- Summary view of user_log - -CREATE OR REPLACE VIEW _user_log_summary AS - SELECT MAX(user_log_pk) AS user_log_pk, user_pk, dataset_pk, action, - MAX(ts) AS ts - FROM user_log - GROUP BY user_pk, dataset_pk, action; - --- Add dataset_version.avaliable_from_ts and dataset_version.ref_doi - -ALTER TABLE dataset_version ADD COLUMN ( - available_from TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - ref_doi VARCHAR(100) DEFAULT NULL -); - -ALTER TABLE dataset_version DROP COLUMN ts; - --- the above makes dataset_version.is_current superfluous - -ALTER TABLE dataset_version DROP COLUMN is_current; - --- Add the ref_doi for the swegen dataset - -UPDATE dataset_version SET ref_doi='10.17044/NBIS/G000003' WHERE dataset_version_pk=2; - --- add the dataset_version_current view - -CREATE OR REPLACE VIEW dataset_version_current AS - SELECT * FROM dataset_version - WHERE (dataset_pk, dataset_version_pk) IN ( - SELECT dataset_pk, MAX(dataset_version_pk) FROM dataset_version - WHERE available_from < now() - GROUP BY dataset_pk ); - - --- add the dataset_access_current view - -ALTER TABLE dataset_access - DROP COLUMN has_consented, - DROP COLUMN has_access; - -CREATE OR REPLACE VIEW dataset_access_current AS - SELECT DISTINCT - access.*, - TRUE AS has_access, - (consent.action IS NOT NULL) AS has_consented, - request.ts AS access_requested - FROM dataset_access AS access - JOIN ( SELECT user_pk, dataset_pk, MAX(ts) AS ts - FROM user_log WHERE action = "access_requested" - GROUP BY user_pk, dataset_pk ) AS request - ON access.user_pk = request.user_pk AND - access.dataset_pk = request.dataset_pk - LEFT JOIN user_log AS consent - ON access.user_pk = consent.user_pk AND - access.dataset_pk = consent.dataset_pk AND - consent.action = 'consent' - WHERE (access.user_pk, access.dataset_pk) IN ( - -- gets user_pk for all users with current access - -- from https://stackoverflow.com/a/39190423/4941495 - SELECT granted.user_pk, granted.dataset_pk - FROM _user_log_summary AS granted - LEFT JOIN _user_log_summary AS revoked - ON granted.user_pk = revoked.user_pk AND - granted.dataset_pk = revoked.dataset_pk AND - revoked.action = 'access_revoked' - WHERE granted.action = 'access_granted' AND - (revoked.user_pk IS NULL OR granted.ts > revoked.ts) - GROUP BY granted.user_pk, granted.dataset_pk, granted.action - ); - --- add the dataset_access_pending view - -CREATE OR REPLACE VIEW dataset_access_pending AS - SELECT DISTINCT - access.*, - FALSE AS has_access, - (consent.action IS NOT NULL) AS has_consented, - request.ts AS access_requested - FROM dataset_access AS access - JOIN ( SELECT user_pk, dataset_pk, MAX(ts) AS ts - FROM user_log WHERE action = "access_requested" - GROUP BY user_pk, dataset_pk ) AS request - ON access.user_pk = request.user_pk AND - access.dataset_pk = request.dataset_pk - LEFT JOIN user_log AS consent - ON access.user_pk = consent.user_pk AND - access.dataset_pk = consent.dataset_pk AND - consent.action = 'consent' - WHERE (access.user_pk, access.dataset_pk) IN ( - -- get user_pk for all users that have pending access requests - SELECT requested.user_pk, requested.dataset_pk - FROM _user_log_summary AS requested - LEFT JOIN _user_log_summary AS granted - ON requested.user_pk = granted.user_pk AND - requested.dataset_pk = granted.dataset_pk AND - granted.action = 'access_granted' - LEFT JOIN _user_log_summary AS revoked - ON requested.user_pk = revoked.user_pk AND - requested.dataset_pk = revoked.dataset_pk AND - revoked.action = 'access_revoked' - WHERE requested.action = 'access_requested' AND - (granted.user_pk IS NULL OR requested.ts > granted.ts) AND - (revoked.user_pk IS NULL OR requested.ts > revoked.ts) - GROUP BY requested.user_pk, requested.dataset_pk, requested.action - ); From 30908617a5fcf695d800b9c7ccceb85feb541632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Thu, 5 Oct 2017 10:54:09 +0200 Subject: [PATCH 05/37] Patch planning --- sql/patch-master-db.sql | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 270af26c5..dc41c9fe4 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -1,3 +1,10 @@ -- Patches a database that is using the master checkout of the -- swefreq.sql schema definition to the develop version. +-- user_log.dataset_pk changes to user_log.dataset_version_pk +-- 1. Insert new column user_log.dataset_version_pk +-- 2. Add foreign constraints +-- 3. Populate column user_log.dataset_version_pk +-- 4. Update dependent views and tables +-- 5. Drop old dataset_pk foreign constraint in user_log +-- 6. Drop column user_log.dataset_pk From 78594a3803a5e29f9e61f6d7f80e338367294b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Fri, 6 Oct 2017 11:10:01 +0200 Subject: [PATCH 06/37] Rename user_log to user_access_log --- sql/swefreq.sql | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/sql/swefreq.sql b/sql/swefreq.sql index 38dfda564..bf989e68a 100644 --- a/sql/swefreq.sql +++ b/sql/swefreq.sql @@ -68,8 +68,8 @@ CREATE TABLE IF NOT EXISTS sample_set ( CONSTRAINT FOREIGN KEY (collection_pk) REFERENCES collection(collection_pk) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -CREATE TABLE IF NOT EXISTS user_log ( - user_log_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, +CREATE TABLE IF NOT EXISTS user_access_log ( + user_access_log_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, user_pk INTEGER NOT NULL, dataset_version_pk INTEGER NOT NULL, action ENUM ('consent','download', @@ -81,10 +81,10 @@ CREATE TABLE IF NOT EXISTS user_log ( REFERENCES dataset(dataset_version_pk) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -CREATE OR REPLACE VIEW _user_log_summary AS - SELECT MAX(user_log_pk) AS user_log_pk, user_pk, dataset_version_pk, - action, MAX(ts) AS ts - FROM user_log +CREATE OR REPLACE VIEW _user_access_log_summary AS + SELECT MAX(user_access_log_pk) AS user_access_log_pk, user_pk, + dataset_version_pk, action, MAX(ts) AS ts + FROM user_access_log GROUP BY user_pk, dataset_version_pk, action; CREATE TABLE IF NOT EXISTS dataset_access ( @@ -106,11 +106,11 @@ CREATE OR REPLACE VIEW dataset_access_current AS request.ts AS access_requested FROM dataset_access AS access JOIN ( SELECT user_pk, dataset_version_pk, MAX(ts) AS ts - FROM user_log WHERE action = "access_requested" + FROM user_access_log WHERE action = "access_requested" GROUP BY user_pk, dataset_version_pk ) AS request ON access.user_pk = request.user_pk AND access.dataset_version_pk = request.dataset_version_pk - LEFT JOIN user_log AS consent + LEFT JOIN user_access_log AS consent ON access.user_pk = consent.user_pk AND access.dataset_version_pk = consent.dataset_version_pk AND consent.action = 'consent' @@ -118,8 +118,8 @@ CREATE OR REPLACE VIEW dataset_access_current AS -- gets user_pk for all users with current access -- from https://stackoverflow.com/a/39190423/4941495 SELECT granted.user_pk, granted.dataset_version_pk - FROM _user_log_summary AS granted - LEFT JOIN _user_log_summary AS revoked + FROM _user_access_log_summary AS granted + LEFT JOIN _user_access_log_summary AS revoked ON granted.user_pk = revoked.user_pk AND granted.dataset_version_pk = revoked.dataset_version_pk AND revoked.action = 'access_revoked' @@ -136,23 +136,23 @@ CREATE OR REPLACE VIEW dataset_access_pending AS request.ts AS access_requested FROM dataset_access AS access JOIN ( SELECT user_pk, dataset_version_pk, MAX(ts) AS ts - FROM user_log WHERE action = "access_requested" + FROM user_access_log WHERE action = "access_requested" GROUP BY user_pk, dataset_version_pk ) AS request ON access.user_pk = request.user_pk AND access.dataset_version_pk = request.dataset_version_pk - LEFT JOIN user_log AS consent + LEFT JOIN user_access_log AS consent ON access.user_pk = consent.user_pk AND access.dataset_version_pk = consent.dataset_version_pk AND consent.action = 'consent' WHERE (access.user_pk, access.dataset_version_pk) IN ( -- get user_pk for all users that have pending access requests SELECT requested.user_pk, requested.dataset_version_pk - FROM _user_log_summary AS requested - LEFT JOIN _user_log_summary AS granted + FROM _user_access_log_summary AS requested + LEFT JOIN _user_access_log_summary AS granted ON requested.user_pk = granted.user_pk AND requested.dataset_version_pk = granted.dataset_version_pk AND granted.action = 'access_granted' - LEFT JOIN _user_log_summary AS revoked + LEFT JOIN _user_access_log_summary AS revoked ON requested.user_pk = revoked.user_pk AND requested.dataset_version_pk = revoked.dataset_version_pk AND revoked.action = 'access_revoked' From c10384a7844288427760942311fe6c5699fe4440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Fri, 6 Oct 2017 11:20:51 +0200 Subject: [PATCH 07/37] user_access_log now has dataset_pk again --- sql/swefreq.sql | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/sql/swefreq.sql b/sql/swefreq.sql index bf989e68a..4330c45b6 100644 --- a/sql/swefreq.sql +++ b/sql/swefreq.sql @@ -71,21 +71,20 @@ CREATE TABLE IF NOT EXISTS sample_set ( CREATE TABLE IF NOT EXISTS user_access_log ( user_access_log_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, user_pk INTEGER NOT NULL, - dataset_version_pk INTEGER NOT NULL, + dataset_pk INTEGER NOT NULL, action ENUM ('consent','download', 'access_requested','access_granted','access_revoked', 'private_link') DEFAULT NULL, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT FOREIGN KEY (user_pk) REFERENCES user(user_pk), - CONSTRAINT FOREIGN KEY (dataset_version_pk) - REFERENCES dataset(dataset_version_pk) + CONSTRAINT FOREIGN KEY (dataset_pk) REFERENCES dataset(dataset_pk) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE OR REPLACE VIEW _user_access_log_summary AS SELECT MAX(user_access_log_pk) AS user_access_log_pk, user_pk, - dataset_version_pk, action, MAX(ts) AS ts + dataset_pk, action, MAX(ts) AS ts FROM user_access_log - GROUP BY user_pk, dataset_version_pk, action; + GROUP BY user_pk, dataset_pk, action; CREATE TABLE IF NOT EXISTS dataset_access ( dataset_access_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -105,27 +104,27 @@ CREATE OR REPLACE VIEW dataset_access_current AS (consent.action IS NOT NULL) AS has_consented, request.ts AS access_requested FROM dataset_access AS access - JOIN ( SELECT user_pk, dataset_version_pk, MAX(ts) AS ts + JOIN ( SELECT user_pk, dataset_pk, MAX(ts) AS ts FROM user_access_log WHERE action = "access_requested" - GROUP BY user_pk, dataset_version_pk ) AS request + GROUP BY user_pk, dataset_pk ) AS request ON access.user_pk = request.user_pk AND - access.dataset_version_pk = request.dataset_version_pk + access.dataset_pk = request.dataset_pk LEFT JOIN user_access_log AS consent ON access.user_pk = consent.user_pk AND - access.dataset_version_pk = consent.dataset_version_pk AND + access.dataset_pk = consent.dataset_pk AND consent.action = 'consent' - WHERE (access.user_pk, access.dataset_version_pk) IN ( + WHERE (access.user_pk, access.dataset_pk) IN ( -- gets user_pk for all users with current access -- from https://stackoverflow.com/a/39190423/4941495 - SELECT granted.user_pk, granted.dataset_version_pk + SELECT granted.user_pk, granted.dataset_pk FROM _user_access_log_summary AS granted LEFT JOIN _user_access_log_summary AS revoked ON granted.user_pk = revoked.user_pk AND - granted.dataset_version_pk = revoked.dataset_version_pk AND + granted.dataset_pk = revoked.dataset_pk AND revoked.action = 'access_revoked' WHERE granted.action = 'access_granted' AND (revoked.user_pk IS NULL OR granted.ts > revoked.ts) - GROUP BY granted.user_pk, granted.dataset_version_pk, granted.action + GROUP BY granted.user_pk, granted.dataset_pk, granted.action ); CREATE OR REPLACE VIEW dataset_access_pending AS @@ -135,33 +134,31 @@ CREATE OR REPLACE VIEW dataset_access_pending AS (consent.action IS NOT NULL) AS has_consented, request.ts AS access_requested FROM dataset_access AS access - JOIN ( SELECT user_pk, dataset_version_pk, MAX(ts) AS ts + JOIN ( SELECT user_pk, dataset_pk, MAX(ts) AS ts FROM user_access_log WHERE action = "access_requested" - GROUP BY user_pk, dataset_version_pk ) AS request + GROUP BY user_pk, dataset_pk ) AS request ON access.user_pk = request.user_pk AND - access.dataset_version_pk = request.dataset_version_pk + access.dataset_pk = request.dataset_pk LEFT JOIN user_access_log AS consent ON access.user_pk = consent.user_pk AND - access.dataset_version_pk = consent.dataset_version_pk AND + access.dataset_pk = consent.dataset_pk AND consent.action = 'consent' - WHERE (access.user_pk, access.dataset_version_pk) IN ( + WHERE (access.user_pk, access.dataset_pk) IN ( -- get user_pk for all users that have pending access requests - SELECT requested.user_pk, requested.dataset_version_pk + SELECT requested.user_pk, requested.dataset_pk FROM _user_access_log_summary AS requested LEFT JOIN _user_access_log_summary AS granted ON requested.user_pk = granted.user_pk AND - requested.dataset_version_pk = granted.dataset_version_pk AND + requested.dataset_pk = granted.dataset_pk AND granted.action = 'access_granted' LEFT JOIN _user_access_log_summary AS revoked ON requested.user_pk = revoked.user_pk AND - requested.dataset_version_pk = revoked.dataset_version_pk AND + requested.dataset_pk = revoked.dataset_pk AND revoked.action = 'access_revoked' WHERE requested.action = 'access_requested' AND (granted.user_pk IS NULL OR requested.ts > granted.ts) AND (revoked.user_pk IS NULL OR requested.ts > revoked.ts) - GROUP BY requested.user_pk, - requested.dataset_version_pk, - requested.action + GROUP BY requested.user_pk, requested.dataset_pk, requested.action ); CREATE TABLE IF NOT EXISTS dataset_file ( From c2bf6e0bf063ea5fd18102a301c26432cbad1ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Fri, 6 Oct 2017 16:50:15 +0200 Subject: [PATCH 08/37] Add user_consent_log --- sql/swefreq.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sql/swefreq.sql b/sql/swefreq.sql index 4330c45b6..704a77f7b 100644 --- a/sql/swefreq.sql +++ b/sql/swefreq.sql @@ -80,6 +80,16 @@ CREATE TABLE IF NOT EXISTS user_access_log ( CONSTRAINT FOREIGN KEY (dataset_pk) REFERENCES dataset(dataset_pk) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; +CREATE TABLE IF NOT EXISTS user_consent_log ( + user_consent_log_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, + user_pk INTEGER NOT NULL, + dataset_version_pk INTEGER NOT NULL, + ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT FOREIGN KEY (user_pk) REFERENCES user(user_pk), + CONSTRAINT FOREIGN KEY (dataset_version_pk) + REFERENCES dataset_version(dataset_version_pk) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + CREATE OR REPLACE VIEW _user_access_log_summary AS SELECT MAX(user_access_log_pk) AS user_access_log_pk, user_pk, dataset_pk, action, MAX(ts) AS ts From 0bf5d490edf8cc0d3a89bc314d68a05dae959de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Fri, 6 Oct 2017 16:50:54 +0200 Subject: [PATCH 09/37] Add unique constraint on linkhash.hash --- sql/swefreq.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/swefreq.sql b/sql/swefreq.sql index 704a77f7b..ca4dd242a 100644 --- a/sql/swefreq.sql +++ b/sql/swefreq.sql @@ -195,6 +195,7 @@ CREATE TABLE IF NOT EXISTS linkhash ( user_pk INTEGER NOT NULL, hash VARCHAR(64) NOT NULL, expires_on TIMESTAMP NOT NULL, + CONSTRAINT UNIQUE (hash), CONSTRAINT FOREIGN KEY (dataset_version_pk) REFERENCES dataset_version(dataset_version_pk), CONSTRAINT FOREIGN KEY (user_pk) REFERENCES user(user_pk) From 28d9871fcf9b928a1b57c51c5ded05b0af3a2f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Fri, 6 Oct 2017 16:51:16 +0200 Subject: [PATCH 10/37] Add todos for things in the SQL file that must have patches written --- sql/patch-master-db.sql | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index dc41c9fe4..4bafc0705 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -8,3 +8,8 @@ -- 4. Update dependent views and tables -- 5. Drop old dataset_pk foreign constraint in user_log -- 6. Drop column user_log.dataset_pk + +-- TODO: Rename user_log to user_access_log +-- TODO: Create user_consent_log +-- TODO: Create user_download_log +-- TODO: Add unique constraint on linkhash.hash From 38d0672eedf6ab42e47c7eba2f73a6da3932f4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Fri, 6 Oct 2017 17:06:23 +0200 Subject: [PATCH 11/37] Move definition of dataset_file table --- sql/swefreq.sql | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sql/swefreq.sql b/sql/swefreq.sql index ca4dd242a..5f27a84fb 100644 --- a/sql/swefreq.sql +++ b/sql/swefreq.sql @@ -68,6 +68,15 @@ CREATE TABLE IF NOT EXISTS sample_set ( CONSTRAINT FOREIGN KEY (collection_pk) REFERENCES collection(collection_pk) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; +CREATE TABLE IF NOT EXISTS dataset_file ( + dataset_file_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, + dataset_version_pk INTEGER NOT NULL, + name VARCHAR(100) NOT NULL, + uri VARCHAR(200) NOT NULL, + CONSTRAINT FOREIGN KEY (dataset_version_pk) + REFERENCES dataset_version(dataset_version_pk) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + CREATE TABLE IF NOT EXISTS user_access_log ( user_access_log_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, user_pk INTEGER NOT NULL, @@ -171,15 +180,6 @@ CREATE OR REPLACE VIEW dataset_access_pending AS GROUP BY requested.user_pk, requested.dataset_pk, requested.action ); -CREATE TABLE IF NOT EXISTS dataset_file ( - dataset_file_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, - dataset_version_pk INTEGER NOT NULL, - name VARCHAR(100) NOT NULL, - uri VARCHAR(200) NOT NULL, - CONSTRAINT FOREIGN KEY (dataset_version_pk) - REFERENCES dataset_version(dataset_version_pk) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; - CREATE TABLE IF NOT EXISTS dataset_logo ( dataset_logo_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, dataset_pk INTEGER NOT NULL, From ec10fe993ab98689a8d5dfbb7e31d709a755ce59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Fri, 6 Oct 2017 17:06:58 +0200 Subject: [PATCH 12/37] Add user_download_log table --- sql/swefreq.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sql/swefreq.sql b/sql/swefreq.sql index 5f27a84fb..2044ef720 100644 --- a/sql/swefreq.sql +++ b/sql/swefreq.sql @@ -99,6 +99,17 @@ CREATE TABLE IF NOT EXISTS user_consent_log ( REFERENCES dataset_version(dataset_version_pk) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; +CREATE TABLE IF NOT EXISTS user_download_log ( + user_download_log_pk + INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, + user_pk INTEGER NOT NULL, + dataset_file_pk INTEGER NOT NULL, + ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT FOREIGN KEY (user_pk) REFERENCES user(user_pk), + CONSTRAINT FOREIGN KEY (dataset_file_pk) + REFERENCES dataset_file(dataset_file_pk) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + CREATE OR REPLACE VIEW _user_access_log_summary AS SELECT MAX(user_access_log_pk) AS user_access_log_pk, user_pk, dataset_pk, action, MAX(ts) AS ts From cfb0808c9669f4528da420577e94ca50d705f1c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Fri, 6 Oct 2017 17:07:19 +0200 Subject: [PATCH 13/37] Remove "consent" and "download" enums from dataset_access_log These now have their own `user_*_log` tables. --- sql/swefreq.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql/swefreq.sql b/sql/swefreq.sql index 2044ef720..e6dacbcbe 100644 --- a/sql/swefreq.sql +++ b/sql/swefreq.sql @@ -81,8 +81,7 @@ CREATE TABLE IF NOT EXISTS user_access_log ( user_access_log_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, user_pk INTEGER NOT NULL, dataset_pk INTEGER NOT NULL, - action ENUM ('consent','download', - 'access_requested','access_granted','access_revoked', + action ENUM ('access_requested','access_granted','access_revoked', 'private_link') DEFAULT NULL, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT FOREIGN KEY (user_pk) REFERENCES user(user_pk), From 204a16f3ce1041f8349c0a9dd74dc7e69457d88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Fri, 6 Oct 2017 17:09:03 +0200 Subject: [PATCH 14/37] Update todos --- sql/patch-master-db.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 4bafc0705..5ad33d411 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -13,3 +13,4 @@ -- TODO: Create user_consent_log -- TODO: Create user_download_log -- TODO: Add unique constraint on linkhash.hash +-- TODO: Remove "consent" and "download" enums from dataset_access_log From b7e5d67ad6d9b9f6135d132a2988689c513fb5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Mon, 9 Oct 2017 10:38:10 +0200 Subject: [PATCH 15/37] Remove column has_consented from views --- sql/swefreq.sql | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/sql/swefreq.sql b/sql/swefreq.sql index e6dacbcbe..537ccff3e 100644 --- a/sql/swefreq.sql +++ b/sql/swefreq.sql @@ -130,7 +130,6 @@ CREATE OR REPLACE VIEW dataset_access_current AS SELECT DISTINCT access.*, TRUE AS has_access, - (consent.action IS NOT NULL) AS has_consented, request.ts AS access_requested FROM dataset_access AS access JOIN ( SELECT user_pk, dataset_pk, MAX(ts) AS ts @@ -138,10 +137,6 @@ CREATE OR REPLACE VIEW dataset_access_current AS GROUP BY user_pk, dataset_pk ) AS request ON access.user_pk = request.user_pk AND access.dataset_pk = request.dataset_pk - LEFT JOIN user_access_log AS consent - ON access.user_pk = consent.user_pk AND - access.dataset_pk = consent.dataset_pk AND - consent.action = 'consent' WHERE (access.user_pk, access.dataset_pk) IN ( -- gets user_pk for all users with current access -- from https://stackoverflow.com/a/39190423/4941495 @@ -160,7 +155,6 @@ CREATE OR REPLACE VIEW dataset_access_pending AS SELECT DISTINCT access.*, FALSE AS has_access, - (consent.action IS NOT NULL) AS has_consented, request.ts AS access_requested FROM dataset_access AS access JOIN ( SELECT user_pk, dataset_pk, MAX(ts) AS ts @@ -168,10 +162,6 @@ CREATE OR REPLACE VIEW dataset_access_pending AS GROUP BY user_pk, dataset_pk ) AS request ON access.user_pk = request.user_pk AND access.dataset_pk = request.dataset_pk - LEFT JOIN user_access_log AS consent - ON access.user_pk = consent.user_pk AND - access.dataset_pk = consent.dataset_pk AND - consent.action = 'consent' WHERE (access.user_pk, access.dataset_pk) IN ( -- get user_pk for all users that have pending access requests SELECT requested.user_pk, requested.dataset_pk From 938bcd01057617e539b679e4733bf4b5788ce91b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Mon, 9 Oct 2017 10:39:43 +0200 Subject: [PATCH 16/37] Add todo to patch --- sql/patch-master-db.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 5ad33d411..05fa2eed6 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -14,3 +14,4 @@ -- TODO: Create user_download_log -- TODO: Add unique constraint on linkhash.hash -- TODO: Remove "consent" and "download" enums from dataset_access_log +-- TODO: Remove has_concented from views From e6957f20262a92d0ad5cecdca9fed0bc6abca2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Tue, 10 Oct 2017 16:48:17 +0200 Subject: [PATCH 17/37] False news: user_log.dataset_pk changes to user_log.dataset_version_pk --- sql/patch-master-db.sql | 8 -------- 1 file changed, 8 deletions(-) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 05fa2eed6..218593320 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -1,14 +1,6 @@ -- Patches a database that is using the master checkout of the -- swefreq.sql schema definition to the develop version. --- user_log.dataset_pk changes to user_log.dataset_version_pk --- 1. Insert new column user_log.dataset_version_pk --- 2. Add foreign constraints --- 3. Populate column user_log.dataset_version_pk --- 4. Update dependent views and tables --- 5. Drop old dataset_pk foreign constraint in user_log --- 6. Drop column user_log.dataset_pk - -- TODO: Rename user_log to user_access_log -- TODO: Create user_consent_log -- TODO: Create user_download_log From 3ea22d42480f8e3f5071738d53f425af09a4e094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Wed, 11 Oct 2017 11:11:55 +0200 Subject: [PATCH 18/37] Rename user_log --> user_access_log Involves recreating three views. --- sql/patch-master-db.sql | 69 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 218593320..5068af64a 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -1,7 +1,74 @@ -- Patches a database that is using the master checkout of the -- swefreq.sql schema definition to the develop version. --- TODO: Rename user_log to user_access_log +-- Rename user_log to user_access_log + +RENAME TABLE user_log TO user_access_log; +ALTER TABLE user_access_log + CHANGE user_log_pk + user_access_log_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT; + +DROP VIEW _user_log_summary; +CREATE OR REPLACE VIEW _user_access_log_summary AS + SELECT MAX(user_access_log_pk) AS user_access_log_pk, user_pk, + dataset_pk, action, MAX(ts) AS ts + FROM user_access_log + GROUP BY user_pk, dataset_pk, action; + +CREATE OR REPLACE VIEW dataset_access_current AS + SELECT DISTINCT + access.*, + TRUE AS has_access, + request.ts AS access_requested + FROM dataset_access AS access + JOIN ( SELECT user_pk, dataset_pk, MAX(ts) AS ts + FROM user_access_log WHERE action = "access_requested" + GROUP BY user_pk, dataset_pk ) AS request + ON access.user_pk = request.user_pk AND + access.dataset_pk = request.dataset_pk + WHERE (access.user_pk, access.dataset_pk) IN ( + -- gets user_pk for all users with current access + -- from https://stackoverflow.com/a/39190423/4941495 + SELECT granted.user_pk, granted.dataset_pk + FROM _user_access_log_summary AS granted + LEFT JOIN _user_access_log_summary AS revoked + ON granted.user_pk = revoked.user_pk AND + granted.dataset_pk = revoked.dataset_pk AND + revoked.action = 'access_revoked' + WHERE granted.action = 'access_granted' AND + (revoked.user_pk IS NULL OR granted.ts > revoked.ts) + GROUP BY granted.user_pk, granted.dataset_pk, granted.action + ); + +CREATE OR REPLACE VIEW dataset_access_pending AS + SELECT DISTINCT + access.*, + FALSE AS has_access, + request.ts AS access_requested + FROM dataset_access AS access + JOIN ( SELECT user_pk, dataset_pk, MAX(ts) AS ts + FROM user_access_log WHERE action = "access_requested" + GROUP BY user_pk, dataset_pk ) AS request + ON access.user_pk = request.user_pk AND + access.dataset_pk = request.dataset_pk + WHERE (access.user_pk, access.dataset_pk) IN ( + -- get user_pk for all users that have pending access requests + SELECT requested.user_pk, requested.dataset_pk + FROM _user_access_log_summary AS requested + LEFT JOIN _user_access_log_summary AS granted + ON requested.user_pk = granted.user_pk AND + requested.dataset_pk = granted.dataset_pk AND + granted.action = 'access_granted' + LEFT JOIN _user_access_log_summary AS revoked + ON requested.user_pk = revoked.user_pk AND + requested.dataset_pk = revoked.dataset_pk AND + revoked.action = 'access_revoked' + WHERE requested.action = 'access_requested' AND + (granted.user_pk IS NULL OR requested.ts > granted.ts) AND + (revoked.user_pk IS NULL OR requested.ts > revoked.ts) + GROUP BY requested.user_pk, requested.dataset_pk, requested.action + ); + -- TODO: Create user_consent_log -- TODO: Create user_download_log -- TODO: Add unique constraint on linkhash.hash From 615a8c52ee321c1b410cbce6f2b1ca967d5bd740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Wed, 11 Oct 2017 12:06:49 +0200 Subject: [PATCH 19/37] Add user_consent_log and user_download_log --- sql/patch-master-db.sql | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 5068af64a..308fa6b4a 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -69,8 +69,31 @@ CREATE OR REPLACE VIEW dataset_access_pending AS GROUP BY requested.user_pk, requested.dataset_pk, requested.action ); --- TODO: Create user_consent_log --- TODO: Create user_download_log +-- Create user_consent_log + +CREATE TABLE IF NOT EXISTS user_consent_log ( + user_consent_log_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, + user_pk INTEGER NOT NULL, + dataset_version_pk INTEGER NOT NULL, + ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT FOREIGN KEY (user_pk) REFERENCES user(user_pk), + CONSTRAINT FOREIGN KEY (dataset_version_pk) + REFERENCES dataset_version(dataset_version_pk) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- Create user_download_log + +CREATE TABLE IF NOT EXISTS user_download_log ( + user_download_log_pk + INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, + user_pk INTEGER NOT NULL, + dataset_file_pk INTEGER NOT NULL, + ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT FOREIGN KEY (user_pk) REFERENCES user(user_pk), + CONSTRAINT FOREIGN KEY (dataset_file_pk) + REFERENCES dataset_file(dataset_file_pk) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + -- TODO: Add unique constraint on linkhash.hash -- TODO: Remove "consent" and "download" enums from dataset_access_log -- TODO: Remove has_concented from views From 7bcb37e61d642277fc4a8634fbdd157e727b32a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Wed, 11 Oct 2017 12:12:36 +0200 Subject: [PATCH 20/37] Add unique constraint on linkhash.hash --- sql/patch-master-db.sql | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 308fa6b4a..22d431408 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -94,6 +94,10 @@ CREATE TABLE IF NOT EXISTS user_download_log ( REFERENCES dataset_file(dataset_file_pk) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; --- TODO: Add unique constraint on linkhash.hash +-- Add unique constraint on linkhash.hash + +ALTER TABLE linkhash + ADD CONSTRAINT UNIQUE (hash); + -- TODO: Remove "consent" and "download" enums from dataset_access_log -- TODO: Remove has_concented from views From 8b8449736d292c3d69538b6eb48f591a82d362f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Wed, 11 Oct 2017 14:22:15 +0200 Subject: [PATCH 21/37] Insert data into user_consent_log --- sql/patch-master-db.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 22d431408..78bc55cc7 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -81,6 +81,17 @@ CREATE TABLE IF NOT EXISTS user_consent_log ( REFERENCES dataset_version(dataset_version_pk) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; +-- Insert data into user_consent_log. This is assuming that the dataset +-- that the user has consented to is the most current version of the +-- dataset. + +INSERT INTO user_consent_log (user_pk, dataset_version_pk, ts) + SELECT ul.user_pk, dvc.dataset_version_pk, ul.ts + FROM user_access_log AS ul + JOIN dataset_version_current AS dvc + ON (dvc.dataset_pk = ul.dataset_pk) + WHERE ul.action = 'consented'; + -- Create user_download_log CREATE TABLE IF NOT EXISTS user_download_log ( From 2506df920c87cbf6e181e3e77cd6b012953c154a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Wed, 11 Oct 2017 15:12:57 +0200 Subject: [PATCH 22/37] Insert data into user_download_log --- sql/patch-master-db.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 78bc55cc7..98830fbbf 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -105,6 +105,19 @@ CREATE TABLE IF NOT EXISTS user_download_log ( REFERENCES dataset_file(dataset_file_pk) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; +-- Insert data into user_download_log. This is assuming that the +-- dataset that the user has downloaded is the most current version of +-- the dataset. + +INSERT INTO user_download_log (user_pk, dataset_file_pk, ts) + SELECT ul.user_pk, df.dataset_file_pk, ul.ts + FROM user_access_log AS ul + JOIN dataset_version_current AS dvc + ON (dvc.dataset_pk = ul.dataset_pk) + JOIN dataset_file AS df + ON (df.dataset_version_pk = dvc.dataset_version_pk) + WHERE ul.action = 'download'; + -- Add unique constraint on linkhash.hash ALTER TABLE linkhash From 48952002aca9c62540dd300da6f7db27df610398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Wed, 11 Oct 2017 15:44:52 +0200 Subject: [PATCH 23/37] 'consented' --> 'consent' --- sql/patch-master-db.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 98830fbbf..307fab335 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -90,7 +90,7 @@ INSERT INTO user_consent_log (user_pk, dataset_version_pk, ts) FROM user_access_log AS ul JOIN dataset_version_current AS dvc ON (dvc.dataset_pk = ul.dataset_pk) - WHERE ul.action = 'consented'; + WHERE ul.action = 'consent'; -- Create user_download_log From 6d410b440d70fa4889c57852a6f4f869c14c17fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Wed, 11 Oct 2017 15:50:08 +0200 Subject: [PATCH 24/37] Remove "consent" and "download" enums from user_access_log --- sql/patch-master-db.sql | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 307fab335..24bf15320 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -121,7 +121,16 @@ INSERT INTO user_download_log (user_pk, dataset_file_pk, ts) -- Add unique constraint on linkhash.hash ALTER TABLE linkhash - ADD CONSTRAINT UNIQUE (hash); + ADD CONSTRAINT UNIQUE (hash); + +-- Remove "consent" and "download" enums from user_access_log + +DELETE FROM user_access_log + WHERE action IN ('concent', 'download'); + +ALTER TABLE user_access_log + CHANGE action + action ENUM ('access_requested','access_granted','access_revoked', + 'private_link'); --- TODO: Remove "consent" and "download" enums from dataset_access_log -- TODO: Remove has_concented from views From 4fab523120f7b5903a961382b5e8ae2616d04339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Thu, 12 Oct 2017 13:13:16 +0200 Subject: [PATCH 25/37] Removed a todo that was already done --- sql/patch-master-db.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 24bf15320..2796fb673 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -132,5 +132,3 @@ ALTER TABLE user_access_log CHANGE action action ENUM ('access_requested','access_granted','access_revoked', 'private_link'); - --- TODO: Remove has_concented from views From 9f48015516d34f09329452d69bf94cefae2ea3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Fri, 13 Oct 2017 10:03:47 +0200 Subject: [PATCH 26/37] Fix primary key renaming --- sql/patch-master-db.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index 2796fb673..c706adad8 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -6,7 +6,7 @@ RENAME TABLE user_log TO user_access_log; ALTER TABLE user_access_log CHANGE user_log_pk - user_access_log_pk INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT; + user_access_log_pk INTEGER; DROP VIEW _user_log_summary; CREATE OR REPLACE VIEW _user_access_log_summary AS From eba8a6ed7971bc6f556275c8b59e01583b7a08d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Fri, 13 Oct 2017 10:04:19 +0200 Subject: [PATCH 27/37] Fix misspelling --- sql/patch-master-db.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/patch-master-db.sql b/sql/patch-master-db.sql index c706adad8..241c33449 100644 --- a/sql/patch-master-db.sql +++ b/sql/patch-master-db.sql @@ -126,7 +126,7 @@ ALTER TABLE linkhash -- Remove "consent" and "download" enums from user_access_log DELETE FROM user_access_log - WHERE action IN ('concent', 'download'); + WHERE action IN ('consent', 'download'); ALTER TABLE user_access_log CHANGE action From 837abf34ac1566b8c740503a3a494b72aa15a380 Mon Sep 17 00:00:00 2001 From: Johan Viklund Date: Fri, 13 Oct 2017 12:50:38 +0000 Subject: [PATCH 28/37] Reorder db.py so classes are in the same order as in sql/swefreq.sql --- tornado/db.py | 176 +++++++++++++++++++++++++------------------------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/tornado/db.py b/tornado/db.py index eac9b3332..3d4294779 100644 --- a/tornado/db.py +++ b/tornado/db.py @@ -14,6 +14,54 @@ class Meta: database = database +class EnumField(Field): + db_field = 'string' # The same as for CharField + + def __init__(self, values=[], *args, **kwargs): + self.values = values + super().__init__(*args, **kwargs) + + def db_value(self, value): + if value not in self.values: + raise ValueError("Illegal value for '{}'".format(self.db_column)) + return value + + def python_value(self, value): + if value not in self.values: + raise ValueError("Illegal value for '{}'".format(self.db_column)) + return value + + +class User(BaseModel): + user = PrimaryKeyField(db_column='user_pk') + name = CharField(null=True) + email = CharField(unique=True) + affiliation = CharField(null=True) + country = CharField(null=True) + + def is_admin(self, dataset): + return DatasetAccess.select().where( + DatasetAccess.dataset == dataset, + DatasetAccess.user == self, + DatasetAccess.is_admin + ).count() + + def has_access(self, dataset): + return DatasetAccessCurrent.select().where( + DatasetAccessCurrent.dataset == dataset, + DatasetAccessCurrent.user == self, + ).count() + + def has_requested_access(self, dataset): + return DatasetAccessPending.select().where( + DatasetAccessPending.dataset == dataset, + DatasetAccessPending.user == self + ).count() + + class Meta: + db_table = 'user' + + class Study(BaseModel): study = PrimaryKeyField(db_column='study_pk') pi_name = CharField() @@ -29,15 +77,6 @@ class Meta: db_table = 'study' -class Collection(BaseModel): - collection = PrimaryKeyField(db_column = 'collection_pk') - name = CharField(null = True) - ethnicity = CharField(null = True) - - class Meta: - db_table = 'collection' - - class Dataset(BaseModel): dataset = PrimaryKeyField(db_column='dataset_pk') study = ForeignKeyField(db_column='study_pk', rel_model=Study, to_field='study', related_name='datasets') @@ -62,6 +101,29 @@ class Meta: db_table = 'dataset' +class DatasetVersion(BaseModel): + dataset_version = PrimaryKeyField(db_column='dataset_version_pk') + dataset = ForeignKeyField(db_column='dataset_pk', rel_model=Dataset, to_field='dataset', related_name='versions') + version = CharField() + description = TextField() + terms = TextField() + var_call_ref = CharField(null=True) + available_from = DateTimeField() + ref_doi = CharField(null=True) + + class Meta: + db_table = 'dataset_version' + + +class Collection(BaseModel): + collection = PrimaryKeyField(db_column = 'collection_pk') + name = CharField(null = True) + ethnicity = CharField(null = True) + + class Meta: + db_table = 'collection' + + class SampleSet(BaseModel): sample_set = PrimaryKeyField(db_column='sample_set_pk') dataset = ForeignKeyField(db_column='dataset_pk', rel_model=Dataset, to_field='dataset', related_name='sample_sets') @@ -73,34 +135,25 @@ class Meta: db_table = 'sample_set' -class User(BaseModel): - user = PrimaryKeyField(db_column='user_pk') - name = CharField(null=True) - email = CharField(unique=True) - affiliation = CharField(null=True) - country = CharField(null=True) +class DatasetFile(BaseModel): + dataset_file = PrimaryKeyField(db_column='dataset_file_pk') + dataset_version = ForeignKeyField(db_column='dataset_version_pk', rel_model=DatasetVersion, to_field='dataset_version', related_name='files') + name = CharField() + uri = CharField() - def is_admin(self, dataset): - return DatasetAccess.select().where( - DatasetAccess.dataset == dataset, - DatasetAccess.user == self, - DatasetAccess.is_admin - ).count() + class Meta: + db_table = 'dataset_file' - def has_access(self, dataset): - return DatasetAccessCurrent.select().where( - DatasetAccessCurrent.dataset == dataset, - DatasetAccessCurrent.user == self, - ).count() - def has_requested_access(self, dataset): - return DatasetAccessPending.select().where( - DatasetAccessPending.dataset == dataset, - DatasetAccessPending.user == self - ).count() +class UserLog(BaseModel): + user_log = PrimaryKeyField(db_column='user_log_pk') + user = ForeignKeyField(db_column='user_pk', rel_model=User, to_field='user', related_name='logs') + dataset = ForeignKeyField(db_column='dataset_pk', rel_model=Dataset, to_field='dataset', related_name='logs') + action = EnumField(null=True, values=['consent','download','access_requested','access_granted','access_revoked','private_link']) + ts = DateTimeField() class Meta: - db_table = 'user' + db_table = 'user_log' class DatasetAccess(BaseModel): @@ -139,37 +192,6 @@ class Meta: db_table = 'dataset_access_pending' -class DatasetVersion(BaseModel): - dataset_version = PrimaryKeyField(db_column='dataset_version_pk') - dataset = ForeignKeyField(db_column='dataset_pk', rel_model=Dataset, to_field='dataset', related_name='versions') - version = CharField() - description = TextField() - terms = TextField() - var_call_ref = CharField(null=True) - available_from = DateTimeField() - ref_doi = CharField(null=True) - - class Meta: - db_table = 'dataset_version' - - -class DatasetVersionCurrent(DatasetVersion): - dataset = ForeignKeyField(db_column='dataset_pk', rel_model=Dataset, to_field='dataset', related_name='current_version') - - class Meta: - db_table = 'dataset_version_current' - - -class DatasetFile(BaseModel): - dataset_file = PrimaryKeyField(db_column='dataset_file_pk') - dataset_version = ForeignKeyField(db_column='dataset_version_pk', rel_model=DatasetVersion, to_field='dataset_version', related_name='files') - name = CharField() - uri = CharField() - - class Meta: - db_table = 'dataset_file' - - class DatasetLogo(BaseModel): dataset_logo = PrimaryKeyField(db_column='dataset_logo_pk') dataset = ForeignKeyField(db_column='dataset_pk', rel_model=Dataset, to_field='dataset', related_name='logo') @@ -191,33 +213,11 @@ class Meta: db_table = 'linkhash' -class EnumField(Field): - db_field = 'string' # The same as for CharField - - def __init__(self, values=[], *args, **kwargs): - self.values = values - super().__init__(*args, **kwargs) - - def db_value(self, value): - if value not in self.values: - raise ValueError("Illegal value for '{}'".format(self.db_column)) - return value - - def python_value(self, value): - if value not in self.values: - raise ValueError("Illegal value for '{}'".format(self.db_column)) - return value - - -class UserLog(BaseModel): - user_log = PrimaryKeyField(db_column='user_log_pk') - user = ForeignKeyField(db_column='user_pk', rel_model=User, to_field='user', related_name='logs') - dataset = ForeignKeyField(db_column='dataset_pk', rel_model=Dataset, to_field='dataset', related_name='logs') - action = EnumField(null=True, values=['consent','download','access_requested','access_granted','access_revoked','private_link']) - ts = DateTimeField() +class DatasetVersionCurrent(DatasetVersion): + dataset = ForeignKeyField(db_column='dataset_pk', rel_model=Dataset, to_field='dataset', related_name='current_version') class Meta: - db_table = 'user_log' + db_table = 'dataset_version_current' def get_dataset(dataset): From cadb2b206178cd95123e97d255fc7fdd3dd7f93c Mon Sep 17 00:00:00 2001 From: Johan Viklund Date: Fri, 13 Oct 2017 14:00:46 +0000 Subject: [PATCH 29/37] Added new log tables and updated views --- tornado/db.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/tornado/db.py b/tornado/db.py index 3d4294779..6ae365694 100644 --- a/tornado/db.py +++ b/tornado/db.py @@ -145,15 +145,35 @@ class Meta: db_table = 'dataset_file' -class UserLog(BaseModel): - user_log = PrimaryKeyField(db_column='user_log_pk') - user = ForeignKeyField(db_column='user_pk', rel_model=User, to_field='user', related_name='logs') - dataset = ForeignKeyField(db_column='dataset_pk', rel_model=Dataset, to_field='dataset', related_name='logs') - action = EnumField(null=True, values=['consent','download','access_requested','access_granted','access_revoked','private_link']) - ts = DateTimeField() +class UserAccessLog(BaseModel): + user_access_log = PrimaryKeyField(db_column='user_access_log_pk') + user = ForeignKeyField(db_column='user_pk', rel_model=User, to_field='user', related_name='access_logs') + dataset = ForeignKeyField(db_column='dataset_pk', rel_model=Dataset, to_field='dataset', related_name='access_logs') + action = EnumField(null=True, values=['access_requested','access_granted','access_revoked','private_link']) + ts = DateTimeField() class Meta: - db_table = 'user_log' + db_table = 'user_access_log' + + +class UserConsentLog(BaseModel): + user_consent_log = PrimaryKeyField(db_column='user_access_log_pk') + user = ForeignKeyField(db_column='user_pk', rel_model=User, to_field='user', related_name='consent_logs') + dataset_version = ForeignKeyField(db_column='dataset_pk', rel_model=DatasetVersion, to_field='dataset_version', related_name='consent_logs') + ts = DateTimeField() + + class Meta: + db_table = 'user_consent_log' + + +class UserDownloadLog(BaseModel): + user_download_log = PrimaryKeyField(db_column='user_download_log_pk') + user = ForeignKeyField(db_column='user_pk', rel_model=User, to_field='user', related_name='download_logs') + dataset_file = ForeignKeyField(db_column='dataset_pk', rel_model=DatasetVersion, to_field='dataset_version', related_name='download_logs') + ts = DateTimeField() + + class Meta: + db_table = 'user_consent_log' class DatasetAccess(BaseModel): @@ -173,7 +193,6 @@ class Meta: class DatasetAccessCurrent(DatasetAccess): dataset = ForeignKeyField(db_column='dataset_pk', rel_model=Dataset, to_field='dataset', related_name='access_current') user = ForeignKeyField(db_column='user_pk', rel_model=User, to_field='user', related_name='access_current') - has_consented = IntegerField() has_access = IntegerField() access_requested = DateTimeField() @@ -184,7 +203,6 @@ class Meta: class DatasetAccessPending(DatasetAccess): dataset = ForeignKeyField(db_column='dataset_pk', rel_model=Dataset, to_field='dataset', related_name='access_pending') user = ForeignKeyField(db_column='user_pk', rel_model=User, to_field='user', related_name='access_pending') - has_consented = IntegerField() has_access = IntegerField() access_requested = DateTimeField() From c198d94f3571b206c9fbcfa178ba10e174950759 Mon Sep 17 00:00:00 2001 From: Johan Viklund Date: Fri, 13 Oct 2017 14:01:56 +0000 Subject: [PATCH 30/37] Removed index spec, only useful for generating tables IIUC --- tornado/db.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tornado/db.py b/tornado/db.py index 6ae365694..5b38bcba1 100644 --- a/tornado/db.py +++ b/tornado/db.py @@ -185,9 +185,6 @@ class DatasetAccess(BaseModel): class Meta: db_table = 'dataset_access' - indexes = ( - (('dataset_pk', 'user_pk'), True), - ) class DatasetAccessCurrent(DatasetAccess): From 93b2e755959b87756e13865469b384161af6a570 Mon Sep 17 00:00:00 2001 From: Johan Viklund Date: Fri, 13 Oct 2017 14:41:44 +0000 Subject: [PATCH 31/37] Need to reference the correct tables and columns in new logs --- tornado/db.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tornado/db.py b/tornado/db.py index 5b38bcba1..00ed67501 100644 --- a/tornado/db.py +++ b/tornado/db.py @@ -159,7 +159,7 @@ class Meta: class UserConsentLog(BaseModel): user_consent_log = PrimaryKeyField(db_column='user_access_log_pk') user = ForeignKeyField(db_column='user_pk', rel_model=User, to_field='user', related_name='consent_logs') - dataset_version = ForeignKeyField(db_column='dataset_pk', rel_model=DatasetVersion, to_field='dataset_version', related_name='consent_logs') + dataset_version = ForeignKeyField(db_column='dataset_version_pk', rel_model=DatasetVersion, to_field='dataset_version', related_name='consent_logs') ts = DateTimeField() class Meta: @@ -169,11 +169,11 @@ class Meta: class UserDownloadLog(BaseModel): user_download_log = PrimaryKeyField(db_column='user_download_log_pk') user = ForeignKeyField(db_column='user_pk', rel_model=User, to_field='user', related_name='download_logs') - dataset_file = ForeignKeyField(db_column='dataset_pk', rel_model=DatasetVersion, to_field='dataset_version', related_name='download_logs') + dataset_file = ForeignKeyField(db_column='dataset_file_pk', rel_model=DatasetFile, to_field='dataset_file', related_name='download_logs') ts = DateTimeField() class Meta: - db_table = 'user_consent_log' + db_table = 'user_download_log' class DatasetAccess(BaseModel): From 4cc675fae2e8f3a0bb7429089db2f741e7fb26a4 Mon Sep 17 00:00:00 2001 From: Johan Viklund Date: Fri, 13 Oct 2017 14:43:42 +0000 Subject: [PATCH 32/37] UserAccessLog instead of UserLog --- tornado/application.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tornado/application.py b/tornado/application.py index 8e9d9b0a6..bff178109 100644 --- a/tornado/application.py +++ b/tornado/application.py @@ -299,7 +299,7 @@ def post(self, dataset, *args, **kwargs): ) da.wants_newsletter = newsletter da.save() - db.UserLog.create( + db.UserAccessLog.create( user = user, dataset = dataset, action = 'access_requested' @@ -337,7 +337,7 @@ def post(self, dataset, email): da.has_access = True da.save() - db.UserLog.create( + db.UserAccessLog.create( user = user, dataset = dataset, action = 'access_granted' @@ -365,7 +365,7 @@ def post(self, dataset, email): dataset = db.get_dataset(dataset) user = db.User.select().where(db.User.email == email).get() - db.UserLog.create( + db.UserAccessLog.create( user = user, dataset = dataset, action = 'access_revoked' From 1f01ba72199b1a81787d165e7d07336d4d5333cd Mon Sep 17 00:00:00 2001 From: Johan Viklund Date: Fri, 13 Oct 2017 14:45:53 +0000 Subject: [PATCH 33/37] Log consent to datasetversion instead --- tornado/application.py | 14 ++++++++------ tornado/route.py | 2 +- tornado/static/js/app.js | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tornado/application.py b/tornado/application.py index bff178109..425b3d98e 100644 --- a/tornado/application.py +++ b/tornado/application.py @@ -309,15 +309,17 @@ def post(self, dataset, *args, **kwargs): class LogEvent(handlers.SafeHandler): - def post(self, dataset, event): + def post(self, dataset, event, target): user = self.current_user - ok_events = ['download','consent'] - if event in ok_events: - db.UserLog.create( + if event == 'consent': + dv = (db.DatasetVersion + .select() + .where(db.DatasetVersion.version==target) + .get()) + db.UserConsentLog.create( user = user, - dataset = db.get_dataset(dataset), - action = event + dataset_version = dv, ) else: raise tornado.web.HTTPError(400, reason="Can't log that") diff --git a/tornado/route.py b/tornado/route.py index d7b867cef..4aa7a3bdb 100644 --- a/tornado/route.py +++ b/tornado/route.py @@ -52,7 +52,7 @@ def __init__(self, settings): ### Dataset Api ("/api/datasets", application.ListDatasets), ("/api/datasets/(?P[^\/]+)", application.GetDataset), - ("/api/datasets/(?P[^\/]+)/log/(?P[^\/]+)", application.LogEvent), + ("/api/datasets/(?P[^\/]+)/log/(?P[^\/]+)/(?P[^\/]+)", application.LogEvent), ("/api/datasets/(?P[^\/]+)/logo", application.ServeLogo), ("/api/datasets/(?P[^\/]+)/files", application.DatasetFiles), ("/api/datasets/(?P[^\/]+)/collection", application.Collection), diff --git a/tornado/static/js/app.js b/tornado/static/js/app.js index a564963c7..b2c87a260 100644 --- a/tornado/static/js/app.js +++ b/tornado/static/js/app.js @@ -78,8 +78,8 @@ var service = {}; $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded"; - service.consent = function(dataset) { - return $http.post('/api/datasets/' + dataset + '/log/consent', + service.consent = function(dataset, version) { + return $http.post('/api/datasets/' + dataset + '/log/consent/' + version, $.param({'_xsrf': $cookies.get('_xsrf')}) ); }; @@ -366,7 +366,7 @@ localThis.consented = function(){ if (!has_already_logged){ has_already_logged = true; - Log.consent(dataset); + Log.consent(dataset, localThis.dataset.version.version); } }; From bfe4b067237cece494d5f02a7e5974cee544413d Mon Sep 17 00:00:00 2001 From: Johan Viklund Date: Fri, 13 Oct 2017 14:46:14 +0000 Subject: [PATCH 34/37] Spell Handler correctly --- tornado/handlers.py | 2 +- tornado/route.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tornado/handlers.py b/tornado/handlers.py index 278df343f..fc94b5370 100644 --- a/tornado/handlers.py +++ b/tornado/handlers.py @@ -170,7 +170,7 @@ class SafeStaticFileHandler(tornado.web.StaticFileHandler, SafeHandler): """ pass -class AuthorizedStaticNginxFileHanlder(AuthorizedHandler): +class AuthorizedStaticNginxFileHandler(AuthorizedHandler): """ Serve static files for authenticated users from the nginx frontend Requires a ``path`` argument in constructor which should be the root of diff --git a/tornado/route.py b/tornado/route.py index 4aa7a3bdb..16b1b8aae 100644 --- a/tornado/route.py +++ b/tornado/route.py @@ -41,7 +41,7 @@ def __init__(self, settings): {"path": "static/"}), (r'/(favicon.ico)', tornado.web.StaticFileHandler, {"path": "static/img/"}), - (r"/release/(?P[^\/]+)/(?P.*)", handlers.AuthorizedStaticNginxFileHanlder, + (r"/release/(?P[^\/]+)/(?P.*)", handlers.AuthorizedStaticNginxFileHandler, {"path": "/release-files/"}), ## Authentication ("/login", handlers.LoginHandler), From 6a4c48bc65bc638112ed2a636d1170058432ed52 Mon Sep 17 00:00:00 2001 From: Johan Viklund Date: Fri, 13 Oct 2017 14:46:40 +0000 Subject: [PATCH 35/37] Log download in the backend instead --- tornado/handlers.py | 10 ++++++++++ tornado/static/js/app.js | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tornado/handlers.py b/tornado/handlers.py index fc94b5370..908773fd3 100644 --- a/tornado/handlers.py +++ b/tornado/handlers.py @@ -188,6 +188,16 @@ def initialize(self, path): self.root = path def get(self, dataset, file): + user = self.current_user + dbfile = (db.DatasetFile + .select() + .where(db.DatasetFile.name == file) + .get()) + db.UserDownloadLog.create( + user = user, + dataset_file = dbfile + ) + abspath = os.path.abspath(os.path.join(self.root, file)) self.set_header("X-Accel-Redirect", abspath) self.set_header("Content-Disposition", "attachment") diff --git a/tornado/static/js/app.js b/tornado/static/js/app.js index b2c87a260..c0e909761 100644 --- a/tornado/static/js/app.js +++ b/tornado/static/js/app.js @@ -83,12 +83,6 @@ $.param({'_xsrf': $cookies.get('_xsrf')}) ); }; - service.download = function(dataset) { - return $http.post( - '/api/datasets/' + dataset + '/log/download', - $.param({'_xsrf': $cookies.get('_xsrf')}) - ); - }; return service; }); @@ -369,10 +363,6 @@ Log.consent(dataset, localThis.dataset.version.version); } }; - - localThis.downloadData = function(){ - Log.download(dataset); - }; }]); ///////////////////////////////////////////////////////////////////////////////////// From 1a31ed7498da037cfed8b68da48175a462b0b266 Mon Sep 17 00:00:00 2001 From: Johan Viklund Date: Mon, 16 Oct 2017 14:11:52 +0200 Subject: [PATCH 36/37] Create LICENSE --- LICENSE | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 674 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..9cecc1d46 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. From ee2428c9da371b8b207f371e3ff5f39db179558c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=28Kusalananda=29=20K=C3=A4h=C3=A4ri?= Date: Tue, 17 Oct 2017 12:10:03 +0200 Subject: [PATCH 37/37] Use --complete-insert when creating the database dumps --- scripts/backup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 752d1566d..e053276f9 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -33,7 +33,7 @@ tmpbackup="$( mktemp -p "$userdb_base" )" # Dump database, and remove the "Dump completed" comment at the end to # be able to compare with previous dump. lxc exec swefreq-web -- \ -mysqldump --user=swefreq --host=swefreq-db swefreq | +mysqldump --complete-insert --user=swefreq --host=swefreq-db swefreq | sed '/^-- Dump completed on/d' >"$tmpbackup" gzip --best "$tmpbackup"