forked from ddd-by-examples/library-nestjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset-db.js
42 lines (34 loc) · 954 Bytes
/
reset-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
41
42
const Knex = require('knex')
// You can dynamically pass the database name
// as a command-line argument, or obtain it from
// a .env file
const databaseName = 'lib1';
const connection = {
host: 'localhost',
user: 'postgres',
password: 'postgres',
port: 5432,
ssl: false,
};
async function main() {
let knex = Knex({
client: 'pg',
connection
});
await knex.raw('DROP DATABASE IF EXISTS ?? ', databaseName)
// Lets create our database if it does not exist
await knex.raw('CREATE DATABASE ?? ', databaseName)
// Now that our database is known, let's create another knex object
// with database name specified so that we can run our migrations
// knex = Knex({
// client: 'pg',
// connection: {
// ...connection,
// database: databaseName,
// }
// });
// Now we can happily run our migrations
// await knex.migrate.latest();
// Done!!
}
main().catch(console.log).then(process.exit);