aboutsummaryrefslogtreecommitdiffstats
path: root/db/normalized/referrals.js
diff options
context:
space:
mode:
Diffstat (limited to 'db/normalized/referrals.js')
-rw-r--r--db/normalized/referrals.js88
1 files changed, 16 insertions, 72 deletions
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');
+};