diff options
| author | Ran Guin <[email protected]> | 2021-07-14 18:00:30 -0700 |
|---|---|---|
| committer | Ran Guin <[email protected]> | 2021-07-14 18:00:30 -0700 |
| commit | 4eacfda951f8275ac4f3a1283368884e53285ed0 (patch) | |
| tree | 149e15bc2292b65756dff6323cb3778c9dc89f54 /db/normalized/accounts.js | |
| parent | 826da4a8f7d791b06bb53346597ab0ed51b6362e (diff) | |
| download | coinos-server-4eacfda951f8275ac4f3a1283368884e53285ed0.tar.gz coinos-server-4eacfda951f8275ac4f3a1283368884e53285ed0.zip | |
update normalized models
Diffstat (limited to 'db/normalized/accounts.js')
| -rw-r--r-- | db/normalized/accounts.js | 276 |
1 files changed, 224 insertions, 52 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); |
