diff --git a/core/server/data/migrations/versions/2.32/01-add-members-stripe-customers-table.js b/core/server/data/migrations/versions/2.32/01-add-members-stripe-customers-table.js index ede5c402d1..2f62d259d5 100644 --- a/core/server/data/migrations/versions/2.32/01-add-members-stripe-customers-table.js +++ b/core/server/data/migrations/versions/2.32/01-add-members-stripe-customers-table.js @@ -1,34 +1,4 @@ -const common = require('../../../../lib/common'); -const commands = require('../../../schema/commands'); - module.exports = { - config: { - transaction: true - }, - - async up(options){ - const conn = options.transacting || options.connection; - const hasTable = await conn.schema.hasTable('members_stripe_customers'); - - if (hasTable) { - common.logging.warn('Adding table: members_stripe_customers'); - return; - } - - 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_customers'); - - if (!hasTable) { - common.logging.warn('Dropping table: members_stripe_customers'); - return; - } - - common.logging.info('Dropping table: members_stripe_customers'); - return commands.deleteTable('members_stripe_customers', conn); - } + async up(){}, + async down(){} }; diff --git a/core/server/data/migrations/versions/2.33/01-correct-members-stripe-customers-table.js b/core/server/data/migrations/versions/2.33/01-correct-members-stripe-customers-table.js new file mode 100644 index 0000000000..80ecbbd534 --- /dev/null +++ b/core/server/data/migrations/versions/2.33/01-correct-members-stripe-customers-table.js @@ -0,0 +1,37 @@ +const common = require('../../../../lib/common'); +const commands = require('../../../schema/commands'); + +module.exports = { + config: { + transaction: true + }, + + async up(options){ + const conn = options.transacting || options.connection; + const hasTable = await conn.schema.hasTable('members_stripe_customers'); + + if (hasTable) { + common.logging.info('Dropping table: members_stripe_customers'); + await commands.deleteTable('members_stripe_customers', conn); + } else { + common.logging.warn('Dropping table: members_stripe_customers'); + } + + 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_customers'); + + if (!hasTable) { + common.logging.warn('Dropping table: members_stripe_customers'); + return; + } + + common.logging.info('Dropping table: members_stripe_customers'); + return commands.deleteTable('members_stripe_customers', conn); + } +}; + diff --git a/core/server/data/schema/schema.js b/core/server/data/schema/schema.js index d92c7c769f..6cf11a3600 100644 --- a/core/server/data/schema/schema.js +++ b/core/server/data/schema/schema.js @@ -394,7 +394,8 @@ module.exports = { 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}, + // customer_id is unique: false because mysql with innodb utf8mb4 cannot have unqiue columns larger than 191 chars + customer_id: {type: 'string', maxlength: 255, nullable: false, unique: false}, created_at: {type: 'dateTime', nullable: false}, created_by: {type: 'string', maxlength: 24, nullable: false}, updated_at: {type: 'dateTime', nullable: true}, diff --git a/core/test/unit/data/schema/integrity_spec.js b/core/test/unit/data/schema/integrity_spec.js index afa3788b9e..8e4728f0a8 100644 --- a/core/test/unit/data/schema/integrity_spec.js +++ b/core/test/unit/data/schema/integrity_spec.js @@ -19,7 +19,7 @@ var should = require('should'), */ describe('DB version integrity', function () { // Only these variables should need updating - const currentSchemaHash = '9b7ef61ae828987fe52e3a7ab1e1d835'; + const currentSchemaHash = '2aa35a7d6de956293a08def6cf9d9ecc'; const currentFixturesHash = 'c7b485fe2f16517295bd35c761129729'; // If this test is failing, then it is likely a change has been made that requires a DB version bump,