mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-02 07:43:11 +03:00
🏗 Migrated subscribers data to members (#11152)
no issue - Populates members table with existing subscribers. Only takes into account columns we know already exist and need to be copied i.e `name`/`email`
This commit is contained in:
parent
1559d7cb54
commit
a562f09c0d
@ -0,0 +1,53 @@
|
||||
const ObjectId = require('bson-objectid');
|
||||
const _ = require('lodash');
|
||||
const models = require('../../../../models');
|
||||
const common = require('../../../../lib/common');
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true,
|
||||
irreversible: true
|
||||
};
|
||||
|
||||
module.exports.up = (options) => {
|
||||
const localOptions = _.merge({
|
||||
context: {internal: true},
|
||||
migrating: true
|
||||
}, options);
|
||||
|
||||
const memberAttrs = [
|
||||
'name',
|
||||
'email',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'updated_at',
|
||||
'updated_by'
|
||||
];
|
||||
|
||||
return models.Subscribers
|
||||
.forge()
|
||||
.fetch(localOptions)
|
||||
.then(({models: subscribers}) => {
|
||||
if (subscribers.length > 0) {
|
||||
common.logging.info(`Adding ${subscribers.length} entries to members`);
|
||||
|
||||
let members = _.map(subscribers, (subscriber) => {
|
||||
let member = memberAttrs.reduce(function (obj, prop) {
|
||||
return Object.assign(obj, {
|
||||
[prop]: subscriber.get(prop)
|
||||
});
|
||||
}, {});
|
||||
member.id = ObjectId.generate();
|
||||
|
||||
return member;
|
||||
});
|
||||
return localOptions.transacting('members').insert(members);
|
||||
} else {
|
||||
common.logging.info('Skipping populating members table: found 0 subscribers');
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.down = () => {
|
||||
return Promise.reject();
|
||||
};
|
Loading…
Reference in New Issue
Block a user