-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* v1 * Added tests * migration test dbs * remote processedAt from tests * fix tests for putting pm behind login check * rename methods in subscriptions library * add more tests for updating status * Few other tweaks and cleanup * fix bug and add ability to copy to dev heroku * reduce db connections by default * migrate test dbs * tweak
- Loading branch information
Showing
34 changed files
with
1,041 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: (queryInterface, DataTypes) => { | ||
return queryInterface.createTable('OrderHistories', { | ||
id: DataTypes.INTEGER, | ||
CreatedByUserId: DataTypes.INTEGER, | ||
FromCollectiveId: DataTypes.INTEGER, | ||
CollectiveId: DataTypes.INTEGER, | ||
TierId: DataTypes.INTEGER, | ||
quantity: DataTypes.INTEGER, | ||
currency: DataTypes.STRING(3), | ||
totalAmount: DataTypes.INTEGER, | ||
description: DataTypes.STRING, | ||
publicMessage: DataTypes.STRING, | ||
privateMessage: DataTypes.STRING, | ||
SubscriptionId: DataTypes.INTEGER, | ||
PaymentMethodId: DataTypes.INTEGER, | ||
MatchingPaymentMethodId: DataTypes.INTEGER, | ||
ReferralCollectiveId: DataTypes.INTEGER, | ||
processedAt: DataTypes.DATE, | ||
createdAt: DataTypes.DATE, | ||
updatedAt: DataTypes.DATE, | ||
deletedAt: DataTypes.DATE, | ||
hid: { | ||
type: DataTypes.BIGINT, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
unique: true | ||
}, | ||
archivedAt: { | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW | ||
} | ||
}); | ||
}, | ||
|
||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('OrderHistories'); | ||
} | ||
}; |
57 changes: 57 additions & 0 deletions
57
migrations/20180205203920-populate-collectiveid-in-paymentmethod.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
const Promise = require('bluebird'); | ||
|
||
|
||
module.exports = { | ||
up: (queryInterface, sequelize) => { | ||
// find all post-migration credit cards that don't have a collective id | ||
return queryInterface.sequelize.query(` | ||
SELECT * FROM "PaymentMethods" | ||
WHERE "service" ilike 'stripe' | ||
AND "type" ilike 'creditcard' | ||
AND "deletedAt" is null | ||
AND "CollectiveId" is null | ||
AND "archivedAt" is null | ||
AND "name" is not null | ||
`, { type: sequelize.QueryTypes.SELECT }) | ||
.then(paymentMethods => { | ||
|
||
console.log("PaymentMethods found: ", paymentMethods.length); | ||
|
||
return Promise.map(paymentMethods, pm => { | ||
return queryInterface.sequelize.query(` | ||
SELECT distinct("FromCollectiveId") FROM "Orders" | ||
WHERE "deletedAt" is null | ||
AND "PaymentMethodId" = ${pm.id} | ||
`, { type: sequelize.QueryTypes.SELECT }) | ||
.then(fromCollectiveIds => { | ||
|
||
if (fromCollectiveIds.length === 0) { | ||
console.log("No fromCollectiveId found for pm.id", pm.id, "skipping"); | ||
return Promise.resolve(); | ||
} | ||
if (fromCollectiveIds.length > 1) { | ||
throw new Error('Found more than 1 fromCollectiveId for paymentMethodId', pm.id) | ||
} | ||
|
||
return queryInterface.sequelize.query(` | ||
UPDATE "PaymentMethods" | ||
SET "CollectiveId" = :collectiveId | ||
WHERE "id" = :pmId | ||
`, { | ||
replacements: { | ||
collectiveId: fromCollectiveIds[0].FromCollectiveId, | ||
pmId: pm.id | ||
} | ||
}) | ||
}) | ||
}) | ||
}) | ||
}, | ||
|
||
down: (queryInterface, Sequelize) => { | ||
return Promise.resolve(); // No way to revert this | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.