@@ -9,14 +9,22 @@ import { afterAll } from 'vitest';
9
9
export async function createTestDb ( ) {
10
10
const systemClient = knex ( {
11
11
client : 'mysql2' ,
12
- connection : {
13
- host : process . env . MYSQL_HOST ,
14
- port : Number . parseInt ( process . env . MYSQL_PORT ! ) ,
15
- user : process . env . MYSQL_USER ,
16
- password : process . env . MYSQL_PASSWORD ,
17
- database : 'mysql' ,
18
- timezone : '+00:00' ,
19
- } ,
12
+ connection : process . env . MYSQL_SOCKET_PATH
13
+ ? {
14
+ socketPath : process . env . MYSQL_SOCKET_PATH ,
15
+ user : process . env . MYSQL_USER ,
16
+ password : process . env . MYSQL_PASSWORD ,
17
+ database : process . env . MYSQL_DATABASE ,
18
+ timezone : '+00:00' ,
19
+ }
20
+ : {
21
+ host : process . env . MYSQL_HOST ,
22
+ port : Number . parseInt ( process . env . MYSQL_PORT ! ) ,
23
+ user : process . env . MYSQL_USER ,
24
+ password : process . env . MYSQL_PASSWORD ,
25
+ database : process . env . MYSQL_DATABASE ,
26
+ timezone : '+00:00' ,
27
+ } ,
20
28
} ) ;
21
29
22
30
const dbName = `test_${ randomBytes ( 16 ) . toString ( 'hex' ) } ` ;
@@ -30,22 +38,30 @@ export async function createTestDb() {
30
38
// Clone each table structure
31
39
for ( const { TABLE_NAME } of tables [ 0 ] ) {
32
40
await systemClient . raw (
33
- `CREATE TABLE ${ dbName } .${ TABLE_NAME } LIKE ${ process . env . MYSQL_DATABASE } .${ TABLE_NAME } ` ,
41
+ `CREATE TABLE ${ dbName } .${ TABLE_NAME } LIKE \` ${ process . env . MYSQL_DATABASE } \` .${ TABLE_NAME } ` ,
34
42
) ;
35
43
}
36
44
37
45
await systemClient . destroy ( ) ;
38
46
39
47
const dbClient = knex ( {
40
48
client : 'mysql2' ,
41
- connection : {
42
- host : process . env . MYSQL_HOST ,
43
- port : Number . parseInt ( process . env . MYSQL_PORT ! ) ,
44
- user : process . env . MYSQL_USER ,
45
- password : process . env . MYSQL_PASSWORD ,
46
- database : dbName ,
47
- timezone : '+00:00' ,
48
- } ,
49
+ connection : process . env . MYSQL_SOCKET_PATH
50
+ ? {
51
+ socketPath : process . env . MYSQL_SOCKET_PATH ,
52
+ user : process . env . MYSQL_USER ,
53
+ password : process . env . MYSQL_PASSWORD ,
54
+ database : process . env . MYSQL_DATABASE ,
55
+ timezone : '+00:00' ,
56
+ }
57
+ : {
58
+ host : process . env . MYSQL_HOST ,
59
+ port : Number . parseInt ( process . env . MYSQL_PORT ! ) ,
60
+ user : process . env . MYSQL_USER ,
61
+ password : process . env . MYSQL_PASSWORD ,
62
+ database : process . env . MYSQL_DATABASE ,
63
+ timezone : '+00:00' ,
64
+ } ,
49
65
} ) ;
50
66
51
67
afterAll ( async ( ) => {
0 commit comments