-
Notifications
You must be signed in to change notification settings - Fork 29
/
sqlserver-create-schema.txt
89 lines (75 loc) · 2.71 KB
/
sqlserver-create-schema.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
-- DO THIS SECTION ONCE WHEN CREATING THE DATABASE
-- DO THIS SECTION ONCE WHEN CREATING THE DATABASE
-- DO THIS SECTION ONCE WHEN CREATING THE DATABASE
-- DO THIS SECTION ONCE WHEN CREATING THE DATABASE
--
-- create the database
create database [DATABASE_NAME];
go
-- switch to database
use [DATABASE_NAME];
go
-- DO THIS SECTION FOR EACH USER GROUP YOU DEFINE
-- DO THIS SECTION FOR EACH USER GROUP YOU DEFINE
-- DO THIS SECTION FOR EACH USER GROUP YOU DEFINE
-- DO THIS SECTION FOR EACH USER GROUP YOU DEFINE
-- declare an Azure group to which the user that
-- can write to an ODK Aggregate schema belongs
-- create the group (here: "odk_prod") in Azure Active
-- Directory before you reference it here.
-- Ideally, this would be one group for each ODK Aggregate
-- that is spun up.
--
create user [odk_prod] FROM EXTERNAL PROVIDER;
--
go
-- grant access for this group to the database server.
-- this group or user can connect to the database server
-- and see what objects are defined within
GRANT CONNECT, VIEW DEFINITION TO [odk_prod];
go
-- DO THIS SECTION FOR EACH ODK AGGREGATE YOU SPIN UP
-- DO THIS SECTION FOR EACH ODK AGGREGATE YOU SPIN UP
-- DO THIS SECTION FOR EACH ODK AGGREGATE YOU SPIN UP
-- DO THIS SECTION FOR EACH ODK AGGREGATE YOU SPIN UP
create schema [SCHEMA_NAME];
go
-- grant odk_prod group the ability to create, manipulate
-- and drop tables on the database. Unclear how to narrow
-- this access to just the schema. I think this is needed
-- to access the information_schema ?
grant alter on database::[DATABASE_NAME] to [odk_prod];
go
-- grant odk_prod group the ability to create, manipulate
-- and drop tables within the schema.
grant alter, control on schema::[SCHEMA_NAME] to [odk_prod];
go
-----------------------------------------------------------
-----------------------------------------------------------
-----------------------------------------------------------
-- original version for sqlserver running locally
-- original version for sqlserver running locally
-- original version for sqlserver running locally
-----------------------------------------------------------
-----------------------------------------------------------
-----------------------------------------------------------
USE master;
IF EXISTS(select * from sys.databases where name='odk_unit')
DROP database odk_unit;
go
CREATE DATABASE odk_unit;
go
USE odk_unit;
go
create user [odk_prod] FROM EXTERNAL PROVIDER;
go
GRANT CONNECT, VIEW DEFINITION TO [odk_prod];
go
grant alter on database::[odk_unit] to [odk_prod];
go
CREATE SCHEMA odk_schema authorization [odk_prod];
go
-- grant odk_prod group the ability to create, manipulate
-- and drop tables within the schema.
grant alter, control on schema::[odk_schema] to [odk_prod];
go