forked from Vincit/objection.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-test-db.js
executable file
·40 lines (34 loc) · 911 Bytes
/
setup-test-db.js
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
const knex = require('knex');
const postgres = knex({
client: 'postgres',
connection: {
user: 'postgres',
host: 'localhost',
database: 'postgres'
}
});
const mysql = knex({
client: 'mysql',
connection: {
user: 'root',
host: 'localhost'
}
});
[
postgres.raw('DROP DATABASE IF EXISTS objection_test'),
postgres.raw('DROP USER IF EXISTS objection'),
postgres.raw('CREATE USER objection SUPERUSER'),
postgres.raw('CREATE DATABASE objection_test'),
mysql.raw('DROP DATABASE IF EXISTS objection_test'),
mysql.raw('DROP USER IF EXISTS objection'),
mysql.raw('CREATE USER objection'),
mysql.raw('GRANT ALL PRIVILEGES ON *.* TO objection'),
mysql.raw('CREATE DATABASE objection_test')
].reduce((promise, query) => {
return promise.then(() => query);
}, Promise.resolve()).then(() => {
return Promise.all([
postgres.destroy(),
mysql.destroy()
]);
});