Files
starr-philproperties/apps/api/database/migrations/20270101000020-create-course-purchases.js
T

30 lines
1.7 KiB
JavaScript

'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('course_purchases', {
id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
user_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'users', key: 'user_id' }, onDelete: 'CASCADE' },
product_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'products', key: 'id' }, onDelete: 'RESTRICT' },
amount: { type: Sequelize.DECIMAL(10, 2), allowNull: false },
currency: { type: Sequelize.STRING(10), allowNull: false, defaultValue: 'USD' },
status: { type: Sequelize.ENUM('pending', 'completed', 'failed', 'cancelled', 'refunded'), allowNull: false, defaultValue: 'pending' },
provider: { type: Sequelize.STRING(50), allowNull: false, defaultValue: 'paypal' },
provider_payload: { type: Sequelize.JSONB, allowNull: true, defaultValue: {} },
expires_at: { type: Sequelize.DATE, allowNull: true }, // null = lifetime access
paid_at: { type: Sequelize.DATE, allowNull: true },
createdAt: { type: Sequelize.DATE, allowNull: false },
updatedAt: { type: Sequelize.DATE, allowNull: false },
deletedAt: { type: Sequelize.DATE, allowNull: true },
});
await queryInterface.addIndex('course_purchases', ['user_id']);
await queryInterface.addIndex('course_purchases', ['product_id']);
await queryInterface.addIndex('course_purchases', ['status']);
},
async down(queryInterface) {
await queryInterface.dropTable('course_purchases');
},
};