aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/normalized/README.md41
-rw-r--r--db/normalized/accounts.js55
-rw-r--r--db/normalized/assets.js27
-rw-r--r--db/normalized/codes.js27
-rw-r--r--db/normalized/currencies.js27
-rw-r--r--db/normalized/deposits.js45
-rw-r--r--db/normalized/institutions.js32
-rw-r--r--db/normalized/networks.js32
-rw-r--r--db/normalized/non_custodial_accounts.js69
-rw-r--r--db/normalized/payments.js51
-rw-r--r--db/normalized/referrals.js76
-rw-r--r--db/normalized/user_keys.js47
-rw-r--r--db/normalized/user_preferences.js60
-rw-r--r--db/normalized/user_subscriptions.js28
-rw-r--r--db/normalized/users.js201
-rw-r--r--db/normalized/waiting_list.js48
-rw-r--r--db/normalized/withdrawals.js54
17 files changed, 920 insertions, 0 deletions
diff --git a/db/normalized/README.md b/db/normalized/README.md
new file mode 100644
index 00000000..30228cbb
--- /dev/null
+++ b/db/normalized/README.md
@@ -0,0 +1,41 @@
+# General guidelines for Database schema:
+
+- Some 1-1 tables are split up simply to separate scope or to control access permission (ie only user_preferences table may be edited by users themselves)
+
+- String fields which have a finite number of options should be changed to either:
+ - an FK to a separate lookup table (when the options is large or can grow)
+ - an enum (when there are a short list of essentailly static options)
+
+- Field names should follow SQL standards:
+ - lower case
+ - underscore_separated_words
+
+- options should be standardized with:
+ {
+ tableName: "table_name",
+ comment: "description of table if not self-evident",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {}
+ ]
+ };
+ - note createdAt, updatedAt are renamed to abide by SQL standard.
+
+ - by default allowNull is false, so this attribute need only be specified when fields are NOT NULL.
+
+ - comment attribute should added to any field that is not self-evident
+
+ - may need to add indexes to more fields for rapid access
+
+ ## Questions:
+ - Are indexes automatically generated for primary keys and/or foreign keys ?
+ - Do we add non-unique indexes for data mining: eg { fields: ['username'] }
+ - Do timestamp fields require default value spec (eg Sequelize.NOW) ?
+
+ - payments table needs to be investigated
+ - is invoices required or just summary information ?
+ - need to add orders table
+ - need to add subscriptions table if applicable (?)
+
diff --git a/db/normalized/accounts.js b/db/normalized/accounts.js
new file mode 100644
index 00000000..7eabaaa0
--- /dev/null
+++ b/db/normalized/accounts.js
@@ -0,0 +1,55 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ uuid: {
+ type: DataTypes.STRING(255),
+ allowNull: false,
+ comment: "unique UUID as more secure reference"
+ },
+ user_id: {
+ type: DataTypes.INTEGER(11),
+ references: { model: User, key: 'id' },
+ allowNull: false,
+ comment: "Referral granted to this user (updated when token used)"
+ },
+ asset_id: {
+ type: DataTypes.INTEGER(11),
+ references: { model: Asset, key: 'code' },
+ allowNull: false,
+ comment: "Reference to asset"
+ },
+ balance: {
+ type: DataTypes.DOUBLE,
+ allowNull: false
+ },
+ pending: {
+ type: DataTypes.DOUBLE,
+ allowNull: false,
+ comment: "What is this ?"
+ },
+ precision: {
+ type: DataTypes.INTEGER(11),
+ comment: "what is this for ? ... is it unique for each account ?"
+ }
+}
+const options = {
+ tableName: "accounts",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {
+ unique: true,
+ fields: ['uuid']
+ }
+ ]
+};
+
+db["Account"] = db.define("accounts_model", attributes, options);
diff --git a/db/normalized/assets.js b/db/normalized/assets.js
new file mode 100644
index 00000000..63866b4f
--- /dev/null
+++ b/db/normalized/assets.js
@@ -0,0 +1,27 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ code: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ allowNull: false
+ },
+ name: {
+ type: DataTypes.STRING(255)
+ }
+}
+const options = {
+ tableName: "assets",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {
+ unique: true,
+ fields: ['code']
+ }
+ ]
+};
+
+db["Asset"] = db.define("assets_model", attributes, options);
diff --git a/db/normalized/codes.js b/db/normalized/codes.js
new file mode 100644
index 00000000..956fe56a
--- /dev/null
+++ b/db/normalized/codes.js
@@ -0,0 +1,27 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ code: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ allowNull: false
+ },
+ name: {
+ type: DataTypes.STRING(255)
+ }
+}
+const options = {
+ tableName: "codes",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {
+ unique: true,
+ fields: ['code']
+ }
+ ]
+};
+
+db["Code"] = db.define("codes_model", attributes, options);
diff --git a/db/normalized/currencies.js b/db/normalized/currencies.js
new file mode 100644
index 00000000..57260f50
--- /dev/null
+++ b/db/normalized/currencies.js
@@ -0,0 +1,27 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ code: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ allowNull: false
+ },
+ name: {
+ type: DataTypes.STRING(255)
+ }
+}
+const options = {
+ tableName: "currencies",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {
+ unique: true,
+ fields: ['code']
+ }
+ ]
+};
+
+db["Currency"] = db.define("currencies_model", attributes, options);
diff --git a/db/normalized/deposits.js b/db/normalized/deposits.js
new file mode 100644
index 00000000..7259abc2
--- /dev/null
+++ b/db/normalized/deposits.js
@@ -0,0 +1,45 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ user_id: {
+ type: DataTypes.INTEGER(11),
+ references: { model: User, key: 'id' },
+ allowNull: false,
+ comment: "Referral granted to this user (updated when token used)"
+ },
+ amount: {
+ type: DataTypes.DECIMAL(10,2),
+ allowNull: false
+ },
+ code: {
+ // is this unique ?
+ type: DataTypes.STRING(255)
+ },
+ status: {
+ type: DataTypes.ENUM,
+ values: ['pending', 'credited', 'failed'],
+ defaultValue: 'pending'
+ }
+}
+
+const options = {
+ tableName: "deposits",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {
+ unique: true,
+ fields: ['code']
+ }
+ ]
+};
+
+db["Deposit"] = db.define("deposits_model", attributes, options);
diff --git a/db/normalized/institutions.js b/db/normalized/institutions.js
new file mode 100644
index 00000000..371fab06
--- /dev/null
+++ b/db/normalized/institutions.js
@@ -0,0 +1,32 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ name: {
+ type: DataTypes.STRING(255),
+ allowNull: false
+ },
+ code: {
+ type: DataTypes.STRING(255)
+ }
+}
+const options = {
+ tableName: "institutions",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {
+ unique: true,
+ fields: ['name', 'code']
+ }
+ ]
+};
+
+db["Institution"] = db.define("institutions_model", attributes, options);
diff --git a/db/normalized/networks.js b/db/normalized/networks.js
new file mode 100644
index 00000000..f08880fd
--- /dev/null
+++ b/db/normalized/networks.js
@@ -0,0 +1,32 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ name: {
+ type: DataTypes.STRING(255),
+ allowNull: false
+ },
+ code: {
+ type: DataTypes.STRING(255)
+ }
+}
+const options = {
+ tableName: "networks",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {
+ unique: true,
+ fields: ['name', 'code']
+ }
+ ]
+};
+
+db["Network"] = db.define("networks_model", attributes, options);
diff --git a/db/normalized/non_custodial_accounts.js b/db/normalized/non_custodial_accounts.js
new file mode 100644
index 00000000..0f95d59d
--- /dev/null
+++ b/db/normalized/non_custodial_accounts.js
@@ -0,0 +1,69 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ account_id: {
+ type: DataTypes.INTEGER(11),
+ references: { model: Account, key: 'id' },
+ allowNull: false,
+ comment: "Reference to account"
+ },
+ path: {
+ type: DataTypes.STRING(255),
+ comment: "What is this ?"
+ },
+ seed: {
+ type: DataTypes.STRING(255),
+ comment: "What is this ?"
+ },
+ network: {
+ type: DataTypes.INTEGER(11),
+ references: { model: Network, key: 'id' },
+ allowNull: false,
+ comment: "Reference to network"
+ },
+ domain: {
+ type: DataTypes.STRING(255),
+ comment: "What is this ? ... is it unique or an enum ?"
+ },
+ ticker: {
+ type: DataTypes.STRING(255),
+ comment: "What is this ?"
+ },
+ hide: {
+ type: DataTypes.STRING(255),
+ comment: "What is this ?"
+ },
+ index: {
+ type: DataTypes.STRING(255),
+ comment: "What is this ?"
+ },
+ pub_key: {
+ type: DataTypes.STRING(255),
+ comment: "What is this ?"
+ },
+ priv_key: {
+ type: DataTypes.STRING(255),
+ comment: "What is this ?"
+ }
+}
+const options = {
+ tableName: "non_custodial_accounts",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {
+ unique: true,
+ fields: ['account_id']
+ }
+ ]
+};
+
+db["NonCustodialAccount"] = db.define("non_custodial_accounts_model", attributes, options);
diff --git a/db/normalized/payments.js b/db/normalized/payments.js
new file mode 100644
index 00000000..7d501f20
--- /dev/null
+++ b/db/normalized/payments.js
@@ -0,0 +1,51 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ account_id: {
+ type: DataTypes.INTEGER(11),
+ references: { model: Account, key: 'id' },
+ allowNull: true,
+ comment: "Reference to account"
+ },
+ amount: {
+ type: DataTypes.DOUBLE,
+ allowNull: false
+ },
+ path: {
+ type: DataTypes.STRING(255),
+ comment: "What is this ?"
+ },
+ memo: {
+ type: DataTypes.TEXT,
+ comment: "What is this ?"
+ },
+ hash: {
+ type: DataTypes.TEXT,
+ comment: "What is this ?"
+ },
+ precision: {
+ type: DataTypes.INTEGER(11),
+ comment: "what is this for ? ... is it unique for each account ?"
+ }
+}
+const options = {
+ tableName: "payments",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {
+ unique: true,
+ fields: ['uuid']
+ }
+ ]
+};
+
+db["Payment"] = db.define("payments_model", attributes, options);
diff --git a/db/normalized/referrals.js b/db/normalized/referrals.js
new file mode 100644
index 00000000..5b93ba3f
--- /dev/null
+++ b/db/normalized/referrals.js
@@ -0,0 +1,76 @@
+const { DataTypes } = require('sequelize/types');
+const config = require('./../config')
+const dbc = require('knex')(config.knex)
+
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ sponsor_id: {
+ type: DataTypes.INTEGER(11),
+ references: { model: User, key: 'id' },
+ allowNull: false,
+ comment: "Referral made by this user"
+ },
+ user_id: {
+ type: DataTypes.INTEGER(11),
+ references: { model: User, key: 'id' },
+ allowNull: true,
+ comment: "Referral granted to this user (updated when token used)"
+ },
+ expiry: {
+ type: Sequelize.DATE
+ },
+ status: {
+ type: DataTypes.ENUM,
+ values: ['pending', 'active', 'expired', 'cancelled'],
+ defaultValue: 'pending'
+ }
+}
+
+
+const options = {
+ tableName: "referrals",
+ comment: "Referrals - unique record for each sponsor / user_id",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ // are FK fields automatically indexed ? ... if not add sponsor_id
+ {
+ unique: true,
+ fields: ['user_id']
+ }
+ ]
+};
+
+db["Referral"] = db.define("referrals_model", attributes, options);
+
+// const config = require('./../config')
+// const dbc = require('knex')(config.knex)
+
+// dbc.schema.createTable('referrals', function (table) {
+// table.increments();
+
+// table.string('token')
+// table.date('expiry')
+// table.enu('status', ['active', 'expired', 'closed'])
+
+// table.dateTime('created_at').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP'))
+// table.dateTime('updated_at').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'))
+// })
+
+// dbc.schema.createTable('waiting_list', function (table) {
+// table.increments();
+
+// table.string('email')
+// table.enu('status', ['pending', 'activated', 'cancelled']).defaultTo('pending')
+
+// table.dateTime('created_at').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP'))
+// table.dateTime('updated_at').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'))
+// }) \ No newline at end of file
diff --git a/db/normalized/user_keys.js b/db/normalized/user_keys.js
new file mode 100644
index 00000000..0d84b742
--- /dev/null
+++ b/db/normalized/user_keys.js
@@ -0,0 +1,47 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ user_id: {
+ type: DataTypes.INTEGER(11),
+ references: { model: User, key: 'id' },
+ allowNull: false,
+ comment: "Referral granted to this user (updated when token used)"
+ },
+ otpsecret: {
+ type: DataTypes.STRING(255),
+ comment: "Used for ... ?",
+ },
+ pin: {
+ type: DataTypes.STRING(255),
+ comment: "Used for ... ?
+ },
+ seed: {
+ type: DataTypes.STRING(255),
+ comment: "Used for ... ?
+ },
+ ip: {
+ type: DataTypes.STRING(255),
+ comment: "Used for ... ?
+ },
+ index: {
+ type: DataTypes.STRING(255),
+ comment: "Used for ... ?
+ }
+}
+const options = {
+ tableName: "user_keys",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ ]
+};
+
+db["UserKey"] = db.define("user_keys_model", attributes, options);
diff --git a/db/normalized/user_preferences.js b/db/normalized/user_preferences.js
new file mode 100644
index 00000000..9864f4eb
--- /dev/null
+++ b/db/normalized/user_preferences.js
@@ -0,0 +1,60 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ user_id: {
+ type: DataTypes.INTEGER(11),
+ references: { model: User, key: 'id' },
+ allowNull: false,
+ comment: "Referral granted to this user (updated when token used)"
+ },
+ username: {
+ type: DataTypes.STRING(255),
+ allowNull: false,
+ },
+ gravitar: {
+ type: DataTypes.STRING(255),
+ },
+ fiat: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: true,
+ allowNull: false,
+ comment: "What is this for ?"
+ },
+ default_crypto_unit: {
+ type: DataTypes.ENUM,
+ values: ['SAT', 'BTC'],
+ defaultValue: 'SAT',
+ allowNull: false
+ },
+ default_currency_code: {
+ type: DataTypes.INTEGER(11),
+ references: { model: Currency, key: 'code' },
+ defaultValue: "CAD",
+ allowNull: false
+ },
+ currencies: {
+ type: DataTypes.JSON,
+ allowNull: false,
+ defaultValue: ["USD"],
+ comment: "List of currency options to show for this user",
+ }
+}
+
+const options = {
+ tableName: "user_preferences",
+ comment: "settings that can be controlled by users themselves",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {fields: ['user_id']}
+ ]
+};
+
+db["UserPreference"] = db.define("user_preferences_model", attributes, options);
diff --git a/db/normalized/user_subscriptions.js b/db/normalized/user_subscriptions.js
new file mode 100644
index 00000000..ba18d7c6
--- /dev/null
+++ b/db/normalized/user_subscriptions.js
@@ -0,0 +1,28 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ user_id: {
+ type: DataTypes.INTEGER(11),
+ references: { model: User, key: 'id' },
+ allowNull: false,
+ comment: "Referral granted to this user (updated when token used)"
+ },
+}
+const options = {
+ tableName: "users",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {fields: ['uuid', 'email']}
+ ]
+};
+
+db["User"] = db.define("users_model", attributes, options);
diff --git a/db/normalized/users.js b/db/normalized/users.js
new file mode 100644
index 00000000..fb30a550
--- /dev/null
+++ b/db/normalized/users.js
@@ -0,0 +1,201 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ uuid: {
+ type: DataTypes.STRING(255),
+ allowNull: false,
+ comment: "unique UUID as more secure reference"
+ },
+ password: {
+ type: DataTypes.STRING(255), // Encrypted Password type ??
+ allowNull: false,
+ validate: {
+ len: [8, 255]
+ }
+ },
+ email: {
+ type: DataTypes.STRING(255),
+ validate: {
+ isEmail: true
+ }
+ },
+ sms: {
+ type: DataTypes.STRING(255),
+ validate: {
+ is: /^[0-9]+$/ // replace spaces, brackets, dashes dynamically prior to create
+ }
+ },
+ email_verified: {
+ type: DataTypes.BOOLEAN,
+ allowNull: false,
+ defaultValue: false,
+ },
+ sms_verified: {
+ type: DataTypes.BOOLEAN,
+ allowNull: false,
+ defaultValue: false,
+ }
+}
+
+const options = {
+ tableName: "users",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {fields: ['uuid', 'email']}
+ ]
+};
+
+db["User"] = db.define("users_model", attributes, options);
+
+
+ // *** Move to user_preferences ***
+// unit: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: 'SAT',
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "unit"
+// },
+// currency: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: "CAD",
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "currency"
+// },
+// currencies: {
+// type: DataTypes.JSON,
+// allowNull: false,
+// defaultValue: ["USD"],
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "currencies"
+// },
+
+// fiat: { ???
+// type: DataTypes.BOOLEAN,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "fiat"
+// },
+
+// ** Remove - redundant / unnecessary **
+// account_id: {
+// type: DataTypes.INTEGER(11),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "account_id"
+// },
+// twofa: { = otp_secret NOT NULL
+// type: DataTypes.INTEGER(1),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "twofa"
+// },
+
+// *** Move to user_keys ***
+
+// otpsecret: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: "CAD",
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "otpsecret"
+// },
+// pin: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "pin"
+// },
+// seed: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "seed"
+// },
+
+// ** What are these exactly ... ? **
+// ip: { ??
+// type: DataTypes.INTEGER.UNSIGNED,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "ip"
+// },
+
+// index: {
+// type: DataTypes.INTEGER,
+// allowNull: true,
+// defaultValue: 0,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "index"
+// },
+
+// };
+
+// *** Add breakout table
+// subscriptions: {
+// type: DataTypes.TEXT,
+// get: function() {
+// return JSON.parse(this.getDataValue("subscriptions"));
+// },
+// set: function(value) {
+// return this.setDataValue("subscriptions", JSON.stringify(value));
+// },
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "subscriptions"
+// },
+
+ // *** replaced with other field(s) ***
+ // locked: { - embed logic with user status (?)
+ // type: DataTypes.BOOLEAN,
+ // allowNull: true,
+ // defaultValue: false,
+ // primaryKey: false,
+ // autoIncrement: false,
+ // comment: null,
+ // field: "locked"
+ // },
+
+
+
diff --git a/db/normalized/waiting_list.js b/db/normalized/waiting_list.js
new file mode 100644
index 00000000..c849f34f
--- /dev/null
+++ b/db/normalized/waiting_list.js
@@ -0,0 +1,48 @@
+const { DataTypes } = require('sequelize/types');
+const config = require('./../config')
+const dbc = require('knex')(config.knex)
+
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ email: {
+ type: DataTypes.STRING(255),
+ validate: {
+ isEmail: true
+ }
+ },
+ sms: {
+ type: DataTypes.STRING(255),
+ validate: {
+ is: /^[0-9]+$/ // replace spaces, brackets, dashes dynamically prior to create
+ }
+ },
+ status: {
+ type: DataTypes.ENUM,
+ values: ['pending', 'activated', 'expired', 'cancelled'],
+ defaultValue: 'pending',
+ allowNull: false
+ }
+}
+
+const options = {
+ tableName: "waiting_list",
+ comment: "Users on waiting list",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ {
+ unique: true,
+ fields: ['email', 'sms']
+ }
+ ]
+};
+
+db["WaitingList"] = db.define("waiting_list_model", attributes, options);
diff --git a/db/normalized/withdrawals.js b/db/normalized/withdrawals.js
new file mode 100644
index 00000000..00be4299
--- /dev/null
+++ b/db/normalized/withdrawals.js
@@ -0,0 +1,54 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ primaryKey: true,
+ autoIncrement: true,
+ allowNull: false
+ },
+ user_id: {
+ type: DataTypes.INTEGER(11),
+ references: { model: User, key: 'id' },
+ allowNull: false,
+ comment: "Referral granted to this user (updated when token used)"
+ },
+ amount: {
+ type: DataTypes.DECIMAL(10,2),
+ allowNull: false
+ },
+ institution: {
+ type: DataTypes.INTEGER(11),
+ references: { model: Institution, key: 'id' },
+ allowNull: false,
+ comment: "Reference to bank institution"
+ },
+ transit: {
+ type: DataTypes.STRING(255),
+ allowNull: false
+ },
+ account: {
+ type: DataTypes.STRING(255),
+ allowNull: false
+ },
+ notes: {
+ type: DataTypes.TEXT
+ },
+ status: {
+ type: DataTypes.ENUM,
+ values: ['pending', 'debited', 'failed'],
+ defaultValue: 'pending'
+ }
+}
+
+const options = {
+ tableName: "withdrawals",
+ comment: "",
+ timestamps: true,
+ createdAt: 'created_at',
+ updatedAt: 'updated_at',
+ indexes: [
+ ]
+};
+
+db["Withdrawal"] = db.define("withdrawals_model", attributes, options);