aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-03-11 15:10:40 -0700
committerAdam Soltys <[email protected]>2020-03-11 15:10:40 -0700
commitc0888fab024cc9f7c99812bfabf9d7774312dbf7 (patch)
treecad95683af97432f6092a2c2bae10fbb7a588db5 /db
parentbf2b51f0c2ae9b8f0f330dde6411e45fc0da8a25 (diff)
downloadcoinos-server-c0888fab024cc9f7c99812bfabf9d7774312dbf7.tar.gz
coinos-server-c0888fab024cc9f7c99812bfabf9d7774312dbf7.zip
refactor
Diffstat (limited to 'db')
-rw-r--r--db/index.js22
-rw-r--r--db/models/payments.js138
-rw-r--r--db/models/users.js246
-rw-r--r--db/schema.sql116
4 files changed, 522 insertions, 0 deletions
diff --git a/db/index.js b/db/index.js
new file mode 100644
index 00000000..dac6924e
--- /dev/null
+++ b/db/index.js
@@ -0,0 +1,22 @@
+const Sequelize = require("sequelize");
+const conf = config.dbOptions;
+
+db = new Sequelize(conf.database, conf.username, conf.password, {
+ host: conf.host,
+ dialect: conf.dialect,
+ logging: false,
+ dialectOptions: { multipleStatements: true }
+});
+
+require("./models/users.js");
+require("./models/payments.js");
+
+db["User"].hasMany(db["Payment"], {
+ as: "payments",
+ foreignKey: "user_id"
+});
+
+db["Payment"].belongsTo(db["User"], {
+ as: "user",
+ foreignKey: "user_id"
+});
diff --git a/db/models/payments.js b/db/models/payments.js
new file mode 100644
index 00000000..c6dd6e83
--- /dev/null
+++ b/db/models/payments.js
@@ -0,0 +1,138 @@
+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"
+ },
+ 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"
+ },
+ asset: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "asset"
+ },
+ 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: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "fee"
+ },
+ tip: {
+ type: DataTypes.DOUBLE,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "tip"
+ },
+ 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/models/users.js b/db/models/users.js
new file mode 100644
index 00000000..d5b1f5b8
--- /dev/null
+++ b/db/models/users.js
@@ -0,0 +1,246 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: true,
+ autoIncrement: true,
+ comment: null,
+ field: "id"
+ },
+ username: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "username"
+ },
+ password: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "password"
+ },
+ liquid: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "liquid"
+ },
+ confidential: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "confidential"
+ },
+ address: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "address"
+ },
+ symbol: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "symbol"
+ },
+ otpsecret: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: "CAD",
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "otpsecret"
+ },
+ 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"
+ },
+ pubkey: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "pubkey"
+ },
+ privkey: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "privkey"
+ },
+ 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"
+ },
+ index: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "index"
+ },
+ balance: {
+ type: DataTypes.INTEGER(11),
+ allowNull: false,
+ defaultValue: "0",
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "balance"
+ },
+ channel: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "channel"
+ },
+ readonlypw: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "readonlypw"
+ },
+ limit: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: "0",
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "limit"
+ },
+ fbtoken: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "fbtoken"
+ },
+ friend: {
+ type: DataTypes.INTEGER(1),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "friend"
+ },
+ pending: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: "0",
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "pending"
+ },
+ name: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "name"
+ },
+ pic: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "pic"
+ },
+ twofa: {
+ type: DataTypes.INTEGER(1),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "twofa"
+ },
+ pin: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "pin"
+ },
+};
+
+const options = {
+ tableName: "users",
+ comment: "",
+ indexes: []
+};
+
+db["User"] = db.define("users_model", attributes, options);
diff --git a/db/schema.sql b/db/schema.sql
new file mode 100644
index 00000000..7bdf7d3b
--- /dev/null
+++ b/db/schema.sql
@@ -0,0 +1,116 @@
+-- MySQL dump 10.17 Distrib 10.3.22-MariaDB, for debian-linux-gnu (x86_64)
+--
+-- Host: localhost Database: coinos
+-- ------------------------------------------------------
+-- Server version 10.3.22-MariaDB-1:10.3.22+maria~bionic
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
+/*!40103 SET TIME_ZONE='+00:00' */;
+/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
+/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
+/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
+/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
+
+--
+-- Table structure for table `SequelizeMeta`
+--
+
+DROP TABLE IF EXISTS `SequelizeMeta`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `SequelizeMeta` (
+ `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`name`),
+ UNIQUE KEY `name` (`name`),
+ UNIQUE KEY `SequelizeMeta_name_unique` (`name`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `payments`
+--
+
+DROP TABLE IF EXISTS `payments`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `payments` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `user_id` int(11) DEFAULT NULL,
+ `hash` text DEFAULT NULL,
+ `createdAt` datetime NOT NULL,
+ `updatedAt` datetime NOT NULL,
+ `rate` double DEFAULT NULL,
+ `currency` varchar(255) NOT NULL,
+ `address` varchar(255) DEFAULT NULL,
+ `received` tinyint(1) DEFAULT NULL,
+ `amount` double DEFAULT NULL,
+ `tip` double DEFAULT NULL,
+ `confirmed` tinyint(1) NOT NULL,
+ `fee` double DEFAULT NULL,
+ `asset` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=2782 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `users`
+--
+
+DROP TABLE IF EXISTS `users`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `users` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `username` varchar(255) DEFAULT NULL,
+ `password` varchar(255) DEFAULT NULL,
+ `email` varchar(255) DEFAULT NULL,
+ `address` varchar(255) DEFAULT NULL,
+ `unit` varchar(255) DEFAULT NULL,
+ `symbol` varchar(255) DEFAULT NULL,
+ `currency` varchar(255) DEFAULT NULL,
+ `commission` varchar(255) DEFAULT NULL,
+ `title` varchar(255) DEFAULT NULL,
+ `pubkey` varchar(255) DEFAULT NULL,
+ `privkey` varchar(255) DEFAULT NULL,
+ `createdAt` datetime NOT NULL,
+ `updatedAt` datetime NOT NULL,
+ `index` int(11) DEFAULT NULL,
+ `balance` int(11) NOT NULL DEFAULT 0,
+ `channel` varchar(255) DEFAULT NULL,
+ `readonlypw` varchar(255) DEFAULT NULL,
+ `limit` int(11) DEFAULT 0,
+ `fbtoken` varchar(255) DEFAULT NULL,
+ `friend` tinyint(1) DEFAULT NULL,
+ `pending` int(11) DEFAULT 0,
+ `name` varchar(255) DEFAULT NULL,
+ `pic` varchar(255) DEFAULT NULL,
+ `emailToken` varchar(255) DEFAULT NULL,
+ `phone` varchar(255) DEFAULT NULL,
+ `phoneVerified` tinyint(1) DEFAULT NULL,
+ `twofa` tinyint(1) DEFAULT NULL,
+ `authyId` varchar(255) DEFAULT NULL,
+ `pin` varchar(255) DEFAULT NULL,
+ `emailVerified` tinyint(1) DEFAULT NULL,
+ `phoneToken` varchar(255) DEFAULT NULL,
+ `confidential` varchar(255) DEFAULT NULL,
+ `liquid` varchar(255) DEFAULT NULL,
+ `currencies` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
+ `otp` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=420 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
+
+-- Dump completed on 2020-02-09 15:22:43