aboutsummaryrefslogtreecommitdiffstats
path: root/db/index.js
blob: 4142de33c89e575deaebe23c19b6cab6ab0a1215 (plain) (blame)
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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888 } /* Comment */
.highlight .err { color: #A61717; background-color: #E3D2D2 } /* Error */
.highlight .k { color: #080; font-weight: bold } /* Keyword */
.highlight .ch { color: #888 } /* Comment.Hashbang */
.highlight .cm { color: #888 } /* Comment.Multiline */
.highlight .cp { color: #C00; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888 } /* Comment.Single */
.highlight .cs { color: #C00; font-weight: bold; background-color: #FFF0F0 } /* Comment.Special */
.highlight .gd { color: #000; background-color: #FDD } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph 
const Sequelize = require("sequelize");
const conf = config.dbOptions;

db = new Sequelize(conf.database, conf.username, conf.password, {
  host: conf.host,
  dialect: conf.dialect,
  logging: false,
  dialectOptions: conf.dialectOptions
});

require("./models/accounts.js");
require("./models/invoices.js");
require("./models/keys.js");
require("./models/payments.js");
require("./models/users.js");

db["User"].hasMany(db["Account"], {
  as: "accounts",
  foreignKey: "user_id"
});

db["User"].hasMany(db["Invoice"], {
  as: "invoices",
  foreignKey: "user_id"
});

db["User"].hasMany(db["Key"], {
  as: "keys",
  foreignKey: "user_id"
});

db["User"].hasMany(db["Payment"], {
  as: "payments",
  foreignKey: "user_id"
});

db["User"].belongsTo(db["Account"], {
  as: "account",
  foreignKey: "account_id"
});

db["Account"].belongsTo(db["User"], {
  as: "user",
  foreignKey: "user_id"
});

db["Invoice"].belongsTo(db["User"], {
  as: "user",
  foreignKey: "user_id"
});

db["Key"].belongsTo(db["User"], {
  as: "user",
  foreignKey: "user_id"
});

db["Payment"].belongsTo(db["Account"], {
  as: "account",
  foreignKey: "account_id"
});

db["Payment"].belongsTo(db["User"], {
  as: "user",
  foreignKey: "user_id"
});