From f441d4910dc6eef1f9d419a4d834ff97622207d6 Mon Sep 17 00:00:00 2001 From: Martin McCallion Date: Mon, 18 Mar 2019 11:32:14 +0000 Subject: [PATCH 01/11] Store the user name as lower case for compatibility with Postgres. --- installer/install.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installer/install.py b/installer/install.py index 12c962571..06e160c13 100755 --- a/installer/install.py +++ b/installer/install.py @@ -251,10 +251,10 @@ def get_settings(): # Database name is hardcoded for now. # settings.db_name = get_value_from_user(DATABASE_NAME).strip() settings.db_name = "sahsuland" - settings.db_user = get_value_from_user(DATABASE_USER, - extra=settings.db_name).strip() + settings.db_user = get_value_from_user( + DATABASE_USER, extra=settings.db_name).strip().lower() settings.db_pass = get_password_from_user( - DATABASE_PASSWORD, extra=settings.db_user).strip() + DATABASE_PASSWORD, extra=settings.db_user) # For now the next few are only for Postgres if settings.db_type == "pg": From 01cc44448c2687bfcda20c3b1dfd04d81b8c2b13 Mon Sep 17 00:00:00 2001 From: Martin McCallion Date: Mon, 18 Mar 2019 11:35:14 +0000 Subject: [PATCH 02/11] Remove a 'use sahsuland' that is being called before that database is created. --- .../rif40/table_triggers/t_rif40_inv_covariates_trigger.sql | 3 --- 1 file changed, 3 deletions(-) diff --git a/rifDatabase/SQLserver/sahsuland_dev/rif40/table_triggers/t_rif40_inv_covariates_trigger.sql b/rifDatabase/SQLserver/sahsuland_dev/rif40/table_triggers/t_rif40_inv_covariates_trigger.sql index b83a6755c..07235c9da 100644 --- a/rifDatabase/SQLserver/sahsuland_dev/rif40/table_triggers/t_rif40_inv_covariates_trigger.sql +++ b/rifDatabase/SQLserver/sahsuland_dev/rif40/table_triggers/t_rif40_inv_covariates_trigger.sql @@ -17,9 +17,6 @@ names of geolevels */ -USE [sahsuland] -GO - /****** Object: Trigger [tr_inv_covariate] Script Date: 13/02/2019 11:47:17 ******/ DROP TRIGGER [rif40].[tr_inv_covariate] GO From 4120b0a1ac5ca19d58f8d154e956bea5c21d10a5 Mon Sep 17 00:00:00 2001 From: Martin McCallion Date: Mon, 18 Mar 2019 11:37:57 +0000 Subject: [PATCH 03/11] Condition dropping trigger on it existing in the first place. --- .../table_triggers/t_rif40_inv_covariates_trigger.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rifDatabase/SQLserver/sahsuland_dev/rif40/table_triggers/t_rif40_inv_covariates_trigger.sql b/rifDatabase/SQLserver/sahsuland_dev/rif40/table_triggers/t_rif40_inv_covariates_trigger.sql index 07235c9da..a9db49b2b 100644 --- a/rifDatabase/SQLserver/sahsuland_dev/rif40/table_triggers/t_rif40_inv_covariates_trigger.sql +++ b/rifDatabase/SQLserver/sahsuland_dev/rif40/table_triggers/t_rif40_inv_covariates_trigger.sql @@ -18,7 +18,13 @@ names of geolevels /****** Object: Trigger [tr_inv_covariate] Script Date: 13/02/2019 11:47:17 ******/ -DROP TRIGGER [rif40].[tr_inv_covariate] +IF EXISTS (SELECT * FROM sys.triggers tr + INNER JOIN sys.tables t ON tr.parent_id = t.object_id + WHERE t.schema_id = SCHEMA_ID(N'rif40') + and tr.name=N'tr_inv_covariate') +BEGIN + DROP TRIGGER [rif40].[tr_inv_covariate] +END GO /****** Object: Trigger [rif40].[tr_inv_covariate] Script Date: 13/02/2019 11:47:17 ******/ From 99223da3b9815cba8fcdb2b098e0690eb0e833a6 Mon Sep 17 00:00:00 2001 From: Martin McCallion Date: Mon, 18 Mar 2019 11:49:34 +0000 Subject: [PATCH 04/11] Remove trigger creation; they refer to columns not yet created, and scripts are run in alter_12. --- .../SQLserver/installation/rif40_sahsuland_dev_install.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/rifDatabase/SQLserver/installation/rif40_sahsuland_dev_install.sql b/rifDatabase/SQLserver/installation/rif40_sahsuland_dev_install.sql index f03671767..a68fde718 100644 --- a/rifDatabase/SQLserver/installation/rif40_sahsuland_dev_install.sql +++ b/rifDatabase/SQLserver/installation/rif40_sahsuland_dev_install.sql @@ -89,8 +89,6 @@ GO :r ..\sahsuland_dev\rif40\functions\recreate_all_functions.sql :r ..\sahsuland_dev\rif40\views\recreate_all_views.sql :r ..\sahsuland_dev\error_handling\recreate_error_handling_sahsuland_dev.sql -:r ..\sahsuland_dev\rif40\table_triggers\recreate_table_triggers.sql -:r ..\sahsuland_dev\rif40\view_triggers\recreate_view_triggers.sql :r rif40_import_sahsuland.sql PRINT 'All done: RIF40 create sahsuland_dev database objects and install data.'; From f6ece69e30aa2ec0877f4c7d44b82dd3a55a44e9 Mon Sep 17 00:00:00 2001 From: Martin McCallion Date: Mon, 18 Mar 2019 12:16:14 +0000 Subject: [PATCH 05/11] Revert "Remove trigger creation; they refer to columns not yet created, and scripts are run in alter_12." This reverts commit 99223da3b9815cba8fcdb2b098e0690eb0e833a6. --- .../SQLserver/installation/rif40_sahsuland_dev_install.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rifDatabase/SQLserver/installation/rif40_sahsuland_dev_install.sql b/rifDatabase/SQLserver/installation/rif40_sahsuland_dev_install.sql index a68fde718..f03671767 100644 --- a/rifDatabase/SQLserver/installation/rif40_sahsuland_dev_install.sql +++ b/rifDatabase/SQLserver/installation/rif40_sahsuland_dev_install.sql @@ -89,6 +89,8 @@ GO :r ..\sahsuland_dev\rif40\functions\recreate_all_functions.sql :r ..\sahsuland_dev\rif40\views\recreate_all_views.sql :r ..\sahsuland_dev\error_handling\recreate_error_handling_sahsuland_dev.sql +:r ..\sahsuland_dev\rif40\table_triggers\recreate_table_triggers.sql +:r ..\sahsuland_dev\rif40\view_triggers\recreate_view_triggers.sql :r rif40_import_sahsuland.sql PRINT 'All done: RIF40 create sahsuland_dev database objects and install data.'; From 70995bbda9930d04fceb0dfce4ff818fc9f18ae0 Mon Sep 17 00:00:00 2001 From: Martin McCallion Date: Mon, 18 Mar 2019 12:45:45 +0000 Subject: [PATCH 06/11] Remove covariate_type from original trigger creation, and add new script to call from alter_12. --- .../rif40_inv_covariates_trigger.sql | 175 ++++++++++++++++++ .../SQLserver/alter scripts/v4_0_alter_12.sql | 4 +- .../rif40_inv_covariates_trigger.sql | 4 - 3 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 rifDatabase/SQLserver/alter scripts/rif40_inv_covariates_trigger.sql diff --git a/rifDatabase/SQLserver/alter scripts/rif40_inv_covariates_trigger.sql b/rifDatabase/SQLserver/alter scripts/rif40_inv_covariates_trigger.sql new file mode 100644 index 000000000..5179f2488 --- /dev/null +++ b/rifDatabase/SQLserver/alter scripts/rif40_inv_covariates_trigger.sql @@ -0,0 +1,175 @@ + +IF EXISTS (SELECT * FROM sys.triggers tr +INNER JOIN sys.views t ON tr.parent_id = t.object_id +WHERE t.schema_id = SCHEMA_ID(N'rif40') +and tr.name=N'tr_rif40_inv_covariates') +BEGIN + DROP TRIGGER [rif40].[tr_rif40_inv_covariates]; +END +GO + + +------------------------------ +-- create trigger code +------------------------------ +CREATE trigger [rif40].[tr_rif40_inv_covariates] +on [rif40].[rif40_inv_covariates] +instead of insert , update , delete +as +BEGIN +-------------------------------------- +--to Determine the type of transaction +--------------------------------------- +DECLARE @XTYPE varchar(1); +IF EXISTS (SELECT * FROM DELETED) + SET @XTYPE = 'D'; + +IF EXISTS (SELECT * FROM INSERTED) +BEGIN + IF (@XTYPE = 'D') + SET @XTYPE = 'U' + ELSE + SET @XTYPE = 'I' +END; + +IF @XTYPE='I' +BEGIN +-- +-- Check (USER = NEW.username OR NULL) and USER is a RIF user; if OK INSERT +-- + DECLARE @insert_invalid_user VARCHAR(MAX) = + ( + select SUSER_SNAME() AS username + from inserted + where NOT (username = SUSER_SNAME() OR username is null) + OR NOT ([rif40].[rif40_has_role](SUSER_SNAME(),'rif_user') = 1 + AND [rif40].[rif40_has_role](SUSER_SNAME(),'rif_manager') = 1) + ); + + IF @insert_invalid_user IS NOT NULL + BEGIN TRY + rollback; + DECLARE @err_msg1 VARCHAR(MAX) = formatmessage(51119, @insert_invalid_user); + THROW 51119, @err_msg1, 1; + END TRY + BEGIN CATCH + EXEC [rif40].[ErrorLog_proc] @Error_Location='[rif40].[rif40_inv_covariates]'; + THROW 51119, @err_msg1, 1; + END CATCH; + + INSERT INTO [rif40].[t_rif40_inv_covariates] ( + username, + study_id, + inv_id, + covariate_name, + covariate_type, + [min], + [max], + geography, + study_geolevel_name) + SELECT + isnull(username,SUSER_SNAME()), + isnull(study_id,[rif40].[rif40_sequence_current_value]('rif40.rif40_study_id_seq')), + isnull(inv_id,[rif40].[rif40_sequence_current_value]('rif40.rif40_inv_id_seq')), + covariate_name /* no default value */, + isnull(covariate_type, 'N'), + [min] /* no default value */, + [max] /* no default value */, + geography /* no default value */, + study_geolevel_name /* no default value */ + FROM inserted; + +END; + +IF @XTYPE='U' +BEGIN +-- +-- Check USER = OLD.username and NEW.username = OLD.username; if OK UPDATE +-- + DECLARE @update_invalid_user VARCHAR(MAX) = + ( + select a.username as 'old_username', b.username as 'new_username', SUSER_SNAME() as 'current_user' + from deleted a + left outer join inserted b on a.study_id=b.study_id AND a.inv_id=b.inv_id AND a.covariate_name=b.covariate_name + where a.username != SUSER_SNAME() + or (b.username is not null and a.username != b.username) + FOR XML PATH ('') + ); + IF @update_invalid_user IS NOT NULL + BEGIN TRY + rollback; + DECLARE @err_msg2 VARCHAR(MAX) = formatmessage(51120, @update_invalid_user); + THROW 51120, @err_msg2, 1; + END TRY + BEGIN CATCH + EXEC [rif40].[ErrorLog_proc] @Error_Location='[rif40].[rif40_inv_covariates]'; + THROW 51120, @err_msg2, 1; + END CATCH; + + DELETE FROM [rif40].[t_rif40_inv_covariates] + WHERE EXISTS ( + SELECT 1 + FROM deleted b + WHERE b.study_id=[rif40].[t_rif40_inv_covariates].study_id + AND b.inv_id=[rif40].[t_rif40_inv_covariates].inv_id + AND b.covariate_name=[rif40].[t_rif40_inv_covariates].covariate_name); + + INSERT INTO [rif40].[t_rif40_inv_covariates] ( + username, + study_id, + inv_id, + covariate_name, + covariate_type, + [min], + [max], + geography, + study_geolevel_name) + SELECT + username, + study_id, + inv_id, + covariate_name, + covariate_type, + [min], + [max], + geography, + study_geolevel_name + FROM inserted; + +END; + +IF @XTYPE='D' +BEGIN +-- +-- Check USER = OLD.username; if OK DELETE +-- + DECLARE @delete_invalid_user VARCHAR(MAX) = + ( + select username + from deleted + where username != SUSER_SNAME() + FOR XML PATH('') + ); + IF @delete_invalid_user IS NOT NULL + BEGIN TRY + rollback; + DECLARE @err_msg3 VARCHAR(MAX) = formatmessage(51121, @delete_invalid_user); + THROW 51121, @err_msg3, 1; + END TRY + BEGIN CATCH + EXEC [rif40].[ErrorLog_proc] @Error_Location='[rif40].[rif40_inv_covariates]'; + THROW 51121, @err_msg3, 1; + END CATCH; + + DELETE FROM [rif40].[t_rif40_inv_covariates] + WHERE EXISTS ( + SELECT 1 + FROM deleted b + WHERE b.study_id=[rif40].[t_rif40_inv_covariates].study_id + AND b.inv_id=[rif40].[t_rif40_inv_covariates].inv_id + AND b.covariate_name=[rif40].[t_rif40_inv_covariates].covariate_name); + +END; + +END; +GO diff --git a/rifDatabase/SQLserver/alter scripts/v4_0_alter_12.sql b/rifDatabase/SQLserver/alter scripts/v4_0_alter_12.sql index b1dc18f89..018c55ead 100644 --- a/rifDatabase/SQLserver/alter scripts/v4_0_alter_12.sql +++ b/rifDatabase/SQLserver/alter scripts/v4_0_alter_12.sql @@ -182,7 +182,7 @@ GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Study area geolevel name. Must be a valid GEOLEVEL_NAME for the study GEOGRPAHY in T_RIF40_GEOLEVELS. Cannot be changed by the user; present to allow a foreign key to be enforced.', @level0type=N'SCHEMA',@level0name=N'rif40', @level1type=N'VIEW',@level1name=N'rif40_inv_covariates', @level2type=N'COLUMN',@level2name=N'study_geolevel_name' GO -:r ..\sahsuland_dev\rif40\view_triggers\rif40_inv_covariates_trigger.sql +:r rif40_inv_covariates_trigger.sql SELECT geography, covariate_name, covariate_type, COUNT(*) AS total FROM rif40.t_rif40_inv_covariates @@ -205,4 +205,4 @@ COMMIT TRANSACTION; GO -- --- Eof \ No newline at end of file +-- Eof diff --git a/rifDatabase/SQLserver/sahsuland_dev/rif40/view_triggers/rif40_inv_covariates_trigger.sql b/rifDatabase/SQLserver/sahsuland_dev/rif40/view_triggers/rif40_inv_covariates_trigger.sql index 5179f2488..db20a60e8 100644 --- a/rifDatabase/SQLserver/sahsuland_dev/rif40/view_triggers/rif40_inv_covariates_trigger.sql +++ b/rifDatabase/SQLserver/sahsuland_dev/rif40/view_triggers/rif40_inv_covariates_trigger.sql @@ -62,7 +62,6 @@ BEGIN study_id, inv_id, covariate_name, - covariate_type, [min], [max], geography, @@ -72,7 +71,6 @@ BEGIN isnull(study_id,[rif40].[rif40_sequence_current_value]('rif40.rif40_study_id_seq')), isnull(inv_id,[rif40].[rif40_sequence_current_value]('rif40.rif40_inv_id_seq')), covariate_name /* no default value */, - isnull(covariate_type, 'N'), [min] /* no default value */, [max] /* no default value */, geography /* no default value */, @@ -119,7 +117,6 @@ BEGIN study_id, inv_id, covariate_name, - covariate_type, [min], [max], geography, @@ -129,7 +126,6 @@ BEGIN study_id, inv_id, covariate_name, - covariate_type, [min], [max], geography, From 695347dfd55c75e00d536570953706950ed86912 Mon Sep 17 00:00:00 2001 From: Martin McCallion Date: Tue, 19 Mar 2019 10:01:21 +0000 Subject: [PATCH 07/11] Remove various new fields from original study areas trigger creation, and add new script to call from alter_12. --- .../rif40_study_areas_trigger.sql | 167 ++++++++++++++++++ .../SQLserver/alter scripts/v4_0_alter_12.sql | 2 +- .../rif40_study_areas_trigger.sql | 24 +-- 3 files changed, 172 insertions(+), 21 deletions(-) create mode 100644 rifDatabase/SQLserver/alter scripts/rif40_study_areas_trigger.sql diff --git a/rifDatabase/SQLserver/alter scripts/rif40_study_areas_trigger.sql b/rifDatabase/SQLserver/alter scripts/rif40_study_areas_trigger.sql new file mode 100644 index 000000000..75a78fa46 --- /dev/null +++ b/rifDatabase/SQLserver/alter scripts/rif40_study_areas_trigger.sql @@ -0,0 +1,167 @@ + +IF EXISTS (SELECT * FROM sys.triggers tr +INNER JOIN sys.views t ON tr.parent_id = t.object_id +WHERE t.schema_id = SCHEMA_ID(N'rif40') +and tr.name=N'tr_rif40_study_areas') +BEGIN + DROP TRIGGER [rif40].[tr_rif40_study_areas]; +END +GO + + +------------------------------ +-- create trigger code +------------------------------ +CREATE trigger [rif40].[tr_rif40_study_areas] +on [rif40].[rif40_study_areas] +instead of insert , update , delete +as +BEGIN +-------------------------------------- +--to Determine the type of transaction +--------------------------------------- +DECLARE @XTYPE varchar(1); +IF EXISTS (SELECT * FROM DELETED) + SET @XTYPE = 'D'; + +IF EXISTS (SELECT * FROM INSERTED) +BEGIN + IF (@XTYPE = 'D') + SET @XTYPE = 'U' + ELSE + SET @XTYPE = 'I' +END; + +IF @XTYPE='I' +BEGIN +-- +-- Check (USER = username OR NULL) and USER is a RIF user; if OK INSERT +-- + DECLARE @insert_invalid_user VARCHAR(MAX) = + ( + select SUSER_SNAME() AS username + from inserted + where NOT (username = SUSER_SNAME() OR username is null) + OR NOT ([rif40].[rif40_has_role](SUSER_SNAME(),'rif_user') = 1 + AND [rif40].[rif40_has_role](SUSER_SNAME(),'rif_manager') = 1) + ); + + IF @insert_invalid_user IS NOT NULL + BEGIN TRY + rollback; + DECLARE @err_msg1 VARCHAR(MAX) = formatmessage(51134, @insert_invalid_user); + THROW 51134, @err_msg1, 1; + END TRY + BEGIN CATCH + EXEC [rif40].[ErrorLog_proc] @Error_Location='[rif40].[rif40_study_areas]'; + THROW 51134, @err_msg1, 1; + END CATCH; + + INSERT INTO [rif40].[t_rif40_study_areas] ( + username, + study_id, + area_id, + band_id, + intersect_count, + distance_from_nearest_source, + nearest_rifshapepolyid, + exposure_value) + SELECT + isnull(username,SUSER_SNAME()), + isnull(study_id,[rif40].[rif40_sequence_current_value]('rif40.rif40_study_id_seq')), + area_id /* no default value */, + band_id /* no default value */, + intersect_count, + distance_from_nearest_source, + nearest_rifshapepolyid, + exposure_value + FROM inserted; + +END; + +IF @XTYPE='U' +BEGIN +-- +-- Check USER = OLD.username and NEW.username = OLD.username; if OK UPDATE +-- + DECLARE @update_invalid_user VARCHAR(MAX) = + ( + select a.username as 'old_username', b.username as 'new_username', SUSER_SNAME() as 'current_user' + from deleted a + left outer join inserted b on a.study_id=b.study_id and a.area_id=b.area_id + where a.username != SUSER_SNAME() + or (b.username is not null and a.username != b.username) + FOR XML PATH ('') + ); + IF @update_invalid_user IS NOT NULL + BEGIN TRY + rollback; + DECLARE @err_msg2 VARCHAR(MAX) = formatmessage(51135, @update_invalid_user); + THROW 51135, @err_msg2, 1; + END TRY + BEGIN CATCH + EXEC [rif40].[ErrorLog_proc] @Error_Location='[rif40].[rif40_study_areas]'; + THROW 51135, @err_msg2, 1; + END CATCH; + + DELETE FROM [rif40].[t_rif40_study_areas] + WHERE EXISTS ( + SELECT 1 + FROM deleted b + WHERE b.study_id=[rif40].[t_rif40_study_areas].study_id + AND b.area_id=[rif40].[t_rif40_study_areas].area_id); + + INSERT INTO [rif40].[t_rif40_study_areas] ( + username, + study_id, + area_id, + band_id, + intersect_count, + distance_from_nearest_source, + nearest_rifshapepolyid, + exposure_value) + SELECT + username, + study_id, + area_id, + band_id, + intersect_count, + distance_from_nearest_source, + nearest_rifshapepolyid, + exposure_value + FROM inserted; +END; + +IF @XTYPE='D' +BEGIN +-- +-- Check USER = OLD.username; if OK DELETE +-- + DECLARE @delete_invalid_user VARCHAR(MAX) = + ( + select username + from deleted + where username != SUSER_SNAME() + FOR XML PATH('') + ); + IF @delete_invalid_user IS NOT NULL + BEGIN TRY + rollback; + DECLARE @err_msg3 VARCHAR(MAX) = formatmessage(51136, @delete_invalid_user); + THROW 51136, @err_msg3, 1; + END TRY + BEGIN CATCH + EXEC [rif40].[ErrorLog_proc] @Error_Location='[rif40].[rif40_study_areas]'; + THROW 51136, @err_msg3, 1; + END CATCH; + + DELETE FROM [rif40].[t_rif40_study_areas] + WHERE EXISTS ( + SELECT 1 + FROM deleted b + WHERE b.study_id=[rif40].[t_rif40_study_areas].study_id + AND b.area_id=[rif40].[t_rif40_study_areas].area_id); +END; + +END; +GO diff --git a/rifDatabase/SQLserver/alter scripts/v4_0_alter_12.sql b/rifDatabase/SQLserver/alter scripts/v4_0_alter_12.sql index 018c55ead..bc8ef002d 100644 --- a/rifDatabase/SQLserver/alter scripts/v4_0_alter_12.sql +++ b/rifDatabase/SQLserver/alter scripts/v4_0_alter_12.sql @@ -194,7 +194,7 @@ SELECT geography, covariate_name, covariate_type, COUNT(*) AS total GO :r ..\sahsuland_dev\rif40\functions\rif40_create_insert_statement.sql -:r ..\sahsuland_dev\rif40\view_triggers\rif40_study_areas_trigger.sql +:r rif40_study_areas_trigger.sql -- -- Testing stop -- diff --git a/rifDatabase/SQLserver/sahsuland_dev/rif40/view_triggers/rif40_study_areas_trigger.sql b/rifDatabase/SQLserver/sahsuland_dev/rif40/view_triggers/rif40_study_areas_trigger.sql index 75a78fa46..fa27286e2 100644 --- a/rifDatabase/SQLserver/sahsuland_dev/rif40/view_triggers/rif40_study_areas_trigger.sql +++ b/rifDatabase/SQLserver/sahsuland_dev/rif40/view_triggers/rif40_study_areas_trigger.sql @@ -61,20 +61,12 @@ BEGIN username, study_id, area_id, - band_id, - intersect_count, - distance_from_nearest_source, - nearest_rifshapepolyid, - exposure_value) + band_id) SELECT isnull(username,SUSER_SNAME()), isnull(study_id,[rif40].[rif40_sequence_current_value]('rif40.rif40_study_id_seq')), area_id /* no default value */, - band_id /* no default value */, - intersect_count, - distance_from_nearest_source, - nearest_rifshapepolyid, - exposure_value + band_id /* no default value */ FROM inserted; END; @@ -115,20 +107,12 @@ BEGIN username, study_id, area_id, - band_id, - intersect_count, - distance_from_nearest_source, - nearest_rifshapepolyid, - exposure_value) + band_id) SELECT username, study_id, area_id, - band_id, - intersect_count, - distance_from_nearest_source, - nearest_rifshapepolyid, - exposure_value + band_id FROM inserted; END; From 3bcd55066e08aa55e3911159839adaa8e7a106e6 Mon Sep 17 00:00:00 2001 From: Martin McCallion Date: Tue, 19 Mar 2019 12:09:23 +0000 Subject: [PATCH 08/11] Add check that Windows user is running installation as administrator. --- installer/install.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/installer/install.py b/installer/install.py index 06e160c13..53784aff9 100755 --- a/installer/install.py +++ b/installer/install.py @@ -679,6 +679,14 @@ def set_windows_permissions(file_name): # complain. import ntsecuritycon import win32security + from win32com.shell import shell + + # Have to run as an administrator for this bit. + if not shell.IsUserAnAdmin(): + banner("This function requires elevated privileges. Please run again " + "from a command prompt started using the 'Run as " + "administrator' feature", 100) + sys.exit(-1) entries = [{'AccessMode': win32security.GRANT_ACCESS, 'AccessPermissions': 0, From 1d0cdcc99dba562f2cc22ee0edf4914d1c4fdd26 Mon Sep 17 00:00:00 2001 From: Martin McCallion Date: Wed, 20 Mar 2019 16:15:48 +0000 Subject: [PATCH 09/11] Add details on setting the PATH environment variable; and strengthened warning about running as admin on Windows. --- docs/Installation/QuickstartGuide.md | 32 +++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/docs/Installation/QuickstartGuide.md b/docs/Installation/QuickstartGuide.md index c052563e5..700fc72c6 100644 --- a/docs/Installation/QuickstartGuide.md +++ b/docs/Installation/QuickstartGuide.md @@ -15,6 +15,34 @@ Before installing the RIF you must have the following installed: You must also have administrative rights on the machine on which you are installing. +## Setting the Path + +The installation process creates the database schemas used by the RIF, by running a series of SQL scripts. To do so it needs to be able to find the appropriate commands: `psql` for PostgreSQL, and `SQLCMD.EXE` for SQL Server. + +To that end you must add the folder containing the appropriate one of those commands to the `PATH` environment variable. If you are unfamiliar with setting environment variables, [you can find instructions here](https://www.computerhope.com/issues/ch000549.htm) for how to do it in various versions of Windows. + +The relevant value to add to the path will be something like: + +``` +C:\Program Files\Microsoft SQL Server\140\Tools\Binn +``` + +for SQL Server on Windows, or: + +``` +C:\Program Files\PostgreSQL\9.5\bin +``` + +for Postgres on Windows, or: + +``` +/usr/local/bin +``` + +(which example will almost certainly be on your `PATH` already) for Postgres on other platforms. Exact values will depend on the version of the database system and the specific details of your system. + +On Unix-based systems, including Mac and Linux, you can set it in the user's `.profile` or `.bashrc` file, or similar. + ## Getting the Installer Download a RIF installer from the [GitHub site](https://github.com/smallAreaHealthStatisticsUnit/rapidInquiryFacility). We recommend always getting the latest version available from the [Releases tab](https://github.com/smallAreaHealthStatisticsUnit/rapidInquiryFacility/releases). @@ -29,7 +57,9 @@ For Windows, save `rifInstaller.exe` to the machine you are installing on. For M Run the installer from the command line. We don't recommend running it by double-clicking the icon in Windows Explorer or the Finder. It will run, but when it finishes you won't see the output to know whether it was successful. -On Windows, open the Start Menu. Right-click on _Command Prompt_ and choose "Run as administrator". Answer "Yes" to the confirmation dialog. +**Note: On Windows, elevated privileges are needed.** + +On Windows, open the Start Menu. Right-click on _Command Prompt_ and choose **"Run as administrator"**. Answer "Yes" to the confirmation dialog. On Mac, open the _Terminal_ app. On Linux open a terminal. From 3fa42ec27d462abfeb3d5a4f4be733bd0ff3cf23 Mon Sep 17 00:00:00 2001 From: Martin McCallion Date: Thu, 21 Mar 2019 12:30:48 +0000 Subject: [PATCH 10/11] Remove use of Postgres 9.6 syntax. --- .../psql_scripts/alter_scripts/v4_0_alter_12.sql | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rifDatabase/Postgres/psql_scripts/alter_scripts/v4_0_alter_12.sql b/rifDatabase/Postgres/psql_scripts/alter_scripts/v4_0_alter_12.sql index be1c798e2..d10ae91d8 100644 --- a/rifDatabase/Postgres/psql_scripts/alter_scripts/v4_0_alter_12.sql +++ b/rifDatabase/Postgres/psql_scripts/alter_scripts/v4_0_alter_12.sql @@ -82,7 +82,14 @@ GRANT SELECT ON rif40_homogeneity TO rif_user, rif_manager; -- -- Table: rif40.t_rif40_inv_covariates: add covariate_type flag -- -ALTER TABLE rif40.t_rif40_inv_covariates ADD COLUMN IF NOT EXISTS covariate_type character varying(1) NULL; +DO LANGUAGE plpgsql $$ + BEGIN + ALTER TABLE rif40.t_rif40_inv_covariates ADD COLUMN covariate_type character varying(1) NULL; + EXCEPTION + WHEN duplicate_column THEN + RAISE NOTICE 'Column already renamed: %',SQLERRM::Text; + END; +$$; DROP TRIGGER t_rif40_inv_covariates_checks ON rif40.t_rif40_inv_covariates; UPDATE rif40.t_rif40_inv_covariates From 77e914ddf5eb86601a1aad091ef2fec06f1dc69e Mon Sep 17 00:00:00 2001 From: Martin McCallion Date: Fri, 22 Mar 2019 11:23:14 +0000 Subject: [PATCH 11/11] Add stderr to the log file. --- installer/install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/install.py b/installer/install.py index 53784aff9..99a2f848a 100755 --- a/installer/install.py +++ b/installer/install.py @@ -103,7 +103,7 @@ def main(): # This sends output to the specified file as well as stdout. outfile = Tee("install.log") sys.stdout = outfile - # sys.stderr = outfile + sys.stderr = outfile # Run SQL scripts if settings.db_type == "pg":