aboutsummaryrefslogtreecommitdiffstats
path: root/db/normalized
diff options
context:
space:
mode:
Diffstat (limited to 'db/normalized')
-rw-r--r--db/normalized/accounts.js276
-rw-r--r--db/normalized/bank_accounts.js24
-rw-r--r--db/normalized/codes.js27
-rw-r--r--db/normalized/credits.js236
-rw-r--r--db/normalized/currencies.js27
-rw-r--r--db/normalized/debits.js236
-rw-r--r--db/normalized/deposits.js135
-rw-r--r--db/normalized/exchanges.js232
-rw-r--r--db/normalized/institutions.js32
-rw-r--r--db/normalized/invoices.js206
-rw-r--r--db/normalized/liquid_assets.js21
-rw-r--r--db/normalized/ln_assets.js34
-rw-r--r--db/normalized/ln_keys.js16
-rw-r--r--db/normalized/lnurl_codes.js14
-rw-r--r--db/normalized/networks.js32
-rw-r--r--db/normalized/non_custodial_accounts.js153
-rw-r--r--db/normalized/orders.js30
-rw-r--r--db/normalized/payments.js51
-rw-r--r--db/normalized/referrals.js88
-rw-r--r--db/normalized/transactions.js41
-rw-r--r--db/normalized/transfers.js243
-rw-r--r--db/normalized/user_keys.js47
-rw-r--r--db/normalized/user_preferences.js72
-rw-r--r--db/normalized/user_security.js21
-rw-r--r--db/normalized/user_subscriptions.js28
-rw-r--r--db/normalized/users.js216
-rw-r--r--db/normalized/vouchers.js18
-rw-r--r--db/normalized/waiting_list.js94
-rw-r--r--db/normalized/withdrawals.js172
29 files changed, 1968 insertions, 854 deletions
diff --git a/db/normalized/accounts.js b/db/normalized/accounts.js
index 36e332d7..d09f2dcf 100644
--- a/db/normalized/accounts.js
+++ b/db/normalized/accounts.js
@@ -1,56 +1,228 @@
-const { DataTypes } = require('sequelize');
+exports.up = function(knex) {
+ return knex.schema.createTable('accounts', function(t) {
+ t.increments('id').unsigned().primary();
+ t.int('user_id').notNull();
+ t.foreign('user_id').references('users.id');
-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: {
- type: DataTypes.STRING,
- allowNull: false,
- comment: "Reference to liquid asset on liquid blockchain"
- },
- balance: {
- type: DataTypes.DOUBLE,
- allowNull: false
- },
- pending: {
- type: DataTypes.DOUBLE,
- allowNull: false,
- comment: "Pending balance indicates that the transaction has been detected on the blockchain but not confirmed"
- },
- /* DEPRECATED
- precision: {
- type: DataTypes.INTEGER(11),
- comment: "The decimal precision for the liquid asset "
- }
- */
+ t.int('uuid').notNull();
+
+ t.double('balance');
+ t.double('pending');
+
+ t.enu('network', ['Bitcoin', 'Liquid', 'Lightning', 'CoinOS']).notNull();
+
+ // t.string('contract');
+ // t.string('hide');
+ // t.string('index');
+
+ t.int('liquid_asset_id').notNull();
+ t.foreign('liquid_asset_id').references('liquid_assets.id');
+
+ t.timestamps();
+ })
}
-const options = {
- tableName: "accounts",
- comment: "",
- timestamps: true,
- createdAt: 'created_at',
- updatedAt: 'updated_at',
- indexes: [
- {
- unique: true,
- fields: ['uuid']
- }
- ]
+
+exports.down = function(knex) {
+ return knex.schema.dropTable('accounts');
};
-db["Account"] = db.define("accounts_model", attributes, options);
+// Change
+//
+// move assets fields (asset, ticker, name, precision...) to separate liquid_assets reference
+
+// separate network specific fields to bitcoin_accounts / liquid_accounts / coinos_accounts tables ? or just non_custodial ?
+// eg liquid -> liquid_asset info
+// non-custodial ? -> privkey, pubkey, path, seed ?
+// contract, hide, index ?
+//
+
+
+// const { DataTypes } = require('sequelize');
+
+// const attributes = {
+// id: {
+// type: DataTypes.INTEGER(11),
+// allowNull: false,
+// defaultValue: null,
+// primaryKey: true,
+// autoIncrement: true,
+// comment: null,
+// field: "id"
+// },
+// user_id: {
+// type: DataTypes.INTEGER(11),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "user_id"
+// },
+// createdAt: {
+// type: DataTypes.DATE,
+// allowNull: false,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "createdAt"
+// },
+// updatedAt: {
+// type: DataTypes.DATE,
+// allowNull: false,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "updatedAt"
+// },
+// path: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "path"
+// },
+// seed: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "seed"
+// },
+// network: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "network"
+// },
+// name: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "name"
+// },
+// contract: {
+// type: DataTypes.TEXT,
+// get: function() {
+// return JSON.parse(this.getDataValue("contract"));
+// },
+// set: function(value) {
+// return this.setDataValue("contract", JSON.stringify(value));
+// },
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "contract"
+// },
+// domain: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "domain"
+// },
+// ticker: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "ticker"
+// },
+// asset: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "asset"
+// },
+// balance: {
+// type: DataTypes.DOUBLE,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "balance"
+// },
+// pending: {
+// type: DataTypes.DOUBLE,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "pending"
+// },
+// hide: {
+// type: DataTypes.BOOLEAN,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "hide"
+// },
+// index: {
+// type: DataTypes.INTEGER(11),
+// allowNull: false,
+// defaultValue: 0,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "index"
+// },
+// privkey: {
+// type: DataTypes.STRING,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "privkey"
+// },
+// pubkey: {
+// type: DataTypes.STRING,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "pubkey"
+// },
+// precision: {
+// type: DataTypes.INTEGER(11),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "precision"
+// },
+// };
+
+// const options = {
+// tableName: "accounts",
+// comment: "",
+// indexes: []
+// };
+
+// db["Account"] = db.define("accounts_model", attributes, options);
diff --git a/db/normalized/bank_accounts.js b/db/normalized/bank_accounts.js
new file mode 100644
index 00000000..3877ffd3
--- /dev/null
+++ b/db/normalized/bank_accounts.js
@@ -0,0 +1,24 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('bank_accounts', function(t) {
+ t.increments('id').unsigned().primary();
+ t.int('user_id').notNull();
+ t.foreign('user_id').references('users.id');
+
+ t.int('transit_number');
+ t.int('institution_number');
+ t.int('account_number');
+
+ t.string('swift');
+ t.string('iban');
+
+ t.timestamps();
+ })
+}
+
+exports.down = function(knex) {
+ return knex.schema.dropTable('user_security');
+};
+
+// Changes:
+//
+// bank info -> bank_account records
diff --git a/db/normalized/codes.js b/db/normalized/codes.js
deleted file mode 100644
index 956fe56a..00000000
--- a/db/normalized/codes.js
+++ /dev/null
@@ -1,27 +0,0 @@
-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/credits.js b/db/normalized/credits.js
new file mode 100644
index 00000000..8b8dd5ea
--- /dev/null
+++ b/db/normalized/credits.js
@@ -0,0 +1,236 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('credits', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.enu('type', ['deposit', 'order', 'transfer', 'invoice', 'exchange'])
+ t.string('description')
+
+ t.int('account_id').notNull();
+ t.foreign('account_id').references('accounts.id');
+
+ t.double('amount');
+
+ t.enu('status', ['pending', 'completed', 'reversed', 'cancelled'])
+
+ t.timestamps();
+ })
+};
+
+exports.down = function(knex) {
+return knex.schema.dropTable('credits');
+};
+
+// Changes:
+//
+// Should these be tracked as transactions ?
+// SAT -> SAT
+// tracking various exchange variations (outside of external networks ?)
+//
+// Is user / account / amount info redundant ?
+// + transaction_type: deposit / withdrawal / transfer / exchange ?
+//
+// add transfers table ? (for internal transfers only ?)
+// add redemptions table ? (for bitcoin transfers only ?)
+// add exchanges table ? (for conversion from one currency to another)
+//
+// network -> scope: internal / bitcoin / liquid / lightning ?
+// add bitcoin_transaction ? (with redemption attributes)
+// add liquid_transaction ? ()
+// add lightning_transaction ? (with LN_invoice_hash)
+// add internal_transaction ? ()
+//
+// context for path, memo, rate, preimage, address, received, fee, tip, confirmed, redeemcode ?
+
+
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: true,
+ autoIncrement: true,
+ comment: null,
+ field: "id"
+ },
+ account_id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "account_id"
+ },
+ user_id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "user_id"
+ },
+ path: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "path"
+ },
+ memo: {
+ type: DataTypes.TEXT,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "memo"
+ },
+ hash: {
+ type: DataTypes.TEXT,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "hash"
+ },
+ createdAt: {
+ type: DataTypes.DATE,
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "createdAt"
+ },
+ updatedAt: {
+ type: DataTypes.DATE,
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "updatedAt"
+ },
+ rate: {
+ type: DataTypes.DOUBLE,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "rate"
+ },
+ preimage: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "preimage"
+ },
+ network: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "network"
+ },
+ currency: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "currency"
+ },
+ address: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "address"
+ },
+ received: {
+ type: DataTypes.INTEGER(1),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "received"
+ },
+ amount: {
+ type: DataTypes.DOUBLE,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "amount"
+ },
+ fee: {
+ type: DataTypes.DOUBLE,
+ allowNull: false,
+ defaultValue: 0,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "fee"
+ },
+ tip: {
+ type: DataTypes.DOUBLE,
+ allowNull: false,
+ defaultValue: 0,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "tip"
+ },
+ redeemed: {
+ type: DataTypes.BOOLEAN,
+ allowNull: false,
+ defaultValue: false,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "redeemed"
+ },
+ redeemcode: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "redeemcode"
+ },
+ confirmed: {
+ type: DataTypes.INTEGER(1),
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "confirmed"
+ }
+};
+
+const options = {
+ tableName: "payments",
+ comment: "",
+ indexes: []
+};
+
+db["Payment"] = db.define("payments_model", attributes, options);
diff --git a/db/normalized/currencies.js b/db/normalized/currencies.js
deleted file mode 100644
index 57260f50..00000000
--- a/db/normalized/currencies.js
+++ /dev/null
@@ -1,27 +0,0 @@
-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/debits.js b/db/normalized/debits.js
new file mode 100644
index 00000000..1b65adc6
--- /dev/null
+++ b/db/normalized/debits.js
@@ -0,0 +1,236 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('debits', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.enu('type', ['withdrawal', 'order', 'transfer', 'invoice', 'exchange'])
+
+ t.int('account_id').notNull();
+ t.foreign('account_id').references('accounts.id');
+
+ t.double('amount');
+
+ t.enu('type', ['withdrawal', 'transfer', 'order', 'invoice'])
+ t.enu('status', ['pending', 'completed', 'reversed', 'cancelled'])
+
+ t.timestamps();
+ })
+};
+
+exports.down = function(knex) {
+return knex.schema.dropTable('debits');
+};
+
+// Changes:
+//
+// Should these be tracked as transactions ?
+// SAT -> SAT
+// tracking various exchange variations (outside of external networks ?)
+//
+// Is user / account / amount info redundant ?
+// + transaction_type: deposit / withdrawal / transfer / exchange ?
+//
+// add transfers table ? (for internal transfers only ?)
+// add redemptions table ? (for bitcoin transfers only ?)
+// add exchanges table ? (for conversion from one currency to another)
+//
+// network -> scope: internal / bitcoin / liquid / lightning ?
+// add bitcoin_transaction ? (with redemption attributes)
+// add liquid_transaction ? ()
+// add lightning_transaction ? (with LN_invoice_hash)
+// add internal_transaction ? ()
+//
+// context for path, memo, rate, preimage, address, received, fee, tip, confirmed, redeemcode ?
+
+
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: true,
+ autoIncrement: true,
+ comment: null,
+ field: "id"
+ },
+ account_id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "account_id"
+ },
+ user_id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "user_id"
+ },
+ path: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "path"
+ },
+ memo: {
+ type: DataTypes.TEXT,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "memo"
+ },
+ hash: {
+ type: DataTypes.TEXT,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "hash"
+ },
+ createdAt: {
+ type: DataTypes.DATE,
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "createdAt"
+ },
+ updatedAt: {
+ type: DataTypes.DATE,
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "updatedAt"
+ },
+ rate: {
+ type: DataTypes.DOUBLE,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "rate"
+ },
+ preimage: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "preimage"
+ },
+ network: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "network"
+ },
+ currency: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "currency"
+ },
+ address: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "address"
+ },
+ received: {
+ type: DataTypes.INTEGER(1),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "received"
+ },
+ amount: {
+ type: DataTypes.DOUBLE,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "amount"
+ },
+ fee: {
+ type: DataTypes.DOUBLE,
+ allowNull: false,
+ defaultValue: 0,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "fee"
+ },
+ tip: {
+ type: DataTypes.DOUBLE,
+ allowNull: false,
+ defaultValue: 0,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "tip"
+ },
+ redeemed: {
+ type: DataTypes.BOOLEAN,
+ allowNull: false,
+ defaultValue: false,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "redeemed"
+ },
+ redeemcode: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "redeemcode"
+ },
+ confirmed: {
+ type: DataTypes.INTEGER(1),
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "confirmed"
+ }
+};
+
+const options = {
+ tableName: "payments",
+ comment: "",
+ indexes: []
+};
+
+db["Payment"] = db.define("payments_model", attributes, options);
diff --git a/db/normalized/deposits.js b/db/normalized/deposits.js
index ec9472d8..c14884ce 100644
--- a/db/normalized/deposits.js
+++ b/db/normalized/deposits.js
@@ -1,45 +1,100 @@
-const { DataTypes } = require('sequelize');
+exports.up = function(knex) {
+ return knex.schema.createTable('deposits', function(t) {
+ t.increments('id').unsigned().primary();
-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
- },
- deposit_code: {
- type: DataTypes.STRING(255),
- comment: "Unique randomly generated code to be put in the interac deposit reference/message to link the deposit to this record/user",
- },
- status: {
- type: DataTypes.ENUM,
- values: ['pending', 'credited', 'failed'],
- defaultValue: 'pending'
- }
+ t.int('credit_id').notNull();
+ t.foreign('credit_id').references('credits.id');
+
+ t.string('confirmation_code');
+
+ t.timestamps();
+ })
}
-const options = {
- tableName: "deposits",
- comment: "",
- timestamps: true,
- createdAt: 'created_at',
- updatedAt: 'updated_at',
- indexes: [
- {
- unique: true,
- fields: ['code']
- }
- ]
+exports.down = function(knex) {
+ return knex.schema.dropTable('deposits');
};
-db["Deposit"] = db.define("deposits_model", attributes, options);
+// Changes:
+//
+// reference transaction
+// reference account rather than user
+// credited - redundant with confirmation_code ?
+// code -> confirmation_code
+
+
+// const { DataTypes } = require('sequelize');
+
+// const attributes = {
+// id: {
+// type: DataTypes.INTEGER(11),
+// allowNull: false,
+// defaultValue: null,
+// primaryKey: true,
+// autoIncrement: true,
+// comment: null,
+// field: "id"
+// },
+// amount: {
+// type: DataTypes.DOUBLE,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "amount"
+// },
+// user_id: {
+// type: DataTypes.INTEGER(11),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "user_id"
+// },
+// createdAt: {
+// type: DataTypes.DATE,
+// allowNull: false,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "createdAt"
+// },
+// updatedAt: {
+// type: DataTypes.DATE,
+// allowNull: false,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "updatedAt"
+// },
+// credited: {
+// type: DataTypes.BOOLEAN,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "credited"
+// },
+// code: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "code"
+// },
+// };
+
+// const options = {
+// tableName: "deposits",
+// comment: "",
+// indexes: []
+// };
+
+// db["Deposit"] = db.define("deposits_model", attributes, options);
diff --git a/db/normalized/exchanges.js b/db/normalized/exchanges.js
new file mode 100644
index 00000000..3fd0a5ca
--- /dev/null
+++ b/db/normalized/exchanges.js
@@ -0,0 +1,232 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('exchanges', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.int('transfer_id').notNull();
+ t.foreign('transfer_id').references('transfers.id');
+
+ t.double('exchange_rate').notNull()
+ t.double('exchange_fee').notNull().defaultTo(0)
+
+ t.timestamps();
+ })
+};
+
+exports.down = function(knex) {
+return knex.schema.dropTable('exchanges');
+};
+
+// Changes:
+//
+// Should these be tracked as transactions ?
+// SAT -> SAT
+// tracking various exchange variations (outside of external networks ?)
+//
+// Is user / account / amount info redundant ?
+// + transaction_type: deposit / withdrawal / transfer / exchange ?
+//
+// add transfers table ? (for internal transfers only ?)
+// add redemptions table ? (for bitcoin transfers only ?)
+// add exchanges table ? (for conversion from one currency to another)
+//
+// network -> scope: internal / bitcoin / liquid / lightning ?
+// add bitcoin_transaction ? (with redemption attributes)
+// add liquid_transaction ? ()
+// add lightning_transaction ? (with LN_invoice_hash)
+// add internal_transaction ? ()
+//
+// context for path, memo, rate, preimage, address, received, fee, tip, confirmed, redeemcode ?
+
+
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: true,
+ autoIncrement: true,
+ comment: null,
+ field: "id"
+ },
+ account_id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "account_id"
+ },
+ user_id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "user_id"
+ },
+ path: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "path"
+ },
+ memo: {
+ type: DataTypes.TEXT,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "memo"
+ },
+ hash: {
+ type: DataTypes.TEXT,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "hash"
+ },
+ createdAt: {
+ type: DataTypes.DATE,
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "createdAt"
+ },
+ updatedAt: {
+ type: DataTypes.DATE,
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "updatedAt"
+ },
+ rate: {
+ type: DataTypes.DOUBLE,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "rate"
+ },
+ preimage: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "preimage"
+ },
+ network: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "network"
+ },
+ currency: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "currency"
+ },
+ address: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "address"
+ },
+ received: {
+ type: DataTypes.INTEGER(1),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "received"
+ },
+ amount: {
+ type: DataTypes.DOUBLE,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "amount"
+ },
+ fee: {
+ type: DataTypes.DOUBLE,
+ allowNull: false,
+ defaultValue: 0,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "fee"
+ },
+ tip: {
+ type: DataTypes.DOUBLE,
+ allowNull: false,
+ defaultValue: 0,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "tip"
+ },
+ redeemed: {
+ type: DataTypes.BOOLEAN,
+ allowNull: false,
+ defaultValue: false,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "redeemed"
+ },
+ redeemcode: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "redeemcode"
+ },
+ confirmed: {
+ type: DataTypes.INTEGER(1),
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "confirmed"
+ }
+};
+
+const options = {
+ tableName: "payments",
+ comment: "",
+ indexes: []
+};
+
+db["Payment"] = db.define("payments_model", attributes, options);
diff --git a/db/normalized/institutions.js b/db/normalized/institutions.js
deleted file mode 100644
index 371fab06..00000000
--- a/db/normalized/institutions.js
+++ /dev/null
@@ -1,32 +0,0 @@
-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/invoices.js b/db/normalized/invoices.js
new file mode 100644
index 00000000..ec075db8
--- /dev/null
+++ b/db/normalized/invoices.js
@@ -0,0 +1,206 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('invoices', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.int('transfer_id').notNull();
+ t.foreign('transfer_id').references('transfers.id');
+
+ t.enu('network', ['Bitcoin', 'Liquid', 'Lightning', 'CoinOS']).notNull();
+
+ t.string('bolt11'); // was 'text'
+
+ // Clarify ??? - break out ? - context ? include everything encoded in hash...
+ t.double('amount');
+
+ // Exchanges
+ // ( are there a couple of types of invoices ? - eg checkout / voucher / receive ... with different attributes ?)
+ t.double('rate')
+ t.string('currency')
+ t.double('tip')
+
+ t.string('path')
+ t.string('uuid')
+ t.string('memo')
+ t.string('unconfidential')
+ t.string('address')
+ t.string('received')
+
+ t.timestamps();
+ })
+}
+
+exports.down = function(knex) {
+ return knex.schema.dropTable('invoices');
+};
+
+
+// Variations: ?
+// wallet -> receive - fields ?
+// checkout - fields ?
+// voucher - fields ?
+
+// const { DataTypes } = require('sequelize');
+
+// const attributes = {
+// id: {
+// type: DataTypes.INTEGER(11),
+// allowNull: false,
+// defaultValue: null,
+// primaryKey: true,
+// autoIncrement: true,
+// comment: null,
+// field: "id"
+// },
+// account_id: {
+// type: DataTypes.INTEGER(11),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "account_id"
+// },
+// user_id: {
+// type: DataTypes.INTEGER(11),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "user_id"
+// },
+// text: {
+// type: DataTypes.TEXT,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "text"
+// },
+// createdAt: {
+// type: DataTypes.DATE,
+// allowNull: false,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "createdAt"
+// },
+// updatedAt: {
+// type: DataTypes.DATE,
+// allowNull: false,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "updatedAt"
+// },
+// path: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "path"
+// },
+// rate: {
+// type: DataTypes.DOUBLE,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "rate"
+// },
+// uuid: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "uuid"
+// },
+// memo: {
+// type: DataTypes.TEXT,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "memo"
+// },
+// network: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "network"
+// },
+// currency: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "currency"
+// },
+// unconfidential: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "unconfidential"
+// },
+// address: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "address"
+// },
+// received: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "received"
+// },
+// amount: {
+// type: DataTypes.DOUBLE,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "amount"
+// },
+// tip: {
+// type: DataTypes.DOUBLE,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "tip"
+// },
+// };
+
+// const options = {
+// tableName: "invoices",
+// comment: "",
+// indexes: []
+// };
+
+// db["Invoice"] = db.define("invoices_model", attributes, options);
diff --git a/db/normalized/liquid_assets.js b/db/normalized/liquid_assets.js
new file mode 100644
index 00000000..f16712d8
--- /dev/null
+++ b/db/normalized/liquid_assets.js
@@ -0,0 +1,21 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('liquid_assets', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.string('asset_id').notNull();
+ t.string('name').notNull();
+
+ t.string('domain')
+ t.string('ticker').notNull();
+ t.int('precision').defaultTo(8);
+ t.string('issuer_pubkey')
+
+ t.boolean('registered').defaultTo(false);
+
+ t.timestamps();
+ })
+}
+
+exports.down = function(knex) {
+ return knex.schema.dropTable('liquid_assets');
+}; \ No newline at end of file
diff --git a/db/normalized/ln_assets.js b/db/normalized/ln_assets.js
deleted file mode 100644
index ae8c5883..00000000
--- a/db/normalized/ln_assets.js
+++ /dev/null
@@ -1,34 +0,0 @@
-const { DataTypes } = require('sequelize');
-
-const attributes = {
- id: {
- type: DataTypes.INTEGER(11),
- primaryKey: true,
- autoIncrement: true,
- allowNull: false
- },
- name: {
- type: DataTypes.STRING(255),
- comment: "eg 'USD'"
- },
- code: {
- type: DataTypes.INTEGER(11),
- allowNull: false,
- comment: "unique uuid on liquid network"
- }
-}
-const options = {
- tableName: "codes",
- comment: "Reference subset of liquid network asset codes",
- timestamps: true,
- createdAt: 'created_at',
- updatedAt: 'updated_at',
- indexes: [
- {
- unique: true,
- fields: ['code']
- }
- ]
-};
-
-db["LnAsset"] = db.define("ln_assets_model", attributes, options);
diff --git a/db/normalized/ln_keys.js b/db/normalized/ln_keys.js
new file mode 100644
index 00000000..74f9ebad
--- /dev/null
+++ b/db/normalized/ln_keys.js
@@ -0,0 +1,16 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('ln_keys', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.int('user_id').notNull();
+ t.foreign('user_id').references('users.id');
+
+ t.string('hex').notNull();
+
+ t.timestamps();
+ })
+}
+
+exports.down = function(knex) {
+ return knex.schema.dropTable('ln_keys');
+}; \ No newline at end of file
diff --git a/db/normalized/lnurl_codes.js b/db/normalized/lnurl_codes.js
new file mode 100644
index 00000000..696b7d44
--- /dev/null
+++ b/db/normalized/lnurl_codes.js
@@ -0,0 +1,14 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('lnurl_codes', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.string('code').notNull();
+ t.text('text');
+
+ t.timestamps();
+ })
+}
+
+exports.down = function(knex) {
+ return knex.schema.dropTable('lnurl_codes');
+};
diff --git a/db/normalized/networks.js b/db/normalized/networks.js
deleted file mode 100644
index f08880fd..00000000
--- a/db/normalized/networks.js
+++ /dev/null
@@ -1,32 +0,0 @@
-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
index 0f95d59d..ad573bc2 100644
--- a/db/normalized/non_custodial_accounts.js
+++ b/db/normalized/non_custodial_accounts.js
@@ -1,69 +1,92 @@
-const { DataTypes } = require('sequelize');
+exports.up = function(knex) {
+ return knex.schema.createTable('non_custodial_accounts', function(t) {
+ t.increments('id').unsigned().primary();
+ t.int('account_id').notNull();
+ t.foreign('account_id').references('accounts.id');
-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 ?"
- }
+ // what is the scope / context of these attributes ?
+ t.string('path');
+ t.string('seed');
+ // t.string('hide');
+ // t.string('index');
+ t.string('pub_key');
+ t.string('priv_key');
+
+ t.timestamps();
+ })
}
-const options = {
- tableName: "non_custodial_accounts",
- comment: "",
- timestamps: true,
- createdAt: 'created_at',
- updatedAt: 'updated_at',
- indexes: [
- {
- unique: true,
- fields: ['account_id']
- }
- ]
+
+
+exports.down = function(knex) {
+ return knex.schema.dropTable('non_custodial_accounts');
};
-db["NonCustodialAccount"] = db.define("non_custodial_accounts_model", attributes, options);
+// 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/orders.js b/db/normalized/orders.js
new file mode 100644
index 00000000..8d8418b6
--- /dev/null
+++ b/db/normalized/orders.js
@@ -0,0 +1,30 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('orders', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.int('sell_transfer_id').notNull();
+ t.foreign('sell_transfer_id').references('transfers.id');
+
+ t.int('buy_transfer_id').notNull();
+ t.foreign('buy_transfer_id').references('transfers.id');
+
+ // t.int('exchange_id').notNull();
+ // t.foreign('exchange_id').references('exchanges.id');
+
+ t.double('exchange_rate').notNull();
+ // t.double('amount').notNull();
+
+ t.enu('status', ['Submitted', 'Accepted', 'Cancelled']).notNull();
+ t.date('completion_date')
+
+ t.timestamps();
+ })
+}
+
+
+// Bid / Accepted ... separate into Bid (credit + debit), Accepted (credit + debit)
+
+exports.down = function(knex) {
+ return knex.schema.dropTable('orders');
+};
+
diff --git a/db/normalized/payments.js b/db/normalized/payments.js
deleted file mode 100644
index 7d501f20..00000000
--- a/db/normalized/payments.js
+++ /dev/null
@@ -1,51 +0,0 @@
-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
index 1193b613..f09c98f4 100644
--- a/db/normalized/referrals.js
+++ b/db/normalized/referrals.js
@@ -1,76 +1,20 @@
-const { DataTypes } = require('sequelize');
+exports.up = function(knex) {
+ return knex.schema.createTable('referrals', function(t) {
+ t.increments('id').unsigned().primary();
+ t.int('user_id').nullable();
+ t.foreign('user_id').references('users.id');
-const attributes = {
- id: {
- type: DataTypes.INTEGER(11),
- primaryKey: true,
- autoIncrement: true,
- allowNull: false
- },
- sponsor_id: {
- type: DataTypes.INTEGER(11),
- references: { model: db.User, key: 'id' },
- allowNull: false,
- comment: "Referral made by this user"
- },
- token: {
- type: DataTypes.STRING(255),
- allowNull: false,
- comment: "Unique referral token"
- },
- user_id: {
- type: DataTypes.INTEGER(11),
- references: { model: db.User, key: 'id' },
- allowNull: true,
- comment: "Referral granted to this user (updated when token used)"
- },
- expiry: {
- type: DataTypes.DATE
- },
- status: {
- type: DataTypes.ENUM,
- values: ['available', 'used', 'expired', 'cancelled'],
- defaultValue: 'available'
- }
-}
+ t.int('sponsor_id').notNull();
+ t.foreign('sponsor_id').references('users.id');
-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'])
+ t.string('token').notNull();
+ t.string('expiry').nullable();
+ t.enum('status', ['available', 'used', 'expired', 'cancelled']).notNull().defaultTo('available');
-// 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')
+ t.timestamps();
+ })
+};
-// table.dateTime('created_at').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP'))
-// table.dateTime('updated_at').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'))
-// })
+exports.down = function(knex) {
+ return knex.schema.dropTable('referrals');
+};
diff --git a/db/normalized/transactions.js b/db/normalized/transactions.js
new file mode 100644
index 00000000..7180b8d7
--- /dev/null
+++ b/db/normalized/transactions.js
@@ -0,0 +1,41 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('transactions', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.enu('type', ['deposit', 'withdrawal', 'transfer', 'exchange', 'invoice', 'voucher', 'new asset'])
+
+ // t.text('notes');
+
+ t.timestamps();
+ })
+};
+
+exports.down = function(knex) {
+return knex.schema.dropTable('transactions');
+};
+
+// Changes:
+//
+// Deposit = deposit + credit
+// Withdrawal = withdrawal + debit
+// Transfer = credit + debit
+// Exchange = credit + debit + debit + credit
+// Invoice = invoice + debit ?
+// Voucher = invoice + debit ?
+// New Asset = liquid_asset + credit
+
+//
+// context for path, memo, rate, preimage, address, received, fee, tip, confirmed, redeemcode ?
+exports.up = function(knex) {
+ return knex.schema.createTable('transactions', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.enu('type', ['deposit', 'withdrawal', 'order', 'transfer', 'invoice', 'voucher'])
+
+ t.timestamps();
+ })
+};
+
+exports.down = function(knex) {
+return knex.schema.dropTable('transactions');
+}; \ No newline at end of file
diff --git a/db/normalized/transfers.js b/db/normalized/transfers.js
new file mode 100644
index 00000000..cefc66f7
--- /dev/null
+++ b/db/normalized/transfers.js
@@ -0,0 +1,243 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('transfers', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.int('transaction_id').notNull();
+ t.foreign('transaction_id').references('accounts.id');
+
+ t.int('debit_id').notNull();
+ t.foreign('debit_id').references('debits.id');
+
+ t.int('credit_id').notNull();
+ t.foreign('credit_id').references('credits.id');
+
+ // t.int('liquid_asset_id').notNull();
+ // t.foreign('liquid_asset_id').references('liquid_assets.id');
+
+ // t.double('amount');
+ t.double('transfer_fee').notNull().defaultTo(0)
+
+ t.enu('status', ['pending', 'completed', 'reversed', 'cancelled'])
+
+ t.timestamps();
+ })
+};
+
+exports.down = function(knex) {
+return knex.schema.dropTable('transfers');
+};
+
+// Changes:
+//
+// Should these be tracked as transactions ?
+// SAT -> SAT
+// tracking various exchange variations (outside of external networks ?)
+//
+// Is user / account / amount info redundant ?
+// + transaction_type: deposit / withdrawal / transfer / exchange ?
+//
+// add transfers table ? (for internal transfers only ?)
+// add redemptions table ? (for bitcoin transfers only ?)
+// add exchanges table ? (for conversion from one currency to another)
+//
+// network -> scope: internal / bitcoin / liquid / lightning ?
+// add bitcoin_transaction ? (with redemption attributes)
+// add liquid_transaction ? ()
+// add lightning_transaction ? (with LN_invoice_hash)
+// add internal_transaction ? ()
+//
+// context for path, memo, rate, preimage, address, received, fee, tip, confirmed, redeemcode ?
+
+
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: true,
+ autoIncrement: true,
+ comment: null,
+ field: "id"
+ },
+ account_id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "account_id"
+ },
+ user_id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "user_id"
+ },
+ path: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "path"
+ },
+ memo: {
+ type: DataTypes.TEXT,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "memo"
+ },
+ hash: {
+ type: DataTypes.TEXT,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "hash"
+ },
+ createdAt: {
+ type: DataTypes.DATE,
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "createdAt"
+ },
+ updatedAt: {
+ type: DataTypes.DATE,
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "updatedAt"
+ },
+ rate: {
+ type: DataTypes.DOUBLE,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "rate"
+ },
+ preimage: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "preimage"
+ },
+ network: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "network"
+ },
+ currency: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "currency"
+ },
+ address: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "address"
+ },
+ received: {
+ type: DataTypes.INTEGER(1),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "received"
+ },
+ amount: {
+ type: DataTypes.DOUBLE,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "amount"
+ },
+ fee: {
+ type: DataTypes.DOUBLE,
+ allowNull: false,
+ defaultValue: 0,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "fee"
+ },
+ tip: {
+ type: DataTypes.DOUBLE,
+ allowNull: false,
+ defaultValue: 0,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "tip"
+ },
+ redeemed: {
+ type: DataTypes.BOOLEAN,
+ allowNull: false,
+ defaultValue: false,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "redeemed"
+ },
+ redeemcode: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "redeemcode"
+ },
+ confirmed: {
+ type: DataTypes.INTEGER(1),
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "confirmed"
+ }
+};
+
+const options = {
+ tableName: "payments",
+ comment: "",
+ indexes: []
+};
+
+db["Payment"] = db.define("payments_model", attributes, options);
diff --git a/db/normalized/user_keys.js b/db/normalized/user_keys.js
deleted file mode 100644
index 0d84b742..00000000
--- a/db/normalized/user_keys.js
+++ /dev/null
@@ -1,47 +0,0 @@
-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
index 9864f4eb..fafe5f1a 100644
--- a/db/normalized/user_preferences.js
+++ b/db/normalized/user_preferences.js
@@ -1,60 +1,18 @@
-const { DataTypes } = require('sequelize');
+exports.up = function(knex) {
+ return knex.schema.createTable('user_preferences', function(t) {
+ t.increments('id').unsigned().primary();
+ t.int('user_id').notNull();
+ t.foreign('user_id').references('users.id');
-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",
- }
-}
+ t.enum('default_unit', ['SAT', 'BTC', 'CAD']).notNull().defaultTo('SAT');
+ t.enum('default_currency', ['CAD', 'USD']).notNull().defaultTo('CAD');
+ t.enum('default_fiat', ['CAD', 'USD']).notNull().defaultTo('CAD');
+ t.set('show_currencies', ['CAD', 'USD']).notNull().defaultTo('CAD');
-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']}
- ]
-};
+ t.timestamps();
+ })
+}
-db["UserPreference"] = db.define("user_preferences_model", attributes, options);
+exports.down = function(knex) {
+ return knex.schema.dropTable('user_preferences');
+}; \ No newline at end of file
diff --git a/db/normalized/user_security.js b/db/normalized/user_security.js
new file mode 100644
index 00000000..78acbcce
--- /dev/null
+++ b/db/normalized/user_security.js
@@ -0,0 +1,21 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('user_security', function(t) {
+ t.increments('id').unsigned().primary();
+ t.int('user_id').notNull();
+ t.foreign('user_id').references('users.id');
+
+ t.boolean('twofa').notNull().defaultTo(false);
+ t.string('pin').notNull();
+ t.string('otp_secret').nullable();
+ t.string('seed').nullable();
+
+ t.boolean('email_verified').notNull().default(false)
+ t.boolean('phone_verified').notNull().default(false)
+
+ t.timestamps();
+ })
+};
+
+exports.down = function(knex) {
+ return knex.schema.dropTable('user_security');
+}; \ No newline at end of file
diff --git a/db/normalized/user_subscriptions.js b/db/normalized/user_subscriptions.js
deleted file mode 100644
index ba18d7c6..00000000
--- a/db/normalized/user_subscriptions.js
+++ /dev/null
@@ -1,28 +0,0 @@
-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
index d5b5240f..2c2004c0 100644
--- a/db/normalized/users.js
+++ b/db/normalized/users.js
@@ -1,206 +1,18 @@
-const { DataTypes } = require('sequelize');
+exports.up = function(knex) {
+ return knex.schema.createTable('users', function(t) {
+ t.increments('id').unsigned().primary();
-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,
- },
- access: {
- type: DataTypes.ENUM,
- values: ['Member', 'Tester', 'Admin'],
- defaultValue: 'Member'
- }
-}
+ t.string('uuid').notNull().index();
+ t.string('username').notNull().index();
+ t.string('password').notNull();
+ t.string('email').nullable().index();
+ t.string('phone').nullable();
+ t.enum('access', ['Anonymous', 'Registered', 'Admin']).notNull().defaultTo('Anonymous');
-const options = {
- tableName: "users",
- comment: "",
- timestamps: true,
- createdAt: 'created_at',
- updatedAt: 'updated_at',
- indexes: [
- {fields: ['uuid', 'email']}
- ]
+ t.timestamps();
+ })
};
-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"
- // },
-
-
-
+exports.down = function(knex) {
+ return knex.schema.dropTable('users');
+}; \ No newline at end of file
diff --git a/db/normalized/vouchers.js b/db/normalized/vouchers.js
new file mode 100644
index 00000000..fa5e12a4
--- /dev/null
+++ b/db/normalized/vouchers.js
@@ -0,0 +1,18 @@
+exports.up = function(knex) {
+ return knex.schema.createTable('vouchers', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.int('invoice_id').notNull();
+ t.foreign('invoice_id').references('invoices.id');
+
+ t.string('redemption_code').notNull();
+
+ t.enu('status', ['pending', 'redeemed', 'cancelled']).notNull();
+
+ t.timestamps();
+ })
+}
+
+exports.down = function(knex) {
+ return knex.schema.dropTable('vouchers');
+}; \ No newline at end of file
diff --git a/db/normalized/waiting_list.js b/db/normalized/waiting_list.js
index 8803066b..42ec57a7 100644
--- a/db/normalized/waiting_list.js
+++ b/db/normalized/waiting_list.js
@@ -1,44 +1,60 @@
-const { DataTypes } = require('sequelize');
+exports.up = function(knex) {
+ return knex.schema.createTable('waiting_list', function(t) {
+ t.increments('id').unsigned().primary();
-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
- }
+ t.string('email').notNull();
+ t.string('phone').notNull();
+ t.enu('status', ['pending', 'activated', 'expired', 'cancelled']).notNull();
+
+ t.timestamps();
+ })
}
-const options = {
- tableName: "waiting_list",
- comment: "Users on waiting list",
- timestamps: true,
- createdAt: 'created_at',
- updatedAt: 'updated_at',
- indexes: [
- {
- unique: true,
- fields: ['email', 'sms']
- }
- ]
+exports.down = function(knex) {
+ return knex.schema.dropTable('waiting_list');
};
-db["WaitingList"] = db.define("waiting_list_model", attributes, options);
+// 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
index 00be4299..9a45c514 100644
--- a/db/normalized/withdrawals.js
+++ b/db/normalized/withdrawals.js
@@ -1,54 +1,128 @@
-const { DataTypes } = require('sequelize');
+exports.up = function(knex) {
+ return knex.schema.createTable('withdrawals', function(t) {
+ t.increments('id').unsigned().primary();
-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'
- }
+ t.int('debit_id').notNull();
+ t.foreign('debit_id').references('debits.id');
+
+ t.int('bank_account_id').notNull();
+ t.foreign('bank_account_id').references('bank_accounts.id');
+
+ t.double('withdrawal_fee').notNull().defaultTo(0)
+
+ t.text('notes');
+
+ t.timestamps();
+ })
}
-const options = {
- tableName: "withdrawals",
- comment: "",
- timestamps: true,
- createdAt: 'created_at',
- updatedAt: 'updated_at',
- indexes: [
- ]
+exports.down = function(knex) {
+ return knex.schema.dropTable('withdrawals');
};
-db["Withdrawal"] = db.define("withdrawals_model", attributes, options);
+// Changes:
+//
+// bank info -> bank_account records
+
+// const { DataTypes } = require('sequelize');
+
+// const attributes = {
+// id: {
+// type: DataTypes.INTEGER(11),
+// allowNull: false,
+// defaultValue: null,
+// primaryKey: true,
+// autoIncrement: true,
+// comment: null,
+// field: "id"
+// },
+// amount: {
+// type: DataTypes.DOUBLE,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "amount"
+// },
+// user_id: {
+// type: DataTypes.INTEGER(11),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "user_id"
+// },
+// createdAt: {
+// type: DataTypes.DATE,
+// allowNull: false,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "createdAt"
+// },
+// updatedAt: {
+// type: DataTypes.DATE,
+// allowNull: false,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "updatedAt"
+// },
+// transit: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "transit"
+// },
+// institution: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "institution"
+// },
+// account: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "account"
+// },
+// email: {
+// type: DataTypes.STRING(255),
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "email"
+// },
+// notes: {
+// type: DataTypes.TEXT,
+// allowNull: true,
+// defaultValue: null,
+// primaryKey: false,
+// autoIncrement: false,
+// comment: null,
+// field: "notes"
+// },
+// };
+
+// const options = {
+// tableName: "withdrawals",
+// comment: "",
+// indexes: []
+// };
+
+// db["Withdrawal"] = db.define("withdrawals_model", attributes, options);