Skip to content

Commit

Permalink
Update create_login.sql to be templated based on ko_db argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevewgr committed May 22, 2024
1 parent ff48df0 commit f26ad64
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
7 changes: 5 additions & 2 deletions import.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ function RunMigrationScriptsAndGenerateDiffs {

function CreateDbCredentials {
MessageInfo "`n`n### Creating login and user for $db_name... ###"
Message "src/misc/create_login.sql"
InvokeSqlScript -script_path "src/misc/create_login.sql"
$login_script_file = "src/misc/create_login.sql"
Message $login_script_file
$output_script_file = Join-Path $env:TEMP "create_login_$(New-Guid).sql"
(Get-Content $login_script_file) -replace "###DB_NAME###", $db_name | Out-File $output_script_file
InvokeSqlScript -script_path "$output_script_file"
}

function Main {
Expand Down
16 changes: 8 additions & 8 deletions src/misc/create_login.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
USE [master]
IF EXISTS (SELECT * FROM sys.server_principals WHERE name = N'kodb_user')
DROP LOGIN [kodb_user];
CREATE LOGIN [kodb_user] WITH PASSWORD=N'kodb_user', DEFAULT_DATABASE=[kodb], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON;
IF EXISTS (SELECT * FROM sys.server_principals WHERE name = N'###DB_NAME###_user')
DROP LOGIN [###DB_NAME###_user];
CREATE LOGIN [###DB_NAME###_user] WITH PASSWORD=N'###DB_NAME###_user', DEFAULT_DATABASE=[###DB_NAME###], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON;
GO

USE [kodb]
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'kodb_user')
DROP USER [kodb_user];
CREATE USER [kodb_user] FOR LOGIN [kodb_user];
EXEC sp_addrolemember N'db_owner', N'kodb_user';
USE [###DB_NAME###]
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'###DB_NAME###_user')
DROP USER [###DB_NAME###_user];
CREATE USER [###DB_NAME###_user] FOR LOGIN [###DB_NAME###_user];
EXEC sp_addrolemember N'db_owner', N'###DB_NAME###_user';
GO

0 comments on commit f26ad64

Please sign in to comment.