Skip to content

Commit

Permalink
UserChallengeProgress table have been created (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
moiskillnadne authored Oct 1, 2024
1 parent 2f06f63 commit 3595c1e
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up (queryInterface, Sequelize) {
await queryInterface.createTable('userChallengeProgress', {
id: {
type: Sequelize.UUIDV4,
primaryKey: true,
defaultValue: Sequelize.UUIDV4,
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
checkpointDate: {
type: Sequelize.TEXT,
allowNull: false,
unique: false,
validate: {
isDate: true,
},
},

userChallengeId: {
type: Sequelize.UUIDV4,
allowNull: false,
references: {
model: 'userChallenges',
key: 'id',
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
})
},

async down (queryInterface, Sequelize) {
await queryInterface.dropTable('userChallengeProgress');
}
};
35 changes: 35 additions & 0 deletions src/database/models/UserChallengeProgress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { DataTypes } from 'sequelize';

import Sequelize from '../connection';
import { UserChallenge } from './UserChallenge';

export const UserChallengeProgress = Sequelize.define(
'userChallengeProgress',
{
id: {
type: DataTypes.UUIDV4,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
},
checkpointDate: {
type: DataTypes.TEXT,
allowNull: false,
unique: false,
validate: {
isDate: true,
},
},

userChallengeId: {
type: DataTypes.UUIDV4,
allowNull: false,
references: {
model: UserChallenge,
key: 'id',
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
},
{},
);

0 comments on commit 3595c1e

Please sign in to comment.