From d499701452748a8f9968ae7a6855b24ae394789e Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Thu, 24 Oct 2024 12:25:36 +0700 Subject: [PATCH] Copying sqlserver init script from xo source --- contrib/sqlserver/init.sql | 61 +++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/contrib/sqlserver/init.sql b/contrib/sqlserver/init.sql index b66cd4a9a98..0dd7f3df09b 100644 --- a/contrib/sqlserver/init.sql +++ b/contrib/sqlserver/init.sql @@ -1,13 +1,3 @@ -\set SQLSERVER_USER sa -\set SQLSERVER_PASS Adm1nP@ssw0rd -\set SQLSERVER_DB postgres -\set SQLSERVER_HOST `docker port sqlserver 1433` - -\prompt NAME 'Create database user: ' -\prompt -password PASS 'Password for "':NAME'": ' - -\connect 'sqlserver://':SQLSERVER_USER':':SQLSERVER_PASS'@':SQLSERVER_HOST'/':SQLSERVER_DB - EXEC sp_configure 'contained database authentication', 1; @@ -18,21 +8,36 @@ DROP LOGIN :NAME; DROP DATABASE :NAME; CREATE DATABASE :NAME - containment=partial; - -\connect 'sqlserver://':SQLSERVER_USER':':SQLSERVER_PASS'@':SQLSERVER_HOST'/':SQLSERVER_DB - -CREATE LOGIN :NAME - WITH - password=:'PASS', - check_policy=off, - default_database=:NAME; - -CREATE USER :NAME - FOR login :NAME - WITH default_schema=:NAME; - -CREATE SCHEMA :NAME authorization :NAME; - -EXEC sp_addrolemember - 'db_owner', :'NAME'; + CONTAINMENT=PARTIAL; + +\set QNAME "''":NAME"''" + +\set SQL 'CREATE LOGIN ':NAME' WITH PASSWORD=':QNAME', CHECK_POLICY=OFF, DEFAULT_DATABASE=':NAME';' +EXEC [:NAME].[dbo].[sp_executesql] N:'SQL' + +\set SQL 'CREATE USER ':NAME' FOR LOGIN ':NAME' WITH DEFAULT_SCHEMA=':NAME';' +EXEC [:NAME].[dbo].[sp_executesql] N:'SQL'; + +\set SQL 'CREATE SCHEMA ':NAME' AUTHORIZATION ':NAME';' +EXEC [:NAME].[dbo].[sp_executesql] N:'SQL'; + +\set SQL 'EXEC sp_addrolemember db_owner, ':QNAME';' +EXEC [:NAME].[dbo].[sp_executesql] N:'SQL'; + +-- original reconnect version: +-- +--\connect 'sqlserver://localhost/':NAME +-- +--CREATE LOGIN :NAME +-- WITH +-- PASSWORD=:'PASS', +-- CHECK_POLICY=OFF, +-- DEFAULT_DATABASE=:NAME; +-- +--CREATE USER :NAME +-- FOR LOGIN :NAME +-- WITH DEFAULT_SCHEMA=:NAME; +-- +--CREATE SCHEMA :NAME AUTHORIZATION :NAME; +-- +--EXEC sp_addrolemember 'db_owner', :'NAME';