@@ -12,6 +12,10 @@ export const providers = [
12
12
label: " MySQL" ,
13
13
value: " mysql" ,
14
14
},
15
+ {
16
+ label: " MariaDB" ,
17
+ value: " mariadb" ,
18
+ },
15
19
{
16
20
label: " SQLite" ,
17
21
value: " sqlite" ,
@@ -80,7 +84,20 @@ sure you update the existing values instead of creating new ones
80
84
<TabItem value = " mysql" >
81
85
82
86
Be sure to change information like root password as needed. If you already have these secrets, make
83
- sure you update the existing values instead of creating new ones
87
+ sure you update the existing values instead of creating new ones.
88
+
89
+ ``` json
90
+ "globalSettings:databaseProvider" : " mysql" ,
91
+ "globalSettings:mySql:connectionString" : " server=localhost;uid=root;pwd=example;database=vault_dev" ,
92
+ ```
93
+
94
+ </TabItem >
95
+ <TabItem value = " mariadb" >
96
+
97
+ MariaDB is generally a drop-in alternative to MySQL, so it shares the ` mysql ` configuration keys.
98
+
99
+ Be sure to change information like root password as needed. If you already have these secrets, make
100
+ sure you update the existing values instead of creating new ones.
84
101
85
102
``` json
86
103
"globalSettings:databaseProvider" : " mysql" ,
@@ -109,7 +126,7 @@ that the changes take effect.
109
126
110
127
:::
111
128
112
- ### Updating the database
129
+ ### Start the database server
113
130
114
131
<Tabs
115
132
groupId = " provider"
@@ -137,7 +154,7 @@ Docker storage volume and initialize the database from scratch.
137
154
138
155
1 . Confirm that ` MYSQL_ROOT_PASSWORD ` in ` dev/.env ` matches the password in ` dev/secrets.json ` .
139
156
140
- 2 . In the ` dev ` folder of your server repository, run
157
+ 2 . In the ` dev ` folder of your server repository, start your database container:
141
158
142
159
``` bash
143
160
docker compose --profile mysql up
@@ -151,57 +168,86 @@ Docker storage volume and initialize the database from scratch.
151
168
152
169
:::
153
170
171
+ </TabItem >
172
+ <TabItem value = " mariadb" >
173
+
174
+ 1 . Confirm that ` MYSQL_ROOT_PASSWORD ` in ` dev/.env ` matches the password in ` dev/secrets.json ` .
175
+
176
+ 2 . In the ` dev ` folder of your server repository, run
177
+
178
+ ``` bash
179
+ docker compose --profile mariadb up
180
+ ```
181
+
182
+ :::tip[ Confirm your database connection!]
183
+
184
+ If you run into connection errors, double check that your ` .env ` and ` secrets.json ` files have
185
+ matching passwords. If they do, you may have initialized your database incorrectly. Delete the
186
+ Docker storage volume and initialize the database from scratch.
187
+
188
+ :::
189
+
154
190
</TabItem >
155
191
<TabItem value = " sqlite" >
156
192
193
+ No additional step is required for SQLite. The migrator will create the database file if it doesn't
194
+ exist.
195
+
157
196
:::tip[ Confirm your database path!]
158
197
159
- The migrator creates the database file if it doesn't exist, but it does not create folders. If you
160
- get an error that the path doesn't exist, double check that the path exists and that the folder
161
- containing the sqlite database has write and/or create permissions.
198
+ The migrator does not create folders. If you get an error that the path doesn't exist, double check
199
+ that the path exists and that the folder containing the sqlite database has write and/or create
200
+ permissions.
162
201
163
202
:::
164
203
165
204
</TabItem >
166
205
</Tabs >
167
206
168
- ### Migrations
207
+ :::tip[ Start all containers at once]
208
+
209
+ Use the ` ef ` profile to start all EntityFramework database containers at once:
210
+
211
+ ``` bash
212
+ docker compose --profile ef up
213
+ ```
214
+
215
+ :::
216
+
217
+ ### Run migrations
218
+
219
+ In the ` dev ` folder, run the following command to update the database to the latest migration:
169
220
170
221
<Tabs
171
222
groupId = " provider"
172
223
values = { providers } >
173
224
<TabItem value = " postgres" >
174
225
175
- In the ` dev ` folder run the following to update the database to the latest migration
176
-
177
226
``` bash
178
227
pwsh migrate.ps1 -postgres
179
228
```
180
229
181
- The ` -postgres ` flag on ` migrate.ps1 ` runs ` dotnet ef ` commands to perform the migrations.
182
-
183
230
</TabItem >
184
231
<TabItem value = " mysql" >
185
232
186
- In the ` dev ` folder run the following to update the database to the latest migration
187
-
188
233
``` bash
189
234
pwsh migrate.ps1 -mysql
190
235
```
191
236
192
- The ` -mysql ` flag on ` migrate.ps1 ` runs ` dotnet ef ` commands to perform the migrations.
237
+ </TabItem >
238
+ <TabItem value = " mariadb" >
239
+
240
+ ``` bash
241
+ pwsh migrate.ps1 -mariadb
242
+ ```
193
243
194
244
</TabItem >
195
245
<TabItem value = " sqlite" >
196
246
197
- In the ` dev ` folder run the following to update the database to the latest migration
198
-
199
247
``` bash
200
248
pwsh migrate.ps1 -sqlite
201
249
```
202
250
203
- The ` -sqlite ` flag on ` migrate.ps1 ` runs ` dotnet ef ` commands to perform the migrations.
204
-
205
251
:::note
206
252
207
253
The migrator creates the database file if it doesn't exist, but it does not create folders. If you
@@ -212,13 +258,7 @@ get an error that the path doesn't exist, it's referring to missing folders.
212
258
</TabItem >
213
259
</Tabs >
214
260
215
- You can also run migrations for all database providers at once using
216
-
217
- ``` bash
218
- pwsh migrate.ps1 -all
219
- ```
220
-
221
- ### Verifying changes
261
+ ### Verify changes
222
262
223
263
If you would like to verify that everything worked correctly:
224
264
@@ -227,26 +267,46 @@ If you would like to verify that everything worked correctly:
227
267
- Note: this requires a configured MSSQL database. You may also need to set up other EF providers
228
268
for tests to pass.
229
269
230
- ## Testing changes
270
+ ## Database integration tests
271
+
272
+ Database integration tests run for each database provider for both Dapper (MSSQL) and Entity
273
+ Framework. Developers are not expected to manually test each database provider. Instead, use
274
+ integration tests to ensure correctness across all supported databases.
275
+
276
+ Integration tests have their own connection strings, so that you can use separate databases to the
277
+ one used by your local development server. This is recommended because integration tests produce a
278
+ lot of test data over time. In the example below, this is done by using ` vault_test ` as the database
279
+ name.
280
+
281
+ ### Configuring test databases
231
282
232
- In your ` server/dev/ secrets.json ` file find or add this block of secrets in the root of the json
233
- structure :
283
+ 1 . In your user secrets, find or add this block of secrets in the root of the json structure
284
+ ( ** not ** in ` GlobalSettings ` ) :
234
285
235
286
```
236
287
"databases:0:type": "Postgres",
237
- "databases:0:connectionString": "Host=localhost;Username=postgres;Password=_________;Database=ef_test ",
288
+ "databases:0:connectionString": "Host=localhost;Username=postgres;Password=_________;Database=vault_test ",
238
289
"databases:0:enabled": "true",
239
290
"databases:1:type": "Sqlite",
240
291
"databases:1:enabled": "true",
241
292
"databases:1:connectionString": "Data Source=_________",
242
293
"databases:2:type": "MySql",
243
- "databases:2:connectionString": "server=localhost;uid=root;pwd=_________;database=ef_test ",
294
+ "databases:2:connectionString": "server=localhost;uid=root;pwd=_________;database=vault_test ",
244
295
"databases:2:enabled": "true",
245
296
"databases:3:type": "SqlServer",
246
- "databases:3:connectionString": "Server=localhost;Database=ef_test ;User Id=SA;Password=_________;Encrypt=True;TrustServerCertificate=True;",
297
+ "databases:3:connectionString": "Server=localhost;Database=vault_test ;User Id=SA;Password=_________;Encrypt=True;TrustServerCertificate=True;",
247
298
"databases:3:enabled": "true"
299
+ "databases:4:type": "MySql",
300
+ "databases:4:connectionString": "server=localhost;port=4306;uid=maria;pwd=_________;database=vault_test;AllowUserVariables=true",
301
+ "databases:4:enabled": "true",
248
302
```
249
303
304
+ :::note
305
+
306
+ The second MySql entry refers to MariaDB.
307
+
308
+ :::
309
+
250
310
:::info
251
311
252
312
The example database index + type combinations are required for the tooling to work, and to support
@@ -255,16 +315,33 @@ multiple versions of the same database running tests at the same time.
255
315
:::
256
316
257
317
This block is used for test databases for each supported provider type. These are what integration
258
- tests will connect to. You should update the password for these connection strings to match your
259
- existing databases if you have not already. If these settings are not present at all in your
260
- ` server/dev/secrets.json ` file just add them to the bottom. These settings _ do not_ go in
261
- ` globalSettings ` . Then run ` pwsh setup_secrets.ps1 -clear ` to apply them to your local projects.
318
+ tests will connect to. Make sure that you fill in the password for each connection string.
319
+
320
+ 2 . Run ` pwsh setup_secrets.ps1 -clear ` to apply the updated user secrets to your local projects.
321
+
322
+ 3 . Ensure your databases are all migrated (see instructions above). You can use the ` -test ` flag to
323
+ only migrate the integration test databases, or ` -all ` to migrate everything.
324
+
325
+ ```
326
+ # Migrate a specific integration test database (used by tests)
327
+ pwsh migrate.ps1 -postgres -test
328
+
329
+ # Migrate a specific development database (used by your local server)
330
+ pwsh migrate.ps1 -postgres
331
+
332
+ # Migrate all local databases
333
+ pwsh migrate.ps1 -all
334
+ ```
335
+
336
+ 4 . Run integration tests from the ` test/Infrastructure.IntegrationTest ` folder using ` dotnet test ` .
337
+
338
+ ### Writing integration tests
262
339
263
- With connection strings applied to your projects: ensure your databases are all migrated using
264
- ` pwsh server/dev/migrate.ps1 --all ` . Then you can run EF tests from the
265
- ` test/Infrastructure.IntegrationTest ` folder using ` dotnet test ` .
340
+ See
341
+ [ Contributing - Database Integration Testing ] ( ../../../../contributing/testing/database/index.md )
342
+ for more information on testing utilities and patterns .
266
343
267
- # Modifying the database
344
+ ## Modifying the database
268
345
269
346
The process for modifying the database is described in
270
347
[ Migrations] ( ./../../../../contributing/database-migrations/ef.md ) .
0 commit comments