-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmigrate.js
More file actions
37 lines (33 loc) · 969 Bytes
/
migrate.js
File metadata and controls
37 lines (33 loc) · 969 Bytes
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
// migrate.js
var r = require("rethinkdb");
r.connect(
{
host: process.env.RETHINKDB_HOST || "localhost",
port: process.env.RETHINKDB_PORT || 28015,
username: process.env.RETHINKDB_USERNAME || "admin",
password: process.env.RETHINKDB_PASSWORD || "",
db: process.env.RETHINKDB_NAME || "test",
},
function (err, conn) {
if (err) throw err;
r.tableList().run(conn, (err, cursor) => {
if (err) throw err;
cursor.toArray((err, tables) => {
if (err) throw err;
// Check if table exists
if (!tables.includes("chats")) {
// Table missing --> create
console.log("Creating chats table");
r.tableCreate("chats").run(conn, (err, _) => {
if (err) throw err;
console.log("Creating chats table -- done");
conn.close();
});
} else {
// Table exists --> exit
conn.close();
}
});
});
}
);