diff options
| author | Ran Guin <[email protected]> | 2021-05-11 18:28:25 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2021-06-04 22:37:02 -0700 |
| commit | 2e18dc7a532d07d6e53581e5076c7d61a45d6d65 (patch) | |
| tree | b6bbd72253c806af56d3640f9e97414f6f4cba19 /db/normalized/referrals.js | |
| parent | 421accbfbc0a1add93f7704e657ae93f2d836b82 (diff) | |
| download | coinos-server-2e18dc7a532d07d6e53581e5076c7d61a45d6d65.tar.gz coinos-server-2e18dc7a532d07d6e53581e5076c7d61a45d6d65.zip | |
add first draft of normalized schema
Diffstat (limited to 'db/normalized/referrals.js')
| -rw-r--r-- | db/normalized/referrals.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/db/normalized/referrals.js b/db/normalized/referrals.js new file mode 100644 index 00000000..5b93ba3f --- /dev/null +++ b/db/normalized/referrals.js @@ -0,0 +1,76 @@ +const { DataTypes } = require('sequelize/types'); +const config = require('./../config') +const dbc = require('knex')(config.knex) + +const { DataTypes } = require('sequelize'); + +const attributes = { + id: { + type: DataTypes.INTEGER(11), + primaryKey: true, + autoIncrement: true, + allowNull: false + }, + sponsor_id: { + type: DataTypes.INTEGER(11), + references: { model: User, key: 'id' }, + allowNull: false, + comment: "Referral made by this user" + }, + user_id: { + type: DataTypes.INTEGER(11), + references: { model: User, key: 'id' }, + allowNull: true, + comment: "Referral granted to this user (updated when token used)" + }, + expiry: { + type: Sequelize.DATE + }, + status: { + type: DataTypes.ENUM, + values: ['pending', 'active', 'expired', 'cancelled'], + defaultValue: 'pending' + } +} + + +const options = { + tableName: "referrals", + comment: "Referrals - unique record for each sponsor / user_id", + timestamps: true, + createdAt: 'created_at', + updatedAt: 'updated_at', + indexes: [ + // are FK fields automatically indexed ? ... if not add sponsor_id + { + unique: true, + fields: ['user_id'] + } + ] +}; + +db["Referral"] = db.define("referrals_model", attributes, options); + +// const config = require('./../config') +// const dbc = require('knex')(config.knex) + +// dbc.schema.createTable('referrals', function (table) { +// table.increments(); + +// table.string('token') +// table.date('expiry') +// table.enu('status', ['active', 'expired', 'closed']) + +// table.dateTime('created_at').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP')) +// table.dateTime('updated_at').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')) +// }) + +// dbc.schema.createTable('waiting_list', function (table) { +// table.increments(); + +// table.string('email') +// table.enu('status', ['pending', 'activated', 'cancelled']).defaultTo('pending') + +// table.dateTime('created_at').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP')) +// table.dateTime('updated_at').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')) +// })
\ No newline at end of file |
