From 5d4e1af5bc3cddb75151c786f008fe0b160a308f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Dec 2020 11:01:49 +0100 Subject: [PATCH 1/4] Bump knex from 0.20.15 to 0.21.13 (#8918) Bumps [knex](https://github.com/knex/knex) from 0.20.15 to 0.21.13. - [Release notes](https://github.com/knex/knex/releases) - [Changelog](https://github.com/knex/knex/blob/master/CHANGELOG.md) - [Commits](https://github.com/knex/knex/compare/0.20.15...0.21.13) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- examples/getstarted/package.json | 2 +- yarn.lock | 78 ++++++++++++-------------------- 2 files changed, 31 insertions(+), 49 deletions(-) diff --git a/examples/getstarted/package.json b/examples/getstarted/package.json index 77def3b6ec..43d1b27184 100644 --- a/examples/getstarted/package.json +++ b/examples/getstarted/package.json @@ -12,7 +12,7 @@ "strapi": "strapi" }, "dependencies": { - "knex": "^0.20.0", + "knex": "^0.21.13", "lodash": "4.17.19", "mysql": "^2.17.1", "pg": "8.4.0", diff --git a/yarn.lock b/yarn.lock index 1790935af5..dd48ead455 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5625,12 +5625,7 @@ color@^3.0.0, color@^3.1.2: color-convert "^1.9.1" color-string "^1.5.2" -colorette@1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.1.0.tgz#1f943e5a357fac10b4e0f5aaef3b14cdc1af6ec7" - integrity sha512-6S062WDQUXi6hOfkO/sBPVwE5ASXY4G2+b4atvhJfSsuUUhIaUKlkjLe9692Ipyt5/a+IPF5aVTu3V5gvXq5cg== - -colorette@^1.2.1: +colorette@1.2.1, colorette@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b" integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw== @@ -5670,7 +5665,7 @@ commander@2.3.0: resolved "https://registry.yarnpkg.com/commander/-/commander-2.3.0.tgz#fd430e889832ec353b9acd1de217c11cb3eef873" integrity sha1-/UMOiJgy7DU7ms0d4hfBHLPu+HM= -commander@6.1.0, commander@^6.0.0: +commander@6.1.0: version "6.1.0" resolved "https://registry.yarnpkg.com/commander/-/commander-6.1.0.tgz#f8d722b78103141006b66f4c7ba1e97315ba75bc" integrity sha512-wl7PNrYWd2y5mp1OK/LhTlv8Ff4kQJQRXXAvF+uU/TPNiVJUxZLRYGj/B0y/lPGAVcSbJqH2Za/cvHmrPMC8mA== @@ -5680,10 +5675,10 @@ commander@^2.19.0, commander@^2.20.0, commander@^2.20.3: resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@^4.1.1: - version "4.1.1" - resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068" - integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA== +commander@^6.0.0, commander@^6.2.0: + version "6.2.1" + resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c" + integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA== commander@~2.19.0: version "2.19.0" @@ -6508,10 +6503,10 @@ dateformat@^3.0.0: resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae" integrity sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q== -debug@*, debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.2.0.tgz#7f150f93920e94c58f5574c2fd01a3110effe7f1" - integrity sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg== +debug@*, debug@4, debug@4.3.1, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0: + version "4.3.1" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee" + integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ== dependencies: ms "2.1.2" @@ -9820,7 +9815,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2, inherits@2.0.4, inherits@^2.0.0, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.0, inherits@~2.0.1, inherits@~2.0.3, inherits@~2.0.4: +inherits@2, inherits@2.0.4, inherits@^2.0.0, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.0, inherits@~2.0.1, inherits@~2.0.3: version "2.0.4" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== @@ -9914,7 +9909,7 @@ interpret@^1.4.0: resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e" integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA== -interpret@^2.0.0: +interpret@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/interpret/-/interpret-2.2.0.tgz#1a78a0b5965c40a5416d007ad6f50ad27c417df9" integrity sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw== @@ -11364,26 +11359,23 @@ klona@^2.0.3: resolved "https://registry.yarnpkg.com/klona/-/klona-2.0.4.tgz#7bb1e3affb0cb8624547ef7e8f6708ea2e39dfc0" integrity sha512-ZRbnvdg/NxqzC7L9Uyqzf4psi1OM4Cuc+sJAkQPjO6XkQIJTNbfK2Rsmbw8fx1p2mkZdp2FZYo2+LwXYY/uwIA== -knex@^0.20.0: - version "0.20.15" - resolved "https://registry.yarnpkg.com/knex/-/knex-0.20.15.tgz#b7e9e1efd9cf35d214440d9439ed21153574679d" - integrity sha512-WHmvgfQfxA5v8pyb9zbskxCS1L1WmYgUbwBhHojlkmdouUOazvroUWlCr6KIKMQ8anXZh1NXOOtIUMnxENZG5Q== +knex@^0.21.13: + version "0.21.13" + resolved "https://registry.yarnpkg.com/knex/-/knex-0.21.13.tgz#5738db52d041d38f8bd9ab15d64f4a8ebb1e97c4" + integrity sha512-O3Zfc7ZHWe32q5k1Z8TqzmiGYVQ9+Tiqb4wP9tPF/ho9DUrHuuy5fLVDdkwDN0gHIr+q5t+XJzNW40DkmeL7lw== dependencies: - colorette "1.1.0" - commander "^4.1.1" - debug "4.1.1" + colorette "1.2.1" + commander "^6.2.0" + debug "4.3.1" esm "^3.2.25" getopts "2.2.5" - inherits "~2.0.4" - interpret "^2.0.0" + interpret "^2.2.0" liftoff "3.1.0" - lodash "^4.17.15" - mkdirp "^0.5.1" - pg-connection-string "2.1.0" - tarn "^2.0.0" + lodash "^4.17.20" + pg-connection-string "2.4.0" + tarn "^3.0.1" tildify "2.0.0" - uuid "^7.0.1" - v8flags "^3.1.3" + v8flags "^3.2.0" known-css-properties@^0.14.0: version "0.14.0" @@ -14204,12 +14196,7 @@ performance-now@^2.1.0: resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= -pg-connection-string@2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.1.0.tgz#e07258f280476540b24818ebb5dca29e101ca502" - integrity sha512-bhlV7Eq09JrRIvo1eKngpwuqKtJnNhZdpdOlvrPrA4dxqXPjxSrbNrfnIDmTpwMyRszrcV4kU5ZA4mMsQUrjdg== - -pg-connection-string@^2.4.0: +pg-connection-string@2.4.0, pg-connection-string@^2.4.0: version "2.4.0" resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.4.0.tgz#c979922eb47832999a204da5dbe1ebf2341b6a10" integrity sha512-3iBXuv7XKvxeMrIgym7njT+HlZkwZqqGX4Bu9cci8xHZNT+Um1gWKqCsAzcC0d95rcKMU5WBg6YRUcHyV0HZKQ== @@ -18406,10 +18393,10 @@ tar@^4, tar@^4.4.10, tar@^4.4.12, tar@^4.4.8: safe-buffer "^5.1.2" yallist "^3.0.3" -tarn@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/tarn/-/tarn-2.0.0.tgz#c68499f69881f99ae955b4317ca7d212d942fdee" - integrity sha512-7rNMCZd3s9bhQh47ksAQd92ADFcJUjjbyOvyFjNLwTPpGieFHMC84S+LOzw0fx1uh6hnDz/19r8CPMnIjJlMMA== +tarn@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/tarn/-/tarn-3.0.1.tgz#ebac2c6dbc6977d34d4526e0a7814200386a8aec" + integrity sha512-6usSlV9KyHsspvwu2duKH+FMUhqJnAh6J5J/4MITl8s94iSUQTLkJggdiewKv4RyARQccnigV48Z+khiuVZDJw== teeny-request@^3.11.3: version "3.11.3" @@ -19270,11 +19257,6 @@ uuid@^3.0.1, uuid@^3.1.0, uuid@^3.2.1, uuid@^3.3.2, uuid@^3.3.3, uuid@^3.4.0: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== -uuid@^7.0.1: - version "7.0.3" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-7.0.3.tgz#c5c9f2c8cf25dc0a372c4df1441c41f5bd0c680b" - integrity sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg== - uuid@^8.0.0, uuid@^8.2.0, uuid@^8.3.0: version "8.3.0" resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.0.tgz#ab738085ca22dc9a8c92725e459b1d507df5d6ea" @@ -19294,7 +19276,7 @@ v8-to-istanbul@^7.0.0: convert-source-map "^1.6.0" source-map "^0.7.3" -v8flags@^3.1.3: +v8flags@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-3.2.0.tgz#b243e3b4dfd731fa774e7492128109a0fe66d656" integrity sha512-mH8etigqMfiGWdeXpaaqGfs6BndypxusHHcv2qSHyZkGEznCd/qAXCWWRzeowtL54147cktFOC4P5y+kl8d8Jg== From 9f1b38c627db48d165022d42e481c46063ecc984 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Dec 2020 11:02:05 +0100 Subject: [PATCH 2/4] Bump react-select from 3.1.0 to 3.1.1 (#8917) Bumps [react-select](https://github.com/JedWatson/react-select) from 3.1.0 to 3.1.1. - [Release notes](https://github.com/JedWatson/react-select/releases) - [Changelog](https://github.com/JedWatson/react-select/blob/master/docs/CHANGELOG.md) - [Commits](https://github.com/JedWatson/react-select/compare/react-select@3.1.0...react-select@3.1.1) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- packages/strapi-admin/package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/strapi-admin/package.json b/packages/strapi-admin/package.json index 794bba8816..4c74d8d656 100644 --- a/packages/strapi-admin/package.json +++ b/packages/strapi-admin/package.json @@ -83,7 +83,7 @@ "react-redux": "7.2.0", "react-router": "^5.0.0", "react-router-dom": "^5.0.0", - "react-select": "^3.0.8", + "react-select": "^3.1.1", "react-transition-group": "4.4.1", "react-virtualized": "^9.21.2", "reactstrap": "8.4.1", diff --git a/yarn.lock b/yarn.lock index dd48ead455..3f36a999d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15580,10 +15580,10 @@ react-router@^5.0.0: tiny-invariant "^1.0.2" tiny-warning "^1.0.0" -react-select@^3.0.8: - version "3.1.0" - resolved "https://registry.yarnpkg.com/react-select/-/react-select-3.1.0.tgz#ab098720b2e9fe275047c993f0d0caf5ded17c27" - integrity sha512-wBFVblBH1iuCBprtpyGtd1dGMadsG36W5/t2Aj8OE6WbByDg5jIFyT7X5gT+l0qmT5TqWhxX+VsKJvCEl2uL9g== +react-select@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/react-select/-/react-select-3.1.1.tgz#156a5b4a6c22b1e3d62a919cb1fd827adb4060bc" + integrity sha512-HjC6jT2BhUxbIbxMZWqVcDibrEpdUJCfGicN0MMV+BQyKtCaPTgFekKWiOizSCy4jdsLMGjLqcFGJMhVGWB0Dg== dependencies: "@babel/runtime" "^7.4.4" "@emotion/cache" "^10.0.9" From 4a02c158b92f724da328e56117ad16f72707f1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 17 Dec 2020 12:33:00 +0100 Subject: [PATCH 3/4] Fix migration when disabling dp on sqlite (#8768) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix migration disable dp on sqlite Signed-off-by: Pierre Noël * fix mongo test Signed-off-by: Pierre Noël * use context instead of migrationInfos * refacto * remove useless if --- .../lib/build-database-schema.js | 189 ++++++++++-------- .../lib/migrations/create-migration-runner.js | 16 +- .../lib/migrations/draft-publish-migration.js | 15 +- .../test/migration-draft-publish.test.e2e.js | 24 +++ 4 files changed, 146 insertions(+), 98 deletions(-) diff --git a/packages/strapi-connector-bookshelf/lib/build-database-schema.js b/packages/strapi-connector-bookshelf/lib/build-database-schema.js index 9f7cc1f155..2ee5673196 100644 --- a/packages/strapi-connector-bookshelf/lib/build-database-schema.js +++ b/packages/strapi-connector-bookshelf/lib/build-database-schema.js @@ -1,3 +1,5 @@ +'use strict'; + const _ = require('lodash'); const { singular } = require('pluralize'); const { contentTypes: contentTypesUtils } = require('strapi-utils'); @@ -7,7 +9,7 @@ const { getManyRelations } = require('./utils/associations'); const createMigrationRunner = require('./migrations/create-migration-runner'); const draftPublishMigration = require('./migrations/draft-publish-migration'); -const migrateSchemas = async ({ ORM, loadedModel, definition, connection, model }) => { +const migrateSchemas = async ({ ORM, loadedModel, definition, connection, model }, context) => { // Add created_at and updated_at field if timestamp option is true if (loadedModel.hasTimestamps) { definition.attributes[loadedModel.hasTimestamps[0]] = { type: 'currentTimestamp' }; @@ -16,13 +18,16 @@ const migrateSchemas = async ({ ORM, loadedModel, definition, connection, model // Equilize tables if (connection.options && connection.options.autoMigration !== false) { - await createOrUpdateTable({ - table: loadedModel.tableName, - attributes: definition.attributes, - definition, - ORM, - model, - }); + await createOrUpdateTable( + { + table: loadedModel.tableName, + attributes: definition.attributes, + definition, + ORM, + model, + }, + context + ); } // Equilize polymorphic relations @@ -40,13 +45,16 @@ const migrateSchemas = async ({ ORM, loadedModel, definition, connection, model }; if (connection.options && connection.options.autoMigration !== false) { - await createOrUpdateTable({ - table: `${loadedModel.tableName}_morph`, - attributes, - definition, - ORM, - model, - }); + await createOrUpdateTable( + { + table: `${loadedModel.tableName}_morph`, + attributes, + definition, + ORM, + model, + }, + context + ); } } @@ -83,7 +91,7 @@ const migrateSchemas = async ({ ORM, loadedModel, definition, connection, model const table = manyRelation.tableCollectionName; if (connection.options && connection.options.autoMigration !== false) { - await createOrUpdateTable({ table, attributes, definition, ORM, model }); + await createOrUpdateTable({ table, attributes, definition, ORM, model }, context); } } } @@ -201,7 +209,7 @@ const buildColType = ({ name, attribute, table, tableExists = false, definition, }; // Equilize database tables -const createOrUpdateTable = async ({ table, attributes, definition, ORM, model }) => { +const createOrUpdateTable = async ({ table, attributes, definition, ORM, model }, context) => { const tableExists = await ORM.knex.schema.hasTable(table); const createIdType = table => { @@ -298,84 +306,93 @@ const createOrUpdateTable = async ({ table, attributes, definition, ORM, model } ORM ); - if (columnsToAlter.length > 0) { - if (definition.client === 'sqlite3') { - const tmpTable = `tmp_${table}`; + const shouldRebuild = + columnsToAlter.length > 0 || (definition.client === 'sqlite3' && context.recreateSqliteTable); - const rebuildTable = async trx => { - await trx.schema.renameTable(table, tmpTable); + if (shouldRebuild) { + switch (definition.client) { + case 'sqlite3': { + const tmpTable = `tmp_${table}`; - // drop possible conflicting indexes - await Promise.all( - attributesNames.map(key => trx.raw('DROP INDEX IF EXISTS ??', uniqueColName(table, key))) - ); + const rebuildTable = async trx => { + await trx.schema.renameTable(table, tmpTable); - // create the table - await createTable(table, { trx }); - - const attrs = attributesNames.filter(attributeName => - isColumn({ - definition, - attribute: attributes[attributeName], - name: attributeName, - }) - ); - - const allAttrs = ['id', ...attrs]; - - await trx.insert(qb => qb.select(allAttrs).from(tmpTable)).into(table); - await trx.schema.dropTableIfExists(tmpTable); - }; - - try { - await ORM.knex.transaction(trx => rebuildTable(trx)); - } catch (err) { - if (err.message.includes('UNIQUE constraint failed')) { - strapi.log.error( - `Unique constraint fails, make sure to update your data and restart to apply the unique constraint.\n\t- ${err.stack}` + // drop possible conflicting indexes + await Promise.all( + attributesNames.map(key => + trx.raw('DROP INDEX IF EXISTS ??', uniqueColName(table, key)) + ) ); - } else { - strapi.log.error(`Migration failed`); - strapi.log.error(err); - } - return false; + // create the table + await createTable(table, { trx }); + + const attrs = attributesNames.filter(attributeName => + isColumn({ + definition, + attribute: attributes[attributeName], + name: attributeName, + }) + ); + + const allAttrs = ['id', ...attrs]; + + await trx.insert(qb => qb.select(allAttrs).from(tmpTable)).into(table); + await trx.schema.dropTableIfExists(tmpTable); + }; + + try { + await ORM.knex.transaction(trx => rebuildTable(trx)); + } catch (err) { + if (err.message.includes('UNIQUE constraint failed')) { + strapi.log.error( + `Unique constraint fails, make sure to update your data and restart to apply the unique constraint.\n\t- ${err.stack}` + ); + } else { + strapi.log.error(`Migration failed`); + strapi.log.error(err); + } + + return false; + } + break; } - } else { - const alterTable = async trx => { - await Promise.all( - columnsToAlter.map(col => { - return ORM.knex.schema - .alterTable(table, tbl => { - tbl.dropUnique(col, uniqueColName(table, col)); - }) - .catch(() => {}); - }) - ); - await trx.schema.alterTable(table, tbl => { - alterColumns(tbl, _.pick(attributes, columnsToAlter), { - tableExists, + default: { + const alterTable = async trx => { + await Promise.all( + columnsToAlter.map(col => { + return ORM.knex.schema + .alterTable(table, tbl => { + tbl.dropUnique(col, uniqueColName(table, col)); + }) + .catch(() => {}); + }) + ); + await trx.schema.alterTable(table, tbl => { + alterColumns(tbl, _.pick(attributes, columnsToAlter), { + tableExists, + }); }); - }); - }; + }; - try { - await ORM.knex.transaction(trx => alterTable(trx)); - } catch (err) { - if (err.code === '23505' && definition.client === 'pg') { - strapi.log.error( - `Unique constraint fails, make sure to update your data and restart to apply the unique constraint.\n\t- ${err.message}\n\t- ${err.detail}` - ); - } else if (definition.client === 'mysql' && err.errno === 1062) { - strapi.log.error( - `Unique constraint fails, make sure to update your data and restart to apply the unique constraint.\n\t- ${err.sqlMessage}` - ); - } else { - strapi.log.error(`Migration failed`); - strapi.log.error(err); + try { + await ORM.knex.transaction(trx => alterTable(trx)); + } catch (err) { + if (err.code === '23505' && definition.client === 'pg') { + strapi.log.error( + `Unique constraint fails, make sure to update your data and restart to apply the unique constraint.\n\t- ${err.message}\n\t- ${err.detail}` + ); + } else if (definition.client === 'mysql' && err.errno === 1062) { + strapi.log.error( + `Unique constraint fails, make sure to update your data and restart to apply the unique constraint.\n\t- ${err.sqlMessage}` + ); + } else { + strapi.log.error(`Migration failed`); + strapi.log.error(err); + } + + return false; } - - return false; } } } diff --git a/packages/strapi-connector-bookshelf/lib/migrations/create-migration-runner.js b/packages/strapi-connector-bookshelf/lib/migrations/create-migration-runner.js index e916802a07..0148b6f3b1 100644 --- a/packages/strapi-connector-bookshelf/lib/migrations/create-migration-runner.js +++ b/packages/strapi-connector-bookshelf/lib/migrations/create-migration-runner.js @@ -2,27 +2,27 @@ const _ = require('lodash'); -const createMigrationRunner = (migrationFunction, { hooks = [] } = {}) => { - const beforeHook = async options => { +const createMigrationRunner = (migrationFunction, { hooks = [] } = {}, context = {}) => { + const beforeHook = async (options, context) => { for (const migration of hooks) { if (_.isFunction(migration.before)) { - await migration.before(options); + await migration.before(options, context); } } }; - const afterHook = async options => { + const afterHook = async (options, context) => { for (const migration of hooks.slice(0).reverse()) { if (_.isFunction(migration.after)) { - await migration.after(options); + await migration.after(options, context); } } }; const run = async options => { - await beforeHook(options); - await migrationFunction(options); - await afterHook(options); + await beforeHook(options, context); + await migrationFunction(options, context); + await afterHook(options, context); }; return { diff --git a/packages/strapi-connector-bookshelf/lib/migrations/draft-publish-migration.js b/packages/strapi-connector-bookshelf/lib/migrations/draft-publish-migration.js index d7575c0afa..39e52449ad 100644 --- a/packages/strapi-connector-bookshelf/lib/migrations/draft-publish-migration.js +++ b/packages/strapi-connector-bookshelf/lib/migrations/draft-publish-migration.js @@ -2,6 +2,7 @@ const _ = require('lodash'); const { contentTypes: contentTypesUtils } = require('strapi-utils'); + const { PUBLISHED_AT_ATTRIBUTE } = contentTypesUtils.constants; const { getDefinitionFromStore } = require('../utils/store-definition'); @@ -22,7 +23,7 @@ const getDraftAndPublishMigrationWay = async ({ definition, ORM }) => { } }; -const before = async ({ definition, ORM }) => { +const before = async ({ definition, ORM }, context) => { const way = await getDraftAndPublishMigrationWay({ definition, ORM }); if (way === 'disable') { @@ -36,9 +37,15 @@ const before = async ({ definition, ORM }) => { .delete() .where(PUBLISHED_AT_ATTRIBUTE, null); - await ORM.knex.schema.table(definition.collectionName, table => { - table.dropColumn(PUBLISHED_AT_ATTRIBUTE); - }); + if (definition.client === 'sqlite3') { + // Bug when droping column with sqlite3 https://github.com/knex/knex/issues/631 + // Need to recreate the table + context.recreateSqliteTable = true; + } else { + await ORM.knex.schema.table(definition.collectionName, table => { + table.dropColumn(PUBLISHED_AT_ATTRIBUTE); + }); + } } } }; diff --git a/packages/strapi-database/test/migration-draft-publish.test.e2e.js b/packages/strapi-database/test/migration-draft-publish.test.e2e.js index 34a4c01ea9..16508d83d4 100644 --- a/packages/strapi-database/test/migration-draft-publish.test.e2e.js +++ b/packages/strapi-database/test/migration-draft-publish.test.e2e.js @@ -18,6 +18,10 @@ const dogModel = { name: { type: 'string', }, + code: { + type: 'string', + unique: true, + }, }, connection: 'default', name: 'dog', @@ -28,9 +32,11 @@ const dogModel = { const dogs = [ { name: 'Nelson', + code: '1', }, { name: 'Atos', + code: '2', }, ]; @@ -131,6 +137,24 @@ describe('Migration - draft and publish', () => { expect(body[0]).toMatchObject(_.pick(data.dogs[0], ['name'])); expect(body[0].published_at).toBeUndefined(); }); + test('Unique constraint is kept after disabling the feature', async () => { + const dogToCreate = { code: 'sameCode' }; + let res = await rq({ + method: 'POST', + url: `/content-manager/explorer/application::dog.dog/`, + body: dogToCreate, + }); + expect(res.statusCode).toBe(200); + expect(res.body).toMatchObject(dogToCreate); + data.dogs.push(res.body); + + res = await rq({ + method: 'POST', + url: `/content-manager/explorer/application::dog.dog/`, + body: dogToCreate, + }); + expect(res.statusCode).toBe(400); + }); }); }); }); From 3304ae3e11b32ea0d3a805413f25236fa549bc68 Mon Sep 17 00:00:00 2001 From: p_0g_8mm3_ <37022952+pr0gr8mm3r@users.noreply.github.com> Date: Thu, 17 Dec 2020 12:54:14 +0100 Subject: [PATCH 4/4] [admin, translations] Translate documentation plugin and add German translations to index of upload plugin (#8803) * add German translations of upload plugin to index * Translate the documentation plugin --- .../admin/src/translations/de.json | 42 +++++++++---------- .../admin/src/translations/index.js | 2 + 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/packages/strapi-plugin-documentation/admin/src/translations/de.json b/packages/strapi-plugin-documentation/admin/src/translations/de.json index b1d270eef0..6d7d8441bd 100755 --- a/packages/strapi-plugin-documentation/admin/src/translations/de.json +++ b/packages/strapi-plugin-documentation/admin/src/translations/de.json @@ -1,24 +1,24 @@ { - "components.Row.generatedDate": "Last generation", - "components.Row.open": "Open", - "components.Row.regenerate": "Regenerate", - "containers.HomePage.Block.title": "Versions", - "containers.HomePage.Button.open": "Open the documentation", - "containers.HomePage.Button.update": "Update", - "containers.HomePage.PluginHeader.description": "Configure the documentation plugin", - "containers.HomePage.PluginHeader.title": "Documentation - Settings", - "containers.HomePage.PopUpWarning.confirm": "I understand", - "containers.HomePage.PopUpWarning.message": "Are you sure you want to delete this version?", - "containers.HomePage.form.password": "Password", - "containers.HomePage.form.password.inputDescription": "Set the password to access the documentation", - "containers.HomePage.form.restrictedAccess": "Restricted access", - "containers.HomePage.form.restrictedAccess.inputDescription": "Make the documentation endpoint private. By default, the access is public", - "containers.HomePage.form.showGeneratedFiles": "Show generated files", - "containers.HomePage.form.showGeneratedFiles.inputDescription": "Useful when you want to override the generated documentation. \nThe plugin will generate files split by model and plugin. \nBy enabling this option it will be easier to customize your documentation", - "error.deleteDoc.versionMissing": "The version you are trying to delete does not exist.", - "error.noVersion": "A version is required", - "error.regenerateDoc": "An error occurred while regenerating the doc", - "error.regenerateDoc.versionMissing": "The version you are trying to generate doesn't exist", - "notification.update.success": "Settings updated successfully", + "components.Row.generatedDate": "Letztes Mal generiert", + "components.Row.open": "Öffnen", + "components.Row.regenerate": "Neu generieren", + "containers.HomePage.Block.title": "Versionen", + "containers.HomePage.Button.open": "Dokumentation öffnen", + "containers.HomePage.Button.update": "Aktualisieren", + "containers.HomePage.PluginHeader.description": "Einstellungen des Dokumentation-Plugins ändern", + "containers.HomePage.PluginHeader.title": "Dokumentation - Einstellungen", + "containers.HomePage.PopUpWarning.confirm": "Ich verstehe", + "containers.HomePage.PopUpWarning.message": "Sind Sie sich sicher, dass Sie diese Version löschen wollen?", + "containers.HomePage.form.password": "Passwort", + "containers.HomePage.form.password.inputDescription": "Setzen Sie ein Passwort, um die Dokumentation privat zu machen", + "containers.HomePage.form.restrictedAccess": "Zugriff beschränken", + "containers.HomePage.form.restrictedAccess.inputDescription": "Den Endpoint der Dokumentation privat machen. Dieser ist standardmäßig öffentlich.", + "containers.HomePage.form.showGeneratedFiles": "Generierte Dateien anzeigen", + "containers.HomePage.form.showGeneratedFiles.inputDescription": "Nützlich, wenn Sie die generierte Dokumentation überschreiben möchten. \nDas Plugin wird nach Modell und Plugin geteilte Dateien erzeugen. \nDurch die Aktivierung dieser Option wird es einfacher sein, Ihre Dokumentation anzupassen.", + "error.deleteDoc.versionMissing": "Die Version, die Sie zu löschen versuchen, existiert nicht.", + "error.noVersion": "Eine Version wird benötigt", + "error.regenerateDoc": "Ein Fehler ist während dem Neu-Erstellen der Dokumentation aufgetreten.", + "error.regenerateDoc.versionMissing": "Die Version, die Sie zu generieren versuchen, existiert nicht", + "notification.update.success": "Einstellungen wurden erfolgreich aktualisiert", "plugin.name": "Dokumentation" } diff --git a/packages/strapi-plugin-upload/admin/src/translations/index.js b/packages/strapi-plugin-upload/admin/src/translations/index.js index 3227890c79..a3e8dc8e5b 100644 --- a/packages/strapi-plugin-upload/admin/src/translations/index.js +++ b/packages/strapi-plugin-upload/admin/src/translations/index.js @@ -1,3 +1,4 @@ +import de from './de.json'; import en from './en.json'; import es from './es.json'; import fr from './fr.json'; @@ -12,6 +13,7 @@ import sk from './sk.json'; import zh from './zh.json'; const trads = { + de, en, es, fr,