mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
30 lines
1.7 KiB
JavaScript
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');
|
|
},
|
|
};
|