-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/58073 tech support user (#2466)
* create user script * update script with token values| * refactor tests and remove duplicate & obsolete * remove superfluous script * retire tech support user, introduce sql support * re-add tech support user * guard against non existing target objects
- Loading branch information
1 parent
6f1af01
commit a01c9a5
Showing
15 changed files
with
97 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
db/migrations/schema-objects/20211208124902.do.enable-change-data-capture.sql
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
db/migrations/schema-objects/20211208124902.undo.enable-change-data-capture.sql
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
db/migrations/schema-objects/20211208124914.do.track-school-changes-cdc.sql
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
db/migrations/schema-objects/20211208124914.undo.track-school-changes-cdc.sql
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
db/migrations/schema-objects/20220117154728.do.disable-cdc-for-db.sql
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
db/migrations/schema-objects/20220117154728.undo.disable-cdc-for-db.sql
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
db/migrations/user-permissions/20230309163938.do.sql-support-user-grants.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
const config = require('../../config') | ||
|
||
module.exports.generateSql = function () { | ||
if (config.Sql.SqlSupport.Password === undefined) return '' | ||
return ` | ||
IF USER_ID('${config.Sql.SqlSupport.Username}') IS NULL RETURN | ||
GRANT CONNECT TO [${config.Sql.SqlSupport.Username}] AS [dbo] | ||
GRANT EXECUTE,SELECT ON SCHEMA::[mtc_admin] TO [${config.Sql.SqlSupport.Username}] AS [dbo] | ||
GRANT EXECUTE,SELECT ON SCHEMA::[mtc_results] TO [${config.Sql.SqlSupport.Username}] AS [dbo] | ||
` | ||
} |
12 changes: 12 additions & 0 deletions
12
db/migrations/user-permissions/20230309163938.undo.sql-support-user-grants.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict' | ||
|
||
const config = require('../../config') | ||
|
||
module.exports.generateSql = function () { | ||
return ` | ||
IF USER_ID('${config.Sql.SqlSupport.Username}') IS NULL RETURN | ||
REVOKE CONNECT TO [${config.Sql.SqlSupport.Username}] AS [dbo] | ||
REVOKE EXECUTE,SELECT ON SCHEMA::[mtc_admin] TO [${config.Sql.SqlSupport.Username}] AS [dbo] | ||
REVOKE EXECUTE,SELECT ON SCHEMA::[mtc_results] TO [${config.Sql.SqlSupport.Username}] AS [dbo] | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict' | ||
|
||
const config = require('../../config') | ||
|
||
const createStatementSqlAzure = `IF USER_ID('${config.Sql.SqlSupport.Username}') IS NOT NULL RETURN; CREATE USER ${config.Sql.SqlSupport.Username} WITH PASSWORD ='${config.Sql.SqlSupport.Password}', DEFAULT_SCHEMA=[mtc_admin];` | ||
const createStatementSqlServer = `IF SUSER_ID('${config.Sql.SqlSupport.Username}') IS NOT NULL RETURN; CREATE LOGIN ${config.Sql.SqlSupport.Username} WITH PASSWORD = '${config.Sql.SqlSupport.Password}'; USE ${config.Sql.Database}; IF USER_ID('${config.Sql.SqlSupport.Username}') IS NOT NULL RETURN; CREATE USER ${config.Sql.SqlSupport.Username} FOR LOGIN ${config.Sql.SqlSupport.Username} WITH DEFAULT_SCHEMA = [mtc_admin];` | ||
|
||
module.exports.generateSql = function () { | ||
// only create if password is configured | ||
if (config.Sql.SqlSupport.Password === undefined) return '' | ||
if (config.Sql.Azure.Scale) { | ||
return createStatementSqlAzure | ||
} else { | ||
return createStatementSqlServer | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
db/migrations/user/20230309163747.undo.sql-support-user.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
const config = require('../../config') | ||
|
||
const dropAzureUser = `DROP USER IF EXISTS ${config.Sql.SqlSupport.Username};` | ||
const dropLocalUser = ` | ||
IF USER_ID('${config.Sql.SqlSupport.Username}') IS NULL RETURN; | ||
DROP USER ${config.Sql.SqlSupport.Username}; | ||
IF SUSER_ID('${config.Sql.SqlSupport.Username}') IS NULL RETURN; | ||
DROP LOGIN ${config.Sql.SqlSupport.Username};` | ||
|
||
module.exports.generateSql = function () { | ||
// always try to undo, as password may have been removed/added between migrations | ||
if (config.Sql.Azure.Scale) { | ||
return dropAzureUser | ||
} else { | ||
return dropLocalUser | ||
} | ||
} |