mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 05:14:12 +03:00
Renamed members_stripe_info to members_stripe_customers
no-issue This is more specific and better if we start adding more stripe tables
This commit is contained in:
parent
9b3d45d4c4
commit
a62b014905
@ -8,27 +8,27 @@ module.exports = {
|
||||
|
||||
async up(options){
|
||||
const conn = options.transacting || options.connection;
|
||||
const hasTable = await conn.schema.hasTable('members_stripe_info');
|
||||
const hasTable = await conn.schema.hasTable('members_stripe_customers');
|
||||
|
||||
if (hasTable) {
|
||||
common.logging.warn('Adding table: members_stripe_info');
|
||||
common.logging.warn('Adding table: members_stripe_customers');
|
||||
return;
|
||||
}
|
||||
|
||||
common.logging.info('Adding table: members_stripe_info');
|
||||
return commands.createTable('members_stripe_info', conn);
|
||||
common.logging.info('Adding table: members_stripe_customers');
|
||||
return commands.createTable('members_stripe_customers', conn);
|
||||
},
|
||||
|
||||
async down(options){
|
||||
const conn = options.transacting || options.connection;
|
||||
const hasTable = await conn.schema.hasTable('members_stripe_info');
|
||||
const hasTable = await conn.schema.hasTable('members_stripe_customers');
|
||||
|
||||
if (!hasTable) {
|
||||
common.logging.warn('Dropping table: members_stripe_info');
|
||||
common.logging.warn('Dropping table: members_stripe_customers');
|
||||
return;
|
||||
}
|
||||
|
||||
common.logging.info('Dropping table: members_stripe_info');
|
||||
return commands.deleteTable('members_stripe_info', conn);
|
||||
common.logging.info('Dropping table: members_stripe_customers');
|
||||
return commands.deleteTable('members_stripe_customers', conn);
|
||||
}
|
||||
};
|
@ -391,7 +391,7 @@ module.exports = {
|
||||
updated_at: {type: 'dateTime', nullable: true},
|
||||
updated_by: {type: 'string', maxlength: 24, nullable: true}
|
||||
},
|
||||
members_stripe_info: {
|
||||
members_stripe_customers: {
|
||||
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
||||
member_id: {type: 'string', maxlength: 24, nullable: false, unique: false},
|
||||
customer_id: {type: 'string', maxlength: 255, nullable: false, unique: true},
|
||||
|
@ -38,7 +38,7 @@ models = [
|
||||
'api-key',
|
||||
'mobiledoc-revision',
|
||||
'member',
|
||||
'member-stripe-info',
|
||||
'member-stripe-customer',
|
||||
'action'
|
||||
];
|
||||
|
||||
|
9
core/server/models/member-stripe-customer.js
Normal file
9
core/server/models/member-stripe-customer.js
Normal file
@ -0,0 +1,9 @@
|
||||
const ghostBookshelf = require('./base');
|
||||
|
||||
const MemberStripeCustomer = ghostBookshelf.Model.extend({
|
||||
tableName: 'members_stripe_customers'
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
MemberStripeCustomer: ghostBookshelf.model('MemberStripeCustomer', MemberStripeCustomer)
|
||||
};
|
@ -1,9 +0,0 @@
|
||||
const ghostBookshelf = require('./base');
|
||||
|
||||
const MemberStripeInfo = ghostBookshelf.Model.extend({
|
||||
tableName: 'members_stripe_info'
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
MemberStripeInfo: ghostBookshelf.model('MemberStripeInfo', MemberStripeInfo)
|
||||
};
|
@ -3,17 +3,17 @@ const ghostBookshelf = require('./base');
|
||||
const Member = ghostBookshelf.Model.extend({
|
||||
tableName: 'members',
|
||||
|
||||
relationships: ['stripe_info'],
|
||||
relationships: ['stripe_customers'],
|
||||
relationshipBelongsTo: {
|
||||
stripe_info: 'members_stripe_info'
|
||||
stripe_customers: 'members_stripe_customers'
|
||||
},
|
||||
|
||||
permittedAttributes(...args) {
|
||||
return ghostBookshelf.Model.prototype.permittedAttributes.apply(this, args).concat(this.relationships);
|
||||
},
|
||||
|
||||
stripe_info() {
|
||||
return this.hasMany('MemberStripeInfo', 'member_id');
|
||||
stripe_customers() {
|
||||
return this.hasMany('MemberStripeCustomer', 'member_id');
|
||||
}
|
||||
}, {
|
||||
permittedOptions(...args) {
|
||||
|
@ -32,8 +32,8 @@ async function setMemberMetadata(member, module, metadata) {
|
||||
return;
|
||||
}
|
||||
await models.Member.edit({
|
||||
stripe_info: metadata
|
||||
}, {id: member.id, withRelated: ['stripe_info']});
|
||||
stripe_customers: metadata
|
||||
}, {id: member.id, withRelated: ['stripe_customers']});
|
||||
return;
|
||||
}
|
||||
|
||||
@ -41,8 +41,8 @@ async function getMemberMetadata(member, module) {
|
||||
if (module !== 'stripe') {
|
||||
return;
|
||||
}
|
||||
const model = await models.Member.where({id: member.id}).fetch({withRelated: ['stripe_info']});
|
||||
const metadata = await model.related('stripe_info');
|
||||
const model = await models.Member.where({id: member.id}).fetch({withRelated: ['stripe_customers']});
|
||||
const metadata = await model.related('stripe_customers');
|
||||
return metadata.toJSON();
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ var should = require('should'),
|
||||
*/
|
||||
describe('DB version integrity', function () {
|
||||
// Only these variables should need updating
|
||||
const currentSchemaHash = 'a503d46e2333202f00fa2bc835b064d2';
|
||||
const currentSchemaHash = '9b7ef61ae828987fe52e3a7ab1e1d835';
|
||||
const currentFixturesHash = 'c7b485fe2f16517295bd35c761129729';
|
||||
|
||||
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
|
||||
|
Loading…
Reference in New Issue
Block a user