mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
🐛 Fixed error when during migration to 2.32.0 on mysql (#11208)
closes #11207 MySQL doesn't allow unqiue keys with a length of more than 191 when using InnoDB with utfmb4. These changes will ensure any incorrect tables created are fixed and have the correct length for customer_id * Changed `customer_id` to non-unique column * Nooped the 2.32 `members_stripe_customers` migration * Added migration to recreate `members_stripe_customers` table * sqlite doesn't allow `ALTER TABLE` queries so this is the cleanest solution considering the table is not yet in use
This commit is contained in:
parent
5789d40951
commit
f1ef801b78
4 changed files with 42 additions and 34 deletions
|
@ -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(){}
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
@ -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},
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue