aboutsummaryrefslogtreecommitdiffstats
path: root/db/normalized/users.js
diff options
context:
space:
mode:
authorRan Guin <[email protected]>2021-05-11 18:28:25 -0700
committerAdam Soltys <[email protected]>2021-06-04 22:37:02 -0700
commit2e18dc7a532d07d6e53581e5076c7d61a45d6d65 (patch)
treeb6bbd72253c806af56d3640f9e97414f6f4cba19 /db/normalized/users.js
parent421accbfbc0a1add93f7704e657ae93f2d836b82 (diff)
downloadcoinos-server-2e18dc7a532d07d6e53581e5076c7d61a45d6d65.tar.gz
coinos-server-2e18dc7a532d07d6e53581e5076c7d61a45d6d65.zip
add first draft of normalized schema
Diffstat (limited to 'db/normalized/users.js')
-rw-r--r--db/normalized/users.js201
1 files changed, 201 insertions, 0 deletions
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"
+ // },
+
+
+