-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
46 lines (41 loc) · 910 Bytes
/
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
43
44
45
46
const Sequelize = require("sequelize");
const pkg = require("./package.json");
const chalk = require("chalk");
const dbName = process.env.NODE_ENV === "test" ? `${pkg.name}_test` : pkg.name;
console.log(chalk.yellow(`Opening database connection to ${dbName}`));
let db;
if (process.env.DATABASE_URL) {
//heroku configuration
db = new Sequelize(process.env.DATABASE_URL, {
logging: false,
dialect: "postgres",
protocol: "postgres",
ssl: true,
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false,
},
},
});
} else {
//local configuration
db = new Sequelize(`postgres://localhost:5432/${dbName}`, {
logging: false,
});
}
const Copy = db.define("copy", {
text: {
type: Sequelize.TEXT,
},
language: {
type: Sequelize.STRING,
},
image: {
type: Sequelize.STRING,
},
});
module.exports = {
db,
Copy,
};