ucampostgresvro 0.1.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Information Services / Infrastructure
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,232 @@
1
+ Metadata-Version: 2.3
2
+ Name: ucampostgresvro
3
+ Version: 0.1.0
4
+ Summary:
5
+ Author: Ishan Mahajan
6
+ Author-email: mahanishanmahajan@gmail.com
7
+ Requires-Python: >=3.10
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Requires-Dist: psycopg2-binary (>=2.9.10,<3.0.0)
14
+ Description-Content-Type: text/markdown
15
+
16
+ # Script for VRA database for Costing
17
+
18
+ # Developing
19
+ 1. [Install docker-compose](https://docs.docker.com/compose/install/).
20
+ 2. Docker will run the postgres on port 5455 so, ensure the system has the port available
21
+
22
+ ```
23
+ # run pytest testing
24
+ ./developer.sh pytest start
25
+
26
+ # run flake8 testing
27
+ ./developer.sh flake8 start
28
+
29
+ # delete the testing environment
30
+ ./developer.sh pytest stop
31
+
32
+ # delete the flake8 environment
33
+ ./developer.sh flake8 stop
34
+ ```
35
+
36
+
37
+ ## Package usage
38
+
39
+ - To setup database
40
+ ```
41
+ from ucampostgresvro import pre_setupconfig
42
+ from ucampostgresvro.DB import DB
43
+ db_params = {
44
+ "dbname": "vrapricing",
45
+ "user": "postgres",
46
+ "password": <1Password: vrapricingpostgres>,
47
+ "host": "infra-db.srv.uis.cam.ac.uk",
48
+ "port": "5432",
49
+ "sslmode": "require",
50
+ "sslrootcert": "./ca.crt", # path to your client certificate
51
+ }
52
+ db = DB(db_params)
53
+ pre_setupconfig(db_params)
54
+ ```
55
+ - To perform CRUD operation
56
+ ```
57
+ from ucampostgresvro.DB import DB
58
+ db_params = {
59
+ "dbname": "vrapricing",
60
+ "user": "postgres",
61
+ "password": <1Password: vrapricingpostgres>,
62
+ "host": "infra-db.srv.uis.cam.ac.uk",
63
+ "port": "5432",
64
+ "sslmode": "require",
65
+ "sslrootcert": "./ca.crt", # path to your client certificate
66
+ }
67
+ db = DB(db_params)
68
+
69
+ # CRUD on user DB./
70
+
71
+ # create user
72
+ db.insert_vrauser("ll220", "Ling-Yan Lau")
73
+
74
+ # read user
75
+ print(db.get_vrauser())
76
+
77
+ # update user
78
+ db.update_vrauser("ll220", "bda20", 'Ben Argyle')
79
+
80
+ # delete user
81
+ db.remove_vrauser('bda20')
82
+
83
+ # create vra deploymentid
84
+ db.insert_deployment_id("1231ee112ad11212")
85
+
86
+ # read vra deployment id
87
+ print(db.get_deployment_id("1231a"))
88
+
89
+ # update vra deployment id
90
+ db.update_deployment_id("1231ee112ad1", "1231a")
91
+
92
+ # delete vra deployment id
93
+ db.remove_deployment_id('1231a')
94
+
95
+ # create project
96
+ db.insert_project("0001",1,100.0)
97
+
98
+ # read project
99
+ print(db.get_project())
100
+
101
+ # update project
102
+ db.update_project("0001", "0002", 4, 200)
103
+
104
+ # delete project
105
+ # db.remove_project("0002")
106
+
107
+ # create grant
108
+ db.insert_grant("0001",1,100.0)
109
+
110
+ # read grant
111
+ print(db.get_grant())
112
+
113
+ # update grant
114
+ db.update_grant("0001", "0002", 4, 200)
115
+
116
+ # delete grant
117
+ db.remove_grant("0002")
118
+
119
+ # create costing
120
+ db.insert_costing(2, "Initial Resource", project_id=4, grant_id=None)
121
+
122
+ # read costing
123
+ print(db.get_costing())
124
+
125
+ # update costing
126
+ db.update_costing(2, "Duration Expansion", old_grant_id=4, old_project_id=None, grant_id=4, project_id=None)
127
+
128
+ # delete costing
129
+ db.remove_costing(2, "Duration Expansion", 4, None)
130
+
131
+ # to close db connection
132
+ db.closedb()
133
+ ```
134
+
135
+ ---
136
+ ### Design
137
+
138
+ ![DB Design](./db.jpg "DB design")
139
+
140
+ ## - VRAUSER table
141
+ ```
142
+ vrapricing=# \d vrauser;
143
+ Table "public.vrauser"
144
+ Column | Type | Collation | Nullable | Default
145
+ --------+------------------------+-----------+----------+-------------------------------------
146
+ id | integer | | not null | nextval('vrauser_id_seq'::regclass)
147
+ crsid | character varying(255) | | |
148
+ name | character varying(255) | | |
149
+ Indexes:
150
+ "vrauser_pkey" PRIMARY KEY, btree (id)
151
+ "vrauser_crsid_key" UNIQUE CONSTRAINT, btree (crsid)
152
+ Referenced by:
153
+ TABLE "purchaseorder" CONSTRAINT "purchaseorder_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
154
+ TABLE "grant" CONSTRAINT "grant_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
155
+
156
+ ```
157
+
158
+ ## - VRA Deployment ID tabel
159
+ ```
160
+ vrapricing=# \d deploymentid;
161
+ Table "public.deploymentid"
162
+ Column | Type | Collation | Nullable | Default
163
+ --------------+-----------------------+-----------+----------+------------------------------------------
164
+ id | integer | | not null | nextval('deploymentid_id_seq'::regclass)
165
+ deploymentid | character varying(50) | | |
166
+ Indexes:
167
+ "deploymentid_pkey" PRIMARY KEY, btree (id)
168
+ "deploymentid_deploymentid_key" UNIQUE CONSTRAINT, btree (deploymentid)
169
+ Referenced by:
170
+ TABLE "costing" CONSTRAINT "costing_deployment_id_fkey" FOREIGN KEY (deployment_id) REFERENCES deploymentid(id)
171
+
172
+ ```
173
+
174
+ ## - project table
175
+ ```
176
+ vrapricing=# \d projects;
177
+ Table "public.projects"
178
+ Column | Type | Collation | Nullable | Default
179
+ ----------------+------------------------+-----------+----------+--------------------------------------
180
+ id | integer | | not null | nextval('projects_id_seq'::regclass)
181
+ project_number | character varying(255) | | |
182
+ paid_by | integer | | |
183
+ amount | double precision | | not null |
184
+ Indexes:
185
+ "projects_pkey" PRIMARY KEY, btree (id)
186
+ Foreign-key constraints:
187
+ "projects_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
188
+ Referenced by:
189
+ TABLE "costing" CONSTRAINT "costing_project_id_fkey" FOREIGN KEY (project_id) REFERENCES projects(id)
190
+
191
+ ```
192
+
193
+ ## - grants table
194
+ ```
195
+ vrapricing=# \d grant;
196
+ Table "public.grant"
197
+ Column | Type | Collation | Nullable | Default
198
+ ----------------+------------------------+-----------+----------+--------------------------------------
199
+ id | integer | | not null | nextval('grant_id_seq'::regclass)
200
+ voucher_number | character varying(255) | | |
201
+ paid_by | integer | | |
202
+ amount | double precision | | not null |
203
+ Indexes:
204
+ "grant_pkey" PRIMARY KEY, btree (id)
205
+ Foreign-key constraints:
206
+ "grant_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
207
+ Referenced by:
208
+ TABLE "costing" CONSTRAINT "costing_voucher_id_fkey" FOREIGN KEY (voucher_id) REFERENCES grant(id)
209
+ ```
210
+
211
+ ## - Costing table
212
+ ```
213
+ vrapricing=# \d costing;
214
+ Table "public.costing"
215
+ Column | Type | Collation | Nullable | Default
216
+ ---------------+------------------------+-----------+----------+-------------------------------------
217
+ id | integer | | not null | nextval('costing_id_seq'::regclass)
218
+ deployment_id | integer | | |
219
+ type | character varying(100) | | |
220
+ po_number_id | integer | | |
221
+ voucher_id | integer | | |
222
+ Indexes:
223
+ "costing_pkey" PRIMARY KEY, btree (id)
224
+ Check constraints:
225
+ "costing_type_check" CHECK (type::text = ANY (ARRAY['Resource Expansion'::character varying, 'Duration Expansion'::character varying, 'Initial Resource'::character varying]::text[]))
226
+ Foreign-key constraints:
227
+ "costing_deployment_id_fkey" FOREIGN KEY (deployment_id) REFERENCES deploymentid(id)
228
+ "costing_po_number_id_fkey" FOREIGN KEY (po_number_id) REFERENCES purchaseorder(id)
229
+ "costing_voucher_id_fkey" FOREIGN KEY (voucher_id) REFERENCES grant(id)
230
+
231
+ ```
232
+
@@ -0,0 +1,216 @@
1
+ # Script for VRA database for Costing
2
+
3
+ # Developing
4
+ 1. [Install docker-compose](https://docs.docker.com/compose/install/).
5
+ 2. Docker will run the postgres on port 5455 so, ensure the system has the port available
6
+
7
+ ```
8
+ # run pytest testing
9
+ ./developer.sh pytest start
10
+
11
+ # run flake8 testing
12
+ ./developer.sh flake8 start
13
+
14
+ # delete the testing environment
15
+ ./developer.sh pytest stop
16
+
17
+ # delete the flake8 environment
18
+ ./developer.sh flake8 stop
19
+ ```
20
+
21
+
22
+ ## Package usage
23
+
24
+ - To setup database
25
+ ```
26
+ from ucampostgresvro import pre_setupconfig
27
+ from ucampostgresvro.DB import DB
28
+ db_params = {
29
+ "dbname": "vrapricing",
30
+ "user": "postgres",
31
+ "password": <1Password: vrapricingpostgres>,
32
+ "host": "infra-db.srv.uis.cam.ac.uk",
33
+ "port": "5432",
34
+ "sslmode": "require",
35
+ "sslrootcert": "./ca.crt", # path to your client certificate
36
+ }
37
+ db = DB(db_params)
38
+ pre_setupconfig(db_params)
39
+ ```
40
+ - To perform CRUD operation
41
+ ```
42
+ from ucampostgresvro.DB import DB
43
+ db_params = {
44
+ "dbname": "vrapricing",
45
+ "user": "postgres",
46
+ "password": <1Password: vrapricingpostgres>,
47
+ "host": "infra-db.srv.uis.cam.ac.uk",
48
+ "port": "5432",
49
+ "sslmode": "require",
50
+ "sslrootcert": "./ca.crt", # path to your client certificate
51
+ }
52
+ db = DB(db_params)
53
+
54
+ # CRUD on user DB./
55
+
56
+ # create user
57
+ db.insert_vrauser("ll220", "Ling-Yan Lau")
58
+
59
+ # read user
60
+ print(db.get_vrauser())
61
+
62
+ # update user
63
+ db.update_vrauser("ll220", "bda20", 'Ben Argyle')
64
+
65
+ # delete user
66
+ db.remove_vrauser('bda20')
67
+
68
+ # create vra deploymentid
69
+ db.insert_deployment_id("1231ee112ad11212")
70
+
71
+ # read vra deployment id
72
+ print(db.get_deployment_id("1231a"))
73
+
74
+ # update vra deployment id
75
+ db.update_deployment_id("1231ee112ad1", "1231a")
76
+
77
+ # delete vra deployment id
78
+ db.remove_deployment_id('1231a')
79
+
80
+ # create project
81
+ db.insert_project("0001",1,100.0)
82
+
83
+ # read project
84
+ print(db.get_project())
85
+
86
+ # update project
87
+ db.update_project("0001", "0002", 4, 200)
88
+
89
+ # delete project
90
+ # db.remove_project("0002")
91
+
92
+ # create grant
93
+ db.insert_grant("0001",1,100.0)
94
+
95
+ # read grant
96
+ print(db.get_grant())
97
+
98
+ # update grant
99
+ db.update_grant("0001", "0002", 4, 200)
100
+
101
+ # delete grant
102
+ db.remove_grant("0002")
103
+
104
+ # create costing
105
+ db.insert_costing(2, "Initial Resource", project_id=4, grant_id=None)
106
+
107
+ # read costing
108
+ print(db.get_costing())
109
+
110
+ # update costing
111
+ db.update_costing(2, "Duration Expansion", old_grant_id=4, old_project_id=None, grant_id=4, project_id=None)
112
+
113
+ # delete costing
114
+ db.remove_costing(2, "Duration Expansion", 4, None)
115
+
116
+ # to close db connection
117
+ db.closedb()
118
+ ```
119
+
120
+ ---
121
+ ### Design
122
+
123
+ ![DB Design](./db.jpg "DB design")
124
+
125
+ ## - VRAUSER table
126
+ ```
127
+ vrapricing=# \d vrauser;
128
+ Table "public.vrauser"
129
+ Column | Type | Collation | Nullable | Default
130
+ --------+------------------------+-----------+----------+-------------------------------------
131
+ id | integer | | not null | nextval('vrauser_id_seq'::regclass)
132
+ crsid | character varying(255) | | |
133
+ name | character varying(255) | | |
134
+ Indexes:
135
+ "vrauser_pkey" PRIMARY KEY, btree (id)
136
+ "vrauser_crsid_key" UNIQUE CONSTRAINT, btree (crsid)
137
+ Referenced by:
138
+ TABLE "purchaseorder" CONSTRAINT "purchaseorder_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
139
+ TABLE "grant" CONSTRAINT "grant_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
140
+
141
+ ```
142
+
143
+ ## - VRA Deployment ID tabel
144
+ ```
145
+ vrapricing=# \d deploymentid;
146
+ Table "public.deploymentid"
147
+ Column | Type | Collation | Nullable | Default
148
+ --------------+-----------------------+-----------+----------+------------------------------------------
149
+ id | integer | | not null | nextval('deploymentid_id_seq'::regclass)
150
+ deploymentid | character varying(50) | | |
151
+ Indexes:
152
+ "deploymentid_pkey" PRIMARY KEY, btree (id)
153
+ "deploymentid_deploymentid_key" UNIQUE CONSTRAINT, btree (deploymentid)
154
+ Referenced by:
155
+ TABLE "costing" CONSTRAINT "costing_deployment_id_fkey" FOREIGN KEY (deployment_id) REFERENCES deploymentid(id)
156
+
157
+ ```
158
+
159
+ ## - project table
160
+ ```
161
+ vrapricing=# \d projects;
162
+ Table "public.projects"
163
+ Column | Type | Collation | Nullable | Default
164
+ ----------------+------------------------+-----------+----------+--------------------------------------
165
+ id | integer | | not null | nextval('projects_id_seq'::regclass)
166
+ project_number | character varying(255) | | |
167
+ paid_by | integer | | |
168
+ amount | double precision | | not null |
169
+ Indexes:
170
+ "projects_pkey" PRIMARY KEY, btree (id)
171
+ Foreign-key constraints:
172
+ "projects_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
173
+ Referenced by:
174
+ TABLE "costing" CONSTRAINT "costing_project_id_fkey" FOREIGN KEY (project_id) REFERENCES projects(id)
175
+
176
+ ```
177
+
178
+ ## - grants table
179
+ ```
180
+ vrapricing=# \d grant;
181
+ Table "public.grant"
182
+ Column | Type | Collation | Nullable | Default
183
+ ----------------+------------------------+-----------+----------+--------------------------------------
184
+ id | integer | | not null | nextval('grant_id_seq'::regclass)
185
+ voucher_number | character varying(255) | | |
186
+ paid_by | integer | | |
187
+ amount | double precision | | not null |
188
+ Indexes:
189
+ "grant_pkey" PRIMARY KEY, btree (id)
190
+ Foreign-key constraints:
191
+ "grant_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
192
+ Referenced by:
193
+ TABLE "costing" CONSTRAINT "costing_voucher_id_fkey" FOREIGN KEY (voucher_id) REFERENCES grant(id)
194
+ ```
195
+
196
+ ## - Costing table
197
+ ```
198
+ vrapricing=# \d costing;
199
+ Table "public.costing"
200
+ Column | Type | Collation | Nullable | Default
201
+ ---------------+------------------------+-----------+----------+-------------------------------------
202
+ id | integer | | not null | nextval('costing_id_seq'::regclass)
203
+ deployment_id | integer | | |
204
+ type | character varying(100) | | |
205
+ po_number_id | integer | | |
206
+ voucher_id | integer | | |
207
+ Indexes:
208
+ "costing_pkey" PRIMARY KEY, btree (id)
209
+ Check constraints:
210
+ "costing_type_check" CHECK (type::text = ANY (ARRAY['Resource Expansion'::character varying, 'Duration Expansion'::character varying, 'Initial Resource'::character varying]::text[]))
211
+ Foreign-key constraints:
212
+ "costing_deployment_id_fkey" FOREIGN KEY (deployment_id) REFERENCES deploymentid(id)
213
+ "costing_po_number_id_fkey" FOREIGN KEY (po_number_id) REFERENCES purchaseorder(id)
214
+ "costing_voucher_id_fkey" FOREIGN KEY (voucher_id) REFERENCES grant(id)
215
+
216
+ ```
@@ -0,0 +1,28 @@
1
+ [project]
2
+ name = "ucampostgresvro"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = [
6
+ {name = "Ishan Mahajan",email = "mahanishanmahajan@gmail.com"}
7
+ ]
8
+ readme = "README.md"
9
+ requires-python = ">=3.10"
10
+ dependencies = [
11
+ "psycopg2-binary (>=2.9.10,<3.0.0)"
12
+ ]
13
+
14
+
15
+ [build-system]
16
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
17
+ build-backend = "poetry.core.masonry.api"
18
+
19
+ [tool.poetry.group.dev.dependencies]
20
+ pytest = "^8.3.4"
21
+ flake8 = "^7.1.1"
22
+
23
+
24
+ [[tool.poetry.source]]
25
+ name = "ucampostgresvro"
26
+ url = "https://gitlab.developers.cam.ac.uk/uis/infra/ucampostgresvro.git"
27
+ priority = "primary"
28
+