From 14305e8d11cb1733a5772a15801a3fbeef254dda Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Tue, 22 Mar 2022 19:41:16 +0100 Subject: [PATCH 01/11] Make strapi compatible with knex v1 --- examples/getstarted/package.json | 2 +- .../lib/dialects/mysql/schema-inspector.js | 2 +- .../lib/dialects/sqlite/schema-inspector.js | 2 +- packages/core/database/lib/entity-manager.js | 4 +- packages/core/database/lib/schema/builder.js | 4 ++ packages/core/database/lib/schema/schema.js | 2 +- packages/core/database/package.json | 2 +- .../app/lib/utils/db-client-dependencies.js | 2 +- yarn.lock | 72 ++++++++++--------- 9 files changed, 51 insertions(+), 41 deletions(-) diff --git a/examples/getstarted/package.json b/examples/getstarted/package.json index fd557bc6cb5..106fd9c2fb2 100644 --- a/examples/getstarted/package.json +++ b/examples/getstarted/package.json @@ -27,7 +27,7 @@ "mysql": "2.18.1", "passport-google-oauth2": "0.2.0", "pg": "8.6.0", - "sqlite3": "5.0.2" + "@vscode/sqlite3": "^5.0.7" }, "strapi": { "uuid": "getstarted" diff --git a/packages/core/database/lib/dialects/mysql/schema-inspector.js b/packages/core/database/lib/dialects/mysql/schema-inspector.js index 7d2bf544fa4..2ac0a67bb7e 100644 --- a/packages/core/database/lib/dialects/mysql/schema-inspector.js +++ b/packages/core/database/lib/dialects/mysql/schema-inspector.js @@ -48,7 +48,7 @@ const toStrapiType = column => { switch (rootType) { case 'int': { if (column.column_key === 'PRI') { - return { type: 'increments', args: [{ primary: true }], unsigned: false }; + return { type: 'increments', args: [{ primary: true, primaryKey: true }], unsigned: false }; } return { type: 'integer' }; diff --git a/packages/core/database/lib/dialects/sqlite/schema-inspector.js b/packages/core/database/lib/dialects/sqlite/schema-inspector.js index 538c0ba0ca8..0b8c128c0ca 100644 --- a/packages/core/database/lib/dialects/sqlite/schema-inspector.js +++ b/packages/core/database/lib/dialects/sqlite/schema-inspector.js @@ -16,7 +16,7 @@ const toStrapiType = column => { switch (rootType) { case 'integer': { if (column.pk) { - return { type: 'increments', args: [{ primary: true }] }; + return { type: 'increments', args: [{ primary: true, primaryKey: true }] }; } return { type: 'integer' }; diff --git a/packages/core/database/lib/entity-manager.js b/packages/core/database/lib/entity-manager.js index c614e5a4e7d..871539d181d 100644 --- a/packages/core/database/lib/entity-manager.js +++ b/packages/core/database/lib/entity-manager.js @@ -166,10 +166,12 @@ const createEntityManager = db => { const dataToInsert = processData(metadata, data, { withDefaults: true }); - const [id] = await this.createQueryBuilder(uid) + const res = await this.createQueryBuilder(uid) .insert(dataToInsert) .execute(); + const id = res[0].id || res[0]; + await this.attachRelations(uid, id, data); // TODO: in case there is no select or populate specified return the inserted data ? diff --git a/packages/core/database/lib/schema/builder.js b/packages/core/database/lib/schema/builder.js index 05d1a07291c..bfef6c626eb 100644 --- a/packages/core/database/lib/schema/builder.js +++ b/packages/core/database/lib/schema/builder.js @@ -199,6 +199,10 @@ const createHelpers = db => { const createColumn = (tableBuilder, column) => { const { type, name, args = [], defaultTo, unsigned, notNullable } = column; + if (name === 'id') { + console.log(name, column); + } + const col = tableBuilder[type](name, ...args); if (unsigned === true) { diff --git a/packages/core/database/lib/schema/schema.js b/packages/core/database/lib/schema/schema.js index 6e11d381c7b..e4a16f8f0b3 100644 --- a/packages/core/database/lib/schema/schema.js +++ b/packages/core/database/lib/schema/schema.js @@ -105,7 +105,7 @@ const getColumnType = attribute => { case 'increments': { return { type: 'increments', - args: [{ primary: true }], + args: [{ primary: true, primaryKey: true }], notNullable: true, }; } diff --git a/packages/core/database/package.json b/packages/core/database/package.json index 0048da30c66..aa208d00ba5 100644 --- a/packages/core/database/package.json +++ b/packages/core/database/package.json @@ -34,7 +34,7 @@ "date-fns": "2.22.1", "debug": "4.3.1", "fs-extra": "10.0.0", - "knex": "0.95.6", + "knex": "^1.0.4", "lodash": "4.17.21", "umzug": "2.3.0" }, diff --git a/packages/generators/app/lib/utils/db-client-dependencies.js b/packages/generators/app/lib/utils/db-client-dependencies.js index dea9ad6d575..3dff2d67e28 100644 --- a/packages/generators/app/lib/utils/db-client-dependencies.js +++ b/packages/generators/app/lib/utils/db-client-dependencies.js @@ -3,7 +3,7 @@ const sqlClientModule = { mysql: { mysql: '2.18.1' }, postgres: { pg: '8.6.0' }, - sqlite: { sqlite3: '5.0.2' }, + sqlite: { '@vscode/sqlite3': '^5.0.7' }, }; /** diff --git a/yarn.lock b/yarn.lock index 1ad92d48a57..395b8ce2469 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5885,6 +5885,13 @@ resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.33.3.tgz#aacc6b3ea9f7b175e0c9a18c9b97e4005a2f4fcc" integrity sha512-JGZ11QV+/ZcfudW2Cz2JVp54/pJNXbsuWRgSh2ZmmZdQBKXqBtIGrwI1Wyx8nlbzAiEFe7FHi4K1zX4//jxTnQ== +"@vscode/sqlite3@^5.0.7": + version "5.0.7" + resolved "https://registry.yarnpkg.com/@vscode/sqlite3/-/sqlite3-5.0.7.tgz#358df36bb0e9e735c54785e3e4b9b2dce1d32895" + integrity sha512-NlsOf+Hir2r4zopI1qMvzWXPwPJuFscirkmFTniTAT24Yz2FWcyZxzK7UT8iSNiTqOCPz48yF55ZVHaz7tTuVQ== + dependencies: + node-addon-api "^4.2.0" + "@webassemblyjs/ast@1.11.1": version "1.11.1" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" @@ -8433,21 +8440,16 @@ color@^4.2.0: color-convert "^2.0.1" color-string "^1.9.0" -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== +colorette@2.0.16, colorette@^2.0.10, colorette@^2.0.14, colorette@^2.0.16: + version "2.0.16" + resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.16.tgz#713b9af84fdb000139f04546bd4a93f62a5085da" + integrity sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g== colorette@^1.2.2: version "1.4.0" resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.4.0.tgz#5190fbb87276259a86ad700bff2c6d6faa3fca40" integrity sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g== -colorette@^2.0.10, colorette@^2.0.14, colorette@^2.0.16: - version "2.0.16" - resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.16.tgz#713b9af84fdb000139f04546bd4a93f62a5085da" - integrity sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g== - colors@1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78" @@ -8521,7 +8523,7 @@ commander@^6.2.0, commander@^6.2.1: resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c" integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA== -commander@^7.0.0, commander@^7.1.0: +commander@^7.0.0: version "7.2.0" resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7" integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw== @@ -9264,7 +9266,7 @@ debug@3.1.0: dependencies: ms "2.0.0" -debug@4, debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0, debug@^4.3.1, debug@^4.3.2, debug@^4.3.3: +debug@4, debug@4.3.3, debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0, debug@^4.3.1, debug@^4.3.2, debug@^4.3.3: version "4.3.3" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664" integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q== @@ -11594,10 +11596,10 @@ get-value@^2.0.3, get-value@^2.0.6: resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" integrity sha1-3BXKHGcjh8p2vTesCjlbogQqLCg= -getopts@2.2.5: - version "2.2.5" - resolved "https://registry.yarnpkg.com/getopts/-/getopts-2.2.5.tgz#67a0fe471cacb9c687d817cab6450b96dde8313b" - integrity sha512-9jb7AW5p3in+IiJWhQiZmmwkpLaR/ccTWdWQCtZM66HJcHHLegowh4q4tSD7gouUyeNvFWRavfK9GXosQHDpFA== +getopts@2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/getopts/-/getopts-2.3.0.tgz#71e5593284807e03e2427449d4f6712a268666f4" + integrity sha512-5eDf9fuSXwxBL6q5HX+dhDj+dslFGWzU5thZ9kNKUkcPtaPdatmUFKwHFrLb/uf/WpA4BHET+AX3Scl56cAjpA== getpass@^0.1.1: version "0.1.7" @@ -14378,23 +14380,23 @@ klona@^2.0.3, klona@^2.0.4: resolved "https://registry.yarnpkg.com/klona/-/klona-2.0.5.tgz#d166574d90076395d9963aa7a928fabb8d76afbc" integrity sha512-pJiBpiXMbt7dkzXe8Ghj/u4FfXOOa98fPW+bihOJ4SjnoijweJrNThJfd3ifXpXhREjpoF2mZVH1GfS9LV3kHQ== -knex@0.95.6: - version "0.95.6" - resolved "https://registry.yarnpkg.com/knex/-/knex-0.95.6.tgz#5fc60ffc2935567bf122925526b1b06b8dbca785" - integrity sha512-noRcmkJl1MdicUbezrcr8OtVLcqQ/cfLIwgAx5EaxNxQOIJff88rBeyLywUScGhQNd/b78DIKKXZzLMrm6h/cw== +knex@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/knex/-/knex-1.0.4.tgz#b9db3c60d0e3a4af37239bb879244e50eb748124" + integrity sha512-cMQ81fpkVmr4ia20BtyrD3oPere/ir/Q6IGLAgcREKOzRVhMsasQ4nx1VQuDRJjqq6oK5kfcxmvWoYkHKrnuMA== dependencies: - colorette "1.2.1" - commander "^7.1.0" - debug "4.3.1" + colorette "2.0.16" + commander "^8.3.0" + debug "4.3.3" escalade "^3.1.1" esm "^3.2.25" - getopts "2.2.5" + getopts "2.3.0" interpret "^2.2.0" lodash "^4.17.21" - pg-connection-string "2.4.0" - rechoir "^0.7.0" + pg-connection-string "2.5.0" + rechoir "^0.8.0" resolve-from "^5.0.0" - tarn "^3.0.1" + tarn "^3.0.2" tildify "2.0.0" known-css-properties@^0.21.0: @@ -16161,7 +16163,7 @@ node-addon-api@^3.0.0: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161" integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A== -node-addon-api@^4.3.0: +node-addon-api@^4.2.0, node-addon-api@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-4.3.0.tgz#52a1a0b475193e0928e98e0426a0d1254782b77f" integrity sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ== @@ -17556,12 +17558,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.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== - -pg-connection-string@^2.5.0: +pg-connection-string@2.5.0, pg-connection-string@^2.5.0: version "2.5.0" resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.5.0.tgz#538cadd0f7e603fc09a12590f3b8a452c2c0cf34" integrity sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ== @@ -18964,6 +18961,13 @@ rechoir@^0.7.0: dependencies: resolve "^1.9.0" +rechoir@^0.8.0: + version "0.8.0" + resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.8.0.tgz#49f866e0d32146142da3ad8f0eff352b3215ff22" + integrity sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ== + dependencies: + resolve "^1.20.0" + recursive-readdir@2.2.2: version "2.2.2" resolved "https://registry.yarnpkg.com/recursive-readdir/-/recursive-readdir-2.2.2.tgz#9946fb3274e1628de6e36b2f6714953b4845094f" @@ -21125,7 +21129,7 @@ tar@^4, tar@^4.4.12: safe-buffer "^5.2.1" yallist "^3.1.1" -tarn@^3.0.1: +tarn@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/tarn/-/tarn-3.0.2.tgz#73b6140fbb881b71559c4f8bfde3d9a4b3d27693" integrity sha512-51LAVKUSZSVfI05vjPESNc5vwqqZpbXCsU+/+wxlOrUjk2SnFTt97v9ZgQrD4YmxYW1Px6w2KjaDitCfkvgxMQ== From 88c317effc80fbc356c633597edc412c6d411304 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Tue, 22 Mar 2022 20:04:23 +0100 Subject: [PATCH 02/11] Fix support old sqlite3 --- examples/getstarted/config/database.js | 2 +- examples/getstarted/package.json | 2 +- packages/core/database/lib/dialects/index.js | 2 ++ packages/core/database/lib/index.js | 10 ++++++++++ yarn.lock | 2 +- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/getstarted/config/database.js b/examples/getstarted/config/database.js index d78eb0ebc8a..0ec8517b500 100644 --- a/examples/getstarted/config/database.js +++ b/examples/getstarted/config/database.js @@ -1,5 +1,5 @@ const sqlite = { - client: 'sqlite', + client: 'sqlite', // sqlite for old sqlite3 / sqlite3 for @vscode/sqlite3 // and better-sqlite3 connection: { filename: '.tmp/data.db', }, diff --git a/examples/getstarted/package.json b/examples/getstarted/package.json index 106fd9c2fb2..4339c988553 100644 --- a/examples/getstarted/package.json +++ b/examples/getstarted/package.json @@ -27,7 +27,7 @@ "mysql": "2.18.1", "passport-google-oauth2": "0.2.0", "pg": "8.6.0", - "@vscode/sqlite3": "^5.0.7" + "@vscode/sqlite3": "5.0.7" }, "strapi": { "uuid": "getstarted" diff --git a/packages/core/database/lib/dialects/index.js b/packages/core/database/lib/dialects/index.js index 2cdb27034c9..f5d340810b2 100644 --- a/packages/core/database/lib/dialects/index.js +++ b/packages/core/database/lib/dialects/index.js @@ -7,6 +7,8 @@ const getDialectClass = client => { case 'mysql': return require('./mysql'); case 'sqlite': + case 'sqlite3': + case 'better-sqlite3': return require('./sqlite'); default: throw new Error(`Unknown dialect ${client}`); diff --git a/packages/core/database/lib/index.js b/packages/core/database/lib/index.js index d75d9ad177c..ada5c6bfd4a 100644 --- a/packages/core/database/lib/index.js +++ b/packages/core/database/lib/index.js @@ -10,10 +10,20 @@ const { createMigrationsProvider } = require('./migrations'); const { createLifecyclesProvider } = require('./lifecycles'); const errors = require('./errors'); +const SqliteClient = require('knex/lib/dialects/sqlite3/index'); + // TODO: move back into strapi const { transformContentTypes } = require('./utils/content-types'); const createConnection = config => { + if (config.client === 'sqlite') { + config.client = class MySqliteClient extends SqliteClient { + _driver() { + return require('sqlite3'); + } + }; + } + const knexInstance = knex(config); return Object.assign(knexInstance, { diff --git a/yarn.lock b/yarn.lock index 395b8ce2469..cb0541f4c99 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5885,7 +5885,7 @@ resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.33.3.tgz#aacc6b3ea9f7b175e0c9a18c9b97e4005a2f4fcc" integrity sha512-JGZ11QV+/ZcfudW2Cz2JVp54/pJNXbsuWRgSh2ZmmZdQBKXqBtIGrwI1Wyx8nlbzAiEFe7FHi4K1zX4//jxTnQ== -"@vscode/sqlite3@^5.0.7": +"@vscode/sqlite3@5.0.7": version "5.0.7" resolved "https://registry.yarnpkg.com/@vscode/sqlite3/-/sqlite3-5.0.7.tgz#358df36bb0e9e735c54785e3e4b9b2dce1d32895" integrity sha512-NlsOf+Hir2r4zopI1qMvzWXPwPJuFscirkmFTniTAT24Yz2FWcyZxzK7UT8iSNiTqOCPz48yF55ZVHaz7tTuVQ== From 317d5be1152aceb3018dbb1a899b5cb8c65e26ee Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Wed, 23 Mar 2022 10:37:12 +0100 Subject: [PATCH 03/11] Use better-sqlite3 by default --- examples/getstarted/config/database.js | 2 +- examples/getstarted/package.json | 2 +- packages/core/database/lib/connection.js | 71 +++++++++++++++++++ packages/core/database/lib/dialects/index.js | 2 - packages/core/database/lib/index.js | 23 +----- .../app/lib/utils/db-client-dependencies.js | 2 +- yarn.lock | 19 ++--- 7 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 packages/core/database/lib/connection.js diff --git a/examples/getstarted/config/database.js b/examples/getstarted/config/database.js index 0ec8517b500..d78eb0ebc8a 100644 --- a/examples/getstarted/config/database.js +++ b/examples/getstarted/config/database.js @@ -1,5 +1,5 @@ const sqlite = { - client: 'sqlite', // sqlite for old sqlite3 / sqlite3 for @vscode/sqlite3 // and better-sqlite3 + client: 'sqlite', connection: { filename: '.tmp/data.db', }, diff --git a/examples/getstarted/package.json b/examples/getstarted/package.json index 4339c988553..7e0a27dbb9b 100644 --- a/examples/getstarted/package.json +++ b/examples/getstarted/package.json @@ -27,7 +27,7 @@ "mysql": "2.18.1", "passport-google-oauth2": "0.2.0", "pg": "8.6.0", - "@vscode/sqlite3": "5.0.7" + "better-sqlite3": "7.5.0" }, "strapi": { "uuid": "getstarted" diff --git a/packages/core/database/lib/connection.js b/packages/core/database/lib/connection.js new file mode 100644 index 00000000000..5b2f6306696 --- /dev/null +++ b/packages/core/database/lib/connection.js @@ -0,0 +1,71 @@ +/* eslint-disable node/no-missing-require */ +/* eslint-disable node/no-extraneous-require */ +'use strict'; + +const knex = require('knex'); + +const SqliteClient = require('knex/lib/dialects/sqlite3/index'); + +const tryBetterSqlite3Client = config => { + try { + require.resolve('better-sqlite3'); + config.client = 'better-sqlite3'; + return true; + } catch (error) { + if (error.code === 'MODULE_NOT_FOUND') { + return false; + } + throw error; + } +}; + +const tryVscodeSqlite3Client = () => { + try { + require.resolve('@vscode/sqlite3'); + return true; + } catch (error) { + if (error.code === 'MODULE_NOT_FOUND') { + return false; + } + throw error; + } +}; + +const tryLegacySqlite3Client = config => { + try { + require.resolve('sqlite3'); + config.client = class MySqliteClient extends SqliteClient { + _driver() { + return require('sqlite3'); + } + }; + + return true; + } catch (error) { + if (error.code === 'MODULE_NOT_FOUND') { + return false; + } + throw error; + } +}; + +const createConnection = config => { + const knexConfig = { ...config }; + if (knexConfig.client === 'sqlite') { + // NOTE: this tries to find the best sqlite module possible to use + // while keeping retro compatibiity + tryBetterSqlite3Client(knexConfig) || + tryVscodeSqlite3Client(knexConfig) || + tryLegacySqlite3Client(knexConfig); + } + + const knexInstance = knex(knexConfig); + + return Object.assign(knexInstance, { + getSchemaName() { + return this.client.connectionSettings.schema; + }, + }); +}; + +module.exports = createConnection; diff --git a/packages/core/database/lib/dialects/index.js b/packages/core/database/lib/dialects/index.js index f5d340810b2..2cdb27034c9 100644 --- a/packages/core/database/lib/dialects/index.js +++ b/packages/core/database/lib/dialects/index.js @@ -7,8 +7,6 @@ const getDialectClass = client => { case 'mysql': return require('./mysql'); case 'sqlite': - case 'sqlite3': - case 'better-sqlite3': return require('./sqlite'); default: throw new Error(`Unknown dialect ${client}`); diff --git a/packages/core/database/lib/index.js b/packages/core/database/lib/index.js index ada5c6bfd4a..12104f51ee0 100644 --- a/packages/core/database/lib/index.js +++ b/packages/core/database/lib/index.js @@ -1,38 +1,17 @@ 'use strict'; -const knex = require('knex'); - const { getDialect } = require('./dialects'); const createSchemaProvider = require('./schema'); const createMetadata = require('./metadata'); const { createEntityManager } = require('./entity-manager'); const { createMigrationsProvider } = require('./migrations'); const { createLifecyclesProvider } = require('./lifecycles'); +const createConnection = require('./connection'); const errors = require('./errors'); -const SqliteClient = require('knex/lib/dialects/sqlite3/index'); - // TODO: move back into strapi const { transformContentTypes } = require('./utils/content-types'); -const createConnection = config => { - if (config.client === 'sqlite') { - config.client = class MySqliteClient extends SqliteClient { - _driver() { - return require('sqlite3'); - } - }; - } - - const knexInstance = knex(config); - - return Object.assign(knexInstance, { - getSchemaName() { - return this.client.connectionSettings.schema; - }, - }); -}; - class Database { constructor(config) { this.metadata = createMetadata(config.models); diff --git a/packages/generators/app/lib/utils/db-client-dependencies.js b/packages/generators/app/lib/utils/db-client-dependencies.js index 3dff2d67e28..76ee1175072 100644 --- a/packages/generators/app/lib/utils/db-client-dependencies.js +++ b/packages/generators/app/lib/utils/db-client-dependencies.js @@ -3,7 +3,7 @@ const sqlClientModule = { mysql: { mysql: '2.18.1' }, postgres: { pg: '8.6.0' }, - sqlite: { '@vscode/sqlite3': '^5.0.7' }, + sqlite: { 'better-sqlite3': '^7.5.0' }, }; /** diff --git a/yarn.lock b/yarn.lock index cb0541f4c99..5be3d54558c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5885,13 +5885,6 @@ resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.33.3.tgz#aacc6b3ea9f7b175e0c9a18c9b97e4005a2f4fcc" integrity sha512-JGZ11QV+/ZcfudW2Cz2JVp54/pJNXbsuWRgSh2ZmmZdQBKXqBtIGrwI1Wyx8nlbzAiEFe7FHi4K1zX4//jxTnQ== -"@vscode/sqlite3@5.0.7": - version "5.0.7" - resolved "https://registry.yarnpkg.com/@vscode/sqlite3/-/sqlite3-5.0.7.tgz#358df36bb0e9e735c54785e3e4b9b2dce1d32895" - integrity sha512-NlsOf+Hir2r4zopI1qMvzWXPwPJuFscirkmFTniTAT24Yz2FWcyZxzK7UT8iSNiTqOCPz48yF55ZVHaz7tTuVQ== - dependencies: - node-addon-api "^4.2.0" - "@webassemblyjs/ast@1.11.1": version "1.11.1" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" @@ -7328,6 +7321,14 @@ better-opn@^2.1.1: dependencies: open "^7.0.3" +better-sqlite3@7.5.0: + version "7.5.0" + resolved "https://registry.yarnpkg.com/better-sqlite3/-/better-sqlite3-7.5.0.tgz#2a91cb616453f002096743b0e5b66a7021cd1c63" + integrity sha512-6FdG9DoytYGDhLW7VWW1vxjEz7xHkqK6LnaUQYA8d6GHNgZhu9PFX2xwKEEnSBRoT1J4PjTUPeg217ShxNmuPg== + dependencies: + bindings "^1.5.0" + prebuild-install "^7.0.0" + big-integer@^1.6.16: version "1.6.51" resolved "https://registry.yarnpkg.com/big-integer/-/big-integer-1.6.51.tgz#0df92a5d9880560d3ff2d5fd20245c889d130686" @@ -16163,7 +16164,7 @@ node-addon-api@^3.0.0: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161" integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A== -node-addon-api@^4.2.0, node-addon-api@^4.3.0: +node-addon-api@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-4.3.0.tgz#52a1a0b475193e0928e98e0426a0d1254782b77f" integrity sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ== @@ -17940,7 +17941,7 @@ postgres-interval@^1.1.0: dependencies: xtend "^4.0.0" -prebuild-install@^7.0.1: +prebuild-install@^7.0.0, prebuild-install@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-7.0.1.tgz#c10075727c318efe72412f333e0ef625beaf3870" integrity sha512-QBSab31WqkyxpnMWQxubYAHR5S9B2+r81ucocew34Fkl98FhvKIF50jIJnNOBmAZfyNV7vE5T6gd3hTVWgY6tg== From 4213aed07b56d695c65cd20fe8a5dd7a5c2217c1 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Wed, 23 Mar 2022 10:47:43 +0100 Subject: [PATCH 04/11] Support db-client sqlite-legacy and add tests for them --- .github/workflows/tests.yml | 42 +++++++++++++++++++ .../app/lib/create-cli-db-project.js | 3 +- .../app/lib/utils/db-client-dependencies.js | 2 + .../app/lib/utils/db-client-name.js | 13 ++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 packages/generators/app/lib/utils/db-client-name.js diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6fba7bc10e6..005dddbbe27 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -191,6 +191,25 @@ jobs: with: dbOptions: '--dbclient=sqlite --dbfile=./tmp/data.db' + e2e_ce_sqlite_legacy: + runs-on: ubuntu-latest + needs: [lint, unit_back, unit_front] + name: '[CE] E2E (sqlite, node: ${{ matrix.node }})' + strategy: + matrix: + node: [12, 14, 16] + max-parallel: 3 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + cache: yarn + - uses: ./.github/actions/install-modules + - uses: ./.github/actions/run-e2e-tests + with: + dbOptions: '--dbclient=sqlite-legacy --dbfile=./tmp/data.db' + # EE e2e_ee_pg: runs-on: ubuntu-latest @@ -295,3 +314,26 @@ jobs: with: dbOptions: '--dbclient=sqlite --dbfile=./tmp/data.db' runEE: true + + e2e_ee_sqlite_legacy: + runs-on: ubuntu-latest + needs: [lint, unit_back, unit_front] + name: '[EE] E2E (sqlite, node: ${{ matrix.node }})' + if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') + env: + STRAPI_LICENSE: ${{ secrets.strapiLicense }} + strategy: + matrix: + node: [12, 14, 16] + max-parallel: 3 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + cache: yarn + - uses: ./.github/actions/install-modules + - uses: ./.github/actions/run-e2e-tests + with: + dbOptions: '--dbclient=sqlite-legacy --dbfile=./tmp/data.db' + runEE: true diff --git a/packages/generators/app/lib/create-cli-db-project.js b/packages/generators/app/lib/create-cli-db-project.js index 9dd8c065529..5c5f6eb9264 100644 --- a/packages/generators/app/lib/create-cli-db-project.js +++ b/packages/generators/app/lib/create-cli-db-project.js @@ -5,6 +5,7 @@ const { merge } = require('lodash'); const { trackUsage } = require('./utils/usage'); const defaultConfigs = require('./utils/db-configs'); const clientDependencies = require('./utils/db-client-dependencies'); +const getClientName = require('./utils/db-client-name'); const createProject = require('./create-project'); module.exports = async scope => { @@ -13,7 +14,7 @@ module.exports = async scope => { const client = scope.database.client; const configuration = { - client, + client: getClientName({ client }), connection: merge({}, defaultConfigs[client] || {}, scope.database), dependencies: clientDependencies({ scope, client }), }; diff --git a/packages/generators/app/lib/utils/db-client-dependencies.js b/packages/generators/app/lib/utils/db-client-dependencies.js index 76ee1175072..3ddf54fdbe1 100644 --- a/packages/generators/app/lib/utils/db-client-dependencies.js +++ b/packages/generators/app/lib/utils/db-client-dependencies.js @@ -4,6 +4,7 @@ const sqlClientModule = { mysql: { mysql: '2.18.1' }, postgres: { pg: '8.6.0' }, sqlite: { 'better-sqlite3': '^7.5.0' }, + 'sqlite-legacy': { sqlite3: '^5.0.2' }, }; /** @@ -12,6 +13,7 @@ const sqlClientModule = { module.exports = ({ client }) => { switch (client) { case 'sqlite': + case 'sqlite-legacy': case 'postgres': case 'mysql': return { diff --git a/packages/generators/app/lib/utils/db-client-name.js b/packages/generators/app/lib/utils/db-client-name.js new file mode 100644 index 00000000000..4db6ddf513f --- /dev/null +++ b/packages/generators/app/lib/utils/db-client-name.js @@ -0,0 +1,13 @@ +'use strict'; + +/** + * Client + */ +module.exports = ({ client }) => { + switch (client) { + case 'sqlite-legacy': + return 'sqlite'; + default: + return client; + } +}; From 06c9939fa740767b07755669b15fa1cdb14f9aac Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Wed, 23 Mar 2022 11:15:25 +0100 Subject: [PATCH 05/11] Fix typo --- packages/core/database/lib/schema/builder.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/core/database/lib/schema/builder.js b/packages/core/database/lib/schema/builder.js index bfef6c626eb..05d1a07291c 100644 --- a/packages/core/database/lib/schema/builder.js +++ b/packages/core/database/lib/schema/builder.js @@ -199,10 +199,6 @@ const createHelpers = db => { const createColumn = (tableBuilder, column) => { const { type, name, args = [], defaultTo, unsigned, notNullable } = column; - if (name === 'id') { - console.log(name, column); - } - const col = tableBuilder[type](name, ...args); if (unsigned === true) { From 337c7cace6182cfbc50d336f52293cac5122a24a Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Wed, 23 Mar 2022 15:19:28 +0100 Subject: [PATCH 06/11] Update workflow --- .github/workflows/tests.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 005dddbbe27..2c7645bce96 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -71,7 +71,6 @@ jobs: strategy: matrix: node: [12, 14, 16] - max-parallel: 3 services: postgres: # Docker Hub image @@ -107,7 +106,6 @@ jobs: strategy: matrix: node: [12, 14, 16] - max-parallel: 3 services: mysql: image: mysql @@ -143,7 +141,6 @@ jobs: strategy: matrix: node: [12, 14, 16] - max-parallel: 3 services: mysql: image: mysql:5 @@ -179,7 +176,6 @@ jobs: strategy: matrix: node: [12, 14, 16] - max-parallel: 3 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 @@ -194,11 +190,10 @@ jobs: e2e_ce_sqlite_legacy: runs-on: ubuntu-latest needs: [lint, unit_back, unit_front] - name: '[CE] E2E (sqlite, node: ${{ matrix.node }})' + name: '[CE] E2E (sqlite legacy, node: ${{ matrix.node }})' strategy: matrix: node: [12, 14, 16] - max-parallel: 3 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 @@ -221,7 +216,6 @@ jobs: strategy: matrix: node: [12, 14, 16] - max-parallel: 3 services: postgres: # Docker Hub image @@ -262,7 +256,6 @@ jobs: strategy: matrix: node: [12, 14, 16] - max-parallel: 3 services: mysql: image: mysql @@ -302,7 +295,6 @@ jobs: strategy: matrix: node: [12, 14, 16] - max-parallel: 3 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 @@ -318,14 +310,13 @@ jobs: e2e_ee_sqlite_legacy: runs-on: ubuntu-latest needs: [lint, unit_back, unit_front] - name: '[EE] E2E (sqlite, node: ${{ matrix.node }})' + name: '[EE] E2E (sqlite legacy, node: ${{ matrix.node }})' if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') env: STRAPI_LICENSE: ${{ secrets.strapiLicense }} strategy: matrix: node: [12, 14, 16] - max-parallel: 3 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 From 4b965665d408208892ebdfec51c00e699c266994 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 25 Mar 2022 09:02:19 +0100 Subject: [PATCH 07/11] Test each sqlite pkg --- .github/actions/run-e2e-tests/script.sh | 4 +- .github/workflows/tests.yml | 579 ++++++++++----------- examples/getstarted/package.json | 4 +- packages/core/admin/server/bootstrap.js | 12 +- packages/core/database/lib/connection.js | 63 ++- packages/generators/app/lib/utils/usage.js | 4 + test/create-test-app.js | 2 + test/e2e.js | 2 + yarn.lock | 9 +- 9 files changed, 336 insertions(+), 343 deletions(-) diff --git a/.github/actions/run-e2e-tests/script.sh b/.github/actions/run-e2e-tests/script.sh index 34ed18f5499..255ebe96806 100755 --- a/.github/actions/run-e2e-tests/script.sh +++ b/.github/actions/run-e2e-tests/script.sh @@ -7,5 +7,5 @@ export ENV_PATH="$(pwd)/testApp/.env" opts=($DB_OPTIONS) -yarn run -s test:generate-app "${opts[@]}" $@ -yarn run -s test:e2e +yarn run -s test:generate-app "${opts[@]}" +yarn run -s test:e2e $@ diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2c7645bce96..bcf5f6104fc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,193 +7,176 @@ on: pull_request: jobs: - lint: - name: 'lint (node: ${{ matrix.node }})' - runs-on: ubuntu-latest - strategy: - matrix: - node: [12, 14, 16] - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta - with: - node-version: ${{ matrix.node }} - - uses: ./.github/actions/install-modules - - name: Run lint - run: yarn run -s lint + # lint: + # name: 'lint (node: ${{ matrix.node }})' + # runs-on: ubuntu-latest + # strategy: + # matrix: + # node: [12, 14, 16] + # steps: + # - uses: actions/checkout@v2 + # - uses: actions/setup-node@v2-beta + # with: + # node-version: ${{ matrix.node }} + # - uses: ./.github/actions/install-modules + # - name: Run lint + # run: yarn run -s lint - unit_back: - name: 'unit_back (node: ${{ matrix.node }})' - needs: [lint] - runs-on: ubuntu-latest - env: - CODECOV_TOKEN: ${{ secrets.codecov }} - strategy: - matrix: - node: [12, 14, 16] - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta - with: - node-version: ${{ matrix.node }} - - uses: ./.github/actions/install-modules - with: - globalPackages: codecov - - name: Run tests - run: yarn run -s test:unit --coverage && codecov -C -F unit + # unit_back: + # name: 'unit_back (node: ${{ matrix.node }})' + # needs: [lint] + # runs-on: ubuntu-latest + # env: + # CODECOV_TOKEN: ${{ secrets.codecov }} + # strategy: + # matrix: + # node: [12, 14, 16] + # steps: + # - uses: actions/checkout@v2 + # - uses: actions/setup-node@v2-beta + # with: + # node-version: ${{ matrix.node }} + # - uses: ./.github/actions/install-modules + # with: + # globalPackages: codecov + # - name: Run tests + # run: yarn run -s test:unit --coverage && codecov -C -F unit - unit_front: - name: 'unit_front (node: ${{ matrix.node }})' - needs: [lint] - runs-on: ubuntu-latest - env: - CODECOV_TOKEN: ${{ secrets.codecov }} - strategy: - matrix: - node: [12, 14, 16] - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta - with: - node-version: ${{ matrix.node }} - - uses: ./.github/actions/install-modules - with: - globalPackages: codecov - - name: Build - run: yarn build - - name: Run test - run: yarn run -s test:front && codecov -C -F front + # unit_front: + # name: 'unit_front (node: ${{ matrix.node }})' + # needs: [lint] + # runs-on: ubuntu-latest + # env: + # CODECOV_TOKEN: ${{ secrets.codecov }} + # strategy: + # matrix: + # node: [12, 14, 16] + # steps: + # - uses: actions/checkout@v2 + # - uses: actions/setup-node@v2-beta + # with: + # node-version: ${{ matrix.node }} + # - uses: ./.github/actions/install-modules + # with: + # globalPackages: codecov + # - name: Build + # run: yarn build + # - name: Run test + # run: yarn run -s test:front && codecov -C -F front - e2e_ce_pg: - runs-on: ubuntu-latest - needs: [lint, unit_back, unit_front] - name: '[CE] E2E (postgres, node: ${{ matrix.node }})' - strategy: - matrix: - node: [12, 14, 16] - services: - postgres: - # Docker Hub image - image: postgres - # Provide the password for postgres - env: - POSTGRES_USER: strapi - POSTGRES_PASSWORD: strapi - POSTGRES_DB: strapi_test - # Set health checks to wait until postgres has started - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - # Maps tcp port 5432 on service container to the host - - 5432:5432 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta - with: - node-version: ${{ matrix.node }} - - uses: ./.github/actions/install-modules - - uses: ./.github/actions/run-e2e-tests - with: - dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' + # e2e_ce_pg: + # runs-on: ubuntu-latest + # needs: [lint, unit_back, unit_front] + # name: '[CE] E2E (postgres, node: ${{ matrix.node }})' + # strategy: + # matrix: + # node: [12, 14, 16] + # services: + # postgres: + # # Docker Hub image + # image: postgres + # # Provide the password for postgres + # env: + # POSTGRES_USER: strapi + # POSTGRES_PASSWORD: strapi + # POSTGRES_DB: strapi_test + # # Set health checks to wait until postgres has started + # options: >- + # --health-cmd pg_isready + # --health-interval 10s + # --health-timeout 5s + # --health-retries 5 + # ports: + # # Maps tcp port 5432 on service container to the host + # - 5432:5432 + # steps: + # - uses: actions/checkout@v2 + # - uses: actions/setup-node@v2-beta + # with: + # node-version: ${{ matrix.node }} + # - uses: ./.github/actions/install-modules + # - uses: ./.github/actions/run-e2e-tests + # with: + # dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' - e2e_ce_mysql: - runs-on: ubuntu-latest - needs: [lint, unit_back, unit_front] - name: '[CE] E2E (mysql, node: ${{ matrix.node }})' - strategy: - matrix: - node: [12, 14, 16] - services: - mysql: - image: mysql - options: >- - --health-cmd="mysqladmin ping" - --health-interval=10s - --health-timeout=5s - --health-retries=3 - -e MYSQL_ROOT_PASSWORD=strapi - -e MYSQL_ROOT_HOST="%" - -e MYSQL_USER=strapi - -e MYSQL_PASSWORD=strapi - -e MYSQL_DATABASE=strapi_test - --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" - ports: - # Maps tcp port 5432 on service container to the host - - 3306:3306 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node }} - cache: yarn - - uses: ./.github/actions/install-modules - - uses: ./.github/actions/run-e2e-tests - with: - dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' + # e2e_ce_mysql: + # runs-on: ubuntu-latest + # needs: [lint, unit_back, unit_front] + # name: '[CE] E2E (mysql, node: ${{ matrix.node }})' + # strategy: + # matrix: + # node: [12, 14, 16] + # services: + # mysql: + # image: mysql + # options: >- + # --health-cmd="mysqladmin ping" + # --health-interval=10s + # --health-timeout=5s + # --health-retries=3 + # -e MYSQL_ROOT_PASSWORD=strapi + # -e MYSQL_ROOT_HOST="%" + # -e MYSQL_USER=strapi + # -e MYSQL_PASSWORD=strapi + # -e MYSQL_DATABASE=strapi_test + # --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" + # ports: + # # Maps tcp port 5432 on service container to the host + # - 3306:3306 + # steps: + # - uses: actions/checkout@v2 + # - uses: actions/setup-node@v2 + # with: + # node-version: ${{ matrix.node }} + # cache: yarn + # - uses: ./.github/actions/install-modules + # - uses: ./.github/actions/run-e2e-tests + # with: + # dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' - e2e_ce_mysql_5: - runs-on: ubuntu-latest - needs: [lint, unit_back, unit_front] - name: '[CE] E2E (mysql:5 , node: ${{ matrix.node }})' - strategy: - matrix: - node: [12, 14, 16] - services: - mysql: - image: mysql:5 - options: >- - --health-cmd="mysqladmin ping" - --health-interval=10s - --health-timeout=5s - --health-retries=3 - -e MYSQL_ROOT_PASSWORD=strapi - -e MYSQL_ROOT_HOST="%" - -e MYSQL_USER=strapi - -e MYSQL_PASSWORD=strapi - -e MYSQL_DATABASE=strapi_test - --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" - ports: - # Maps tcp port 5432 on service container to the host - - 3306:3306 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node }} - cache: yarn - - uses: ./.github/actions/install-modules - - uses: ./.github/actions/run-e2e-tests - with: - dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' + # e2e_ce_mysql_5: + # runs-on: ubuntu-latest + # needs: [lint, unit_back, unit_front] + # name: '[CE] E2E (mysql:5 , node: ${{ matrix.node }})' + # strategy: + # matrix: + # node: [12, 14, 16] + # services: + # mysql: + # image: mysql:5 + # options: >- + # --health-cmd="mysqladmin ping" + # --health-interval=10s + # --health-timeout=5s + # --health-retries=3 + # -e MYSQL_ROOT_PASSWORD=strapi + # -e MYSQL_ROOT_HOST="%" + # -e MYSQL_USER=strapi + # -e MYSQL_PASSWORD=strapi + # -e MYSQL_DATABASE=strapi_test + # --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" + # ports: + # # Maps tcp port 5432 on service container to the host + # - 3306:3306 + # steps: + # - uses: actions/checkout@v2 + # - uses: actions/setup-node@v2 + # with: + # node-version: ${{ matrix.node }} + # cache: yarn + # - uses: ./.github/actions/install-modules + # - uses: ./.github/actions/run-e2e-tests + # with: + # dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' e2e_ce_sqlite: runs-on: ubuntu-latest - needs: [lint, unit_back, unit_front] - name: '[CE] E2E (sqlite, node: ${{ matrix.node }})' - strategy: - matrix: - node: [12, 14, 16] - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node }} - cache: yarn - - uses: ./.github/actions/install-modules - - uses: ./.github/actions/run-e2e-tests - with: - dbOptions: '--dbclient=sqlite --dbfile=./tmp/data.db' - - e2e_ce_sqlite_legacy: - runs-on: ubuntu-latest - needs: [lint, unit_back, unit_front] - name: '[CE] E2E (sqlite legacy, node: ${{ matrix.node }})' + # needs: [lint, unit_back, unit_front] + name: '[CE] E2E (sqlite: ${{ matrix.sqlite_pkg }}, node: ${{ matrix.node }})' strategy: matrix: node: [12, 14, 16] + sqlite_pkg: ['better-sqlite3', 'sqlite3', '@vscode/sqlite3'] steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 @@ -202,129 +185,127 @@ jobs: cache: yarn - uses: ./.github/actions/install-modules - uses: ./.github/actions/run-e2e-tests - with: - dbOptions: '--dbclient=sqlite-legacy --dbfile=./tmp/data.db' - - # EE - e2e_ee_pg: - runs-on: ubuntu-latest - needs: [lint, unit_back, unit_front] - name: '[EE] E2E (postgres, node: ${{ matrix.node }})' - if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') - env: - STRAPI_LICENSE: ${{ secrets.strapiLicense }} - strategy: - matrix: - node: [12, 14, 16] - services: - postgres: - # Docker Hub image - image: postgres - # Provide the password for postgres env: - POSTGRES_USER: strapi - POSTGRES_PASSWORD: strapi - POSTGRES_DB: strapi_test - # Set health checks to wait until postgres has started - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - # Maps tcp port 5432 on service container to the host - - 5432:5432 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node }} - cache: yarn - - uses: ./.github/actions/install-modules - - uses: ./.github/actions/run-e2e-tests - with: - dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' - runEE: true - - e2e_ee_mysql: - runs-on: ubuntu-latest - needs: [lint, unit_back, unit_front] - name: '[EE] E2E (mysql, node: ${{ matrix.node }})' - if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') - env: - STRAPI_LICENSE: ${{ secrets.strapiLicense }} - strategy: - matrix: - node: [12, 14, 16] - services: - mysql: - image: mysql - options: >- - --health-cmd="mysqladmin ping" - --health-interval=10s - --health-timeout=5s - --health-retries=3 - -e MYSQL_ROOT_PASSWORD=strapi - -e MYSQL_ROOT_HOST="%" - -e MYSQL_USER=strapi - -e MYSQL_PASSWORD=strapi - -e MYSQL_DATABASE=strapi_test - --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" - ports: - # Maps tcp port 5432 on service container to the host - - 3306:3306 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node }} - cache: yarn - - uses: ./.github/actions/install-modules - - uses: ./.github/actions/run-e2e-tests - with: - dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' - runEE: true - - e2e_ee_sqlite: - runs-on: ubuntu-latest - needs: [lint, unit_back, unit_front] - name: '[EE] E2E (sqlite, node: ${{ matrix.node }})' - if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') - env: - STRAPI_LICENSE: ${{ secrets.strapiLicense }} - strategy: - matrix: - node: [12, 14, 16] - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node }} - cache: yarn - - uses: ./.github/actions/install-modules - - uses: ./.github/actions/run-e2e-tests - with: - dbOptions: '--dbclient=sqlite --dbfile=./tmp/data.db' - runEE: true - - e2e_ee_sqlite_legacy: - runs-on: ubuntu-latest - needs: [lint, unit_back, unit_front] - name: '[EE] E2E (sqlite legacy, node: ${{ matrix.node }})' - if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') - env: - STRAPI_LICENSE: ${{ secrets.strapiLicense }} - strategy: - matrix: - node: [12, 14, 16] - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node }} - cache: yarn - - uses: ./.github/actions/install-modules - - uses: ./.github/actions/run-e2e-tests + SQLITE_PKG: ${{ matrix.sqlite_pkg }} with: dbOptions: '--dbclient=sqlite-legacy --dbfile=./tmp/data.db' - runEE: true + # EE + # e2e_ee_pg: + # runs-on: ubuntu-latest + # needs: [lint, unit_back, unit_front] + # name: '[EE] E2E (postgres, node: ${{ matrix.node }})' + # if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') + # env: + # STRAPI_LICENSE: ${{ secrets.strapiLicense }} + # strategy: + # matrix: + # node: [12, 14, 16] + # services: + # postgres: + # # Docker Hub image + # image: postgres + # # Provide the password for postgres + # env: + # POSTGRES_USER: strapi + # POSTGRES_PASSWORD: strapi + # POSTGRES_DB: strapi_test + # # Set health checks to wait until postgres has started + # options: >- + # --health-cmd pg_isready + # --health-interval 10s + # --health-timeout 5s + # --health-retries 5 + # ports: + # # Maps tcp port 5432 on service container to the host + # - 5432:5432 + # steps: + # - uses: actions/checkout@v2 + # - uses: actions/setup-node@v2 + # with: + # node-version: ${{ matrix.node }} + # cache: yarn + # - uses: ./.github/actions/install-modules + # - uses: ./.github/actions/run-e2e-tests + # with: + # dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' + # runEE: true + # e2e_ee_mysql: + # runs-on: ubuntu-latest + # needs: [lint, unit_back, unit_front] + # name: '[EE] E2E (mysql, node: ${{ matrix.node }})' + # if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') + # env: + # STRAPI_LICENSE: ${{ secrets.strapiLicense }} + # strategy: + # matrix: + # node: [12, 14, 16] + # services: + # mysql: + # image: mysql + # options: >- + # --health-cmd="mysqladmin ping" + # --health-interval=10s + # --health-timeout=5s + # --health-retries=3 + # -e MYSQL_ROOT_PASSWORD=strapi + # -e MYSQL_ROOT_HOST="%" + # -e MYSQL_USER=strapi + # -e MYSQL_PASSWORD=strapi + # -e MYSQL_DATABASE=strapi_test + # --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" + # ports: + # # Maps tcp port 5432 on service container to the host + # - 3306:3306 + # steps: + # - uses: actions/checkout@v2 + # - uses: actions/setup-node@v2 + # with: + # node-version: ${{ matrix.node }} + # cache: yarn + # - uses: ./.github/actions/install-modules + # - uses: ./.github/actions/run-e2e-tests + # with: + # dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' + # runEE: true + # e2e_ee_sqlite: + # runs-on: ubuntu-latest + # needs: [lint, unit_back, unit_front] + # name: '[EE] E2E (sqlite, node: ${{ matrix.node }})' + # if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') + # env: + # STRAPI_LICENSE: ${{ secrets.strapiLicense }} + # strategy: + # matrix: + # node: [12, 14, 16] + # steps: + # - uses: actions/checkout@v2 + # - uses: actions/setup-node@v2 + # with: + # node-version: ${{ matrix.node }} + # cache: yarn + # - uses: ./.github/actions/install-modules + # - uses: ./.github/actions/run-e2e-tests + # with: + # dbOptions: '--dbclient=sqlite --dbfile=./tmp/data.db' + # runEE: true + # e2e_ee_sqlite_legacy: + # runs-on: ubuntu-latest + # needs: [lint, unit_back, unit_front] + # name: '[EE] E2E (sqlite legacy, node: ${{ matrix.node }})' + # if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') + # env: + # STRAPI_LICENSE: ${{ secrets.strapiLicense }} + # strategy: + # matrix: + # node: [12, 14, 16] + # steps: + # - uses: actions/checkout@v2 + # - uses: actions/setup-node@v2 + # with: + # node-version: ${{ matrix.node }} + # cache: yarn + # - uses: ./.github/actions/install-modules + # - uses: ./.github/actions/run-e2e-tests + # with: + # dbOptions: '--dbclient=sqlite-legacy --dbfile=./tmp/data.db' + # runEE: true diff --git a/examples/getstarted/package.json b/examples/getstarted/package.json index 7e0a27dbb9b..dcec2b2819b 100644 --- a/examples/getstarted/package.json +++ b/examples/getstarted/package.json @@ -27,7 +27,9 @@ "mysql": "2.18.1", "passport-google-oauth2": "0.2.0", "pg": "8.6.0", - "better-sqlite3": "7.5.0" + "better-sqlite3": "7.5.0", + "@vscode/sqlite3": "5.0.7", + "sqlite3": "5.0.2" }, "strapi": { "uuid": "getstarted" diff --git a/packages/core/admin/server/bootstrap.js b/packages/core/admin/server/bootstrap.js index 31ec1812087..1fe0f23e78a 100644 --- a/packages/core/admin/server/bootstrap.js +++ b/packages/core/admin/server/bootstrap.js @@ -12,12 +12,12 @@ const defaultAdminAuthSettings = { }, }; -const registerPermissionActions = () => { - getService('permission').actionProvider.registerMany(adminActions.actions); +const registerPermissionActions = async () => { + await getService('permission').actionProvider.registerMany(adminActions.actions); }; -const registerAdminConditions = () => { - getService('permission').conditionProvider.registerMany(adminConditions.conditions); +const registerAdminConditions = async () => { + await getService('permission').conditionProvider.registerMany(adminConditions.conditions); }; const registerModelHooks = () => { @@ -53,8 +53,8 @@ const syncAuthSettings = async () => { }; module.exports = async () => { - registerAdminConditions(); - registerPermissionActions(); + await registerAdminConditions(); + await registerPermissionActions(); registerModelHooks(); const permissionService = getService('permission'); diff --git a/packages/core/database/lib/connection.js b/packages/core/database/lib/connection.js index 5b2f6306696..1c112ccfe2f 100644 --- a/packages/core/database/lib/connection.js +++ b/packages/core/database/lib/connection.js @@ -6,11 +6,10 @@ const knex = require('knex'); const SqliteClient = require('knex/lib/dialects/sqlite3/index'); -const tryBetterSqlite3Client = config => { +const trySqlitePackage = packageName => { try { - require.resolve('better-sqlite3'); - config.client = 'better-sqlite3'; - return true; + require.resolve(packageName); + return packageName; } catch (error) { if (error.code === 'MODULE_NOT_FOUND') { return false; @@ -18,45 +17,41 @@ const tryBetterSqlite3Client = config => { throw error; } }; - -const tryVscodeSqlite3Client = () => { - try { - require.resolve('@vscode/sqlite3'); - return true; - } catch (error) { - if (error.code === 'MODULE_NOT_FOUND') { - return false; - } - throw error; +class LegacySqliteClient extends SqliteClient { + _driver() { + return require('sqlite3'); } -}; +} -const tryLegacySqlite3Client = config => { - try { - require.resolve('sqlite3'); - config.client = class MySqliteClient extends SqliteClient { - _driver() { - return require('sqlite3'); - } - }; +const clientMap = { + 'better-sqlite3': 'better-sqlite3', + '@vscode/sqlite3': 'sqlite', + sqlite3: LegacySqliteClient, +}; - return true; - } catch (error) { - if (error.code === 'MODULE_NOT_FOUND') { - return false; - } - throw error; +const getSqlitePackageName = () => { + // NOTE: allow forcing the package to use (mostly used for testing purposes) + if (typeof process.env.SQLITE_PKG !== undefined) { + return process.env.SQLITE_PKG; } + + // NOTE: this tries to find the best sqlite module possible to use + // while keeping retro compatibiity + return ( + trySqlitePackage('better-sqlite3') || + trySqlitePackage('@vscode/sqlite3') || + trySqlitePackage('sqlite3') + ); }; const createConnection = config => { const knexConfig = { ...config }; if (knexConfig.client === 'sqlite') { - // NOTE: this tries to find the best sqlite module possible to use - // while keeping retro compatibiity - tryBetterSqlite3Client(knexConfig) || - tryVscodeSqlite3Client(knexConfig) || - tryLegacySqlite3Client(knexConfig); + const sqlitePackageName = getSqlitePackageName(); + + console.log(sqlitePackageName); + + knexConfig.client = clientMap[sqlitePackageName]; } const knexInstance = knex(knexConfig); diff --git a/packages/generators/app/lib/utils/usage.js b/packages/generators/app/lib/utils/usage.js index 67c80107dce..bb7f2ff2fa4 100644 --- a/packages/generators/app/lib/utils/usage.js +++ b/packages/generators/app/lib/utils/usage.js @@ -54,6 +54,10 @@ function captureStderr(name, error) { } function trackEvent(event, body) { + if (process.env.NODE_ENV === 'test') { + return; + } + try { return fetch('https://analytics.strapi.io/track', { method: 'POST', diff --git a/test/create-test-app.js b/test/create-test-app.js index 87f9d2ec2a8..fcc8d1cd0d3 100644 --- a/test/create-test-app.js +++ b/test/create-test-app.js @@ -1,5 +1,7 @@ 'use strict'; +process.env.NODE_ENV = 'test'; + const yargs = require('yargs'); const { cleanTestApp, generateTestApp } = require('./helpers/test-app-generator'); diff --git a/test/e2e.js b/test/e2e.js index a1084c83cdf..03243ebf7af 100644 --- a/test/e2e.js +++ b/test/e2e.js @@ -4,6 +4,8 @@ const path = require('path'); const execa = require('execa'); const yargs = require('yargs'); +process.env.NODE_ENV = 'test'; + const appName = 'testApp'; process.env.ENV_PATH = path.resolve(__dirname, '..', appName, '.env'); diff --git a/yarn.lock b/yarn.lock index 5be3d54558c..bd115650cae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5885,6 +5885,13 @@ resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.33.3.tgz#aacc6b3ea9f7b175e0c9a18c9b97e4005a2f4fcc" integrity sha512-JGZ11QV+/ZcfudW2Cz2JVp54/pJNXbsuWRgSh2ZmmZdQBKXqBtIGrwI1Wyx8nlbzAiEFe7FHi4K1zX4//jxTnQ== +"@vscode/sqlite3@5.0.7": + version "5.0.7" + resolved "https://registry.yarnpkg.com/@vscode/sqlite3/-/sqlite3-5.0.7.tgz#358df36bb0e9e735c54785e3e4b9b2dce1d32895" + integrity sha512-NlsOf+Hir2r4zopI1qMvzWXPwPJuFscirkmFTniTAT24Yz2FWcyZxzK7UT8iSNiTqOCPz48yF55ZVHaz7tTuVQ== + dependencies: + node-addon-api "^4.2.0" + "@webassemblyjs/ast@1.11.1": version "1.11.1" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" @@ -16164,7 +16171,7 @@ node-addon-api@^3.0.0: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161" integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A== -node-addon-api@^4.3.0: +node-addon-api@^4.2.0, node-addon-api@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-4.3.0.tgz#52a1a0b475193e0928e98e0426a0d1254782b77f" integrity sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ== From 5920e31b5b8d41f95bb124e1575cf9930c1fed75 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 25 Mar 2022 09:16:17 +0100 Subject: [PATCH 08/11] Put back entire workflow --- .github/workflows/tests.yml | 536 +++++++++++------------ packages/core/database/lib/connection.js | 2 - 2 files changed, 260 insertions(+), 278 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bcf5f6104fc..e0dfce6cf84 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,171 +7,171 @@ on: pull_request: jobs: - # lint: - # name: 'lint (node: ${{ matrix.node }})' - # runs-on: ubuntu-latest - # strategy: - # matrix: - # node: [12, 14, 16] - # steps: - # - uses: actions/checkout@v2 - # - uses: actions/setup-node@v2-beta - # with: - # node-version: ${{ matrix.node }} - # - uses: ./.github/actions/install-modules - # - name: Run lint - # run: yarn run -s lint + lint: + name: 'lint (node: ${{ matrix.node }})' + runs-on: ubuntu-latest + strategy: + matrix: + node: [12, 14, 16] + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2-beta + with: + node-version: ${{ matrix.node }} + - uses: ./.github/actions/install-modules + - name: Run lint + run: yarn run -s lint - # unit_back: - # name: 'unit_back (node: ${{ matrix.node }})' - # needs: [lint] - # runs-on: ubuntu-latest - # env: - # CODECOV_TOKEN: ${{ secrets.codecov }} - # strategy: - # matrix: - # node: [12, 14, 16] - # steps: - # - uses: actions/checkout@v2 - # - uses: actions/setup-node@v2-beta - # with: - # node-version: ${{ matrix.node }} - # - uses: ./.github/actions/install-modules - # with: - # globalPackages: codecov - # - name: Run tests - # run: yarn run -s test:unit --coverage && codecov -C -F unit + unit_back: + name: 'unit_back (node: ${{ matrix.node }})' + needs: [lint] + runs-on: ubuntu-latest + env: + CODECOV_TOKEN: ${{ secrets.codecov }} + strategy: + matrix: + node: [12, 14, 16] + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2-beta + with: + node-version: ${{ matrix.node }} + - uses: ./.github/actions/install-modules + with: + globalPackages: codecov + - name: Run tests + run: yarn run -s test:unit --coverage && codecov -C -F unit - # unit_front: - # name: 'unit_front (node: ${{ matrix.node }})' - # needs: [lint] - # runs-on: ubuntu-latest - # env: - # CODECOV_TOKEN: ${{ secrets.codecov }} - # strategy: - # matrix: - # node: [12, 14, 16] - # steps: - # - uses: actions/checkout@v2 - # - uses: actions/setup-node@v2-beta - # with: - # node-version: ${{ matrix.node }} - # - uses: ./.github/actions/install-modules - # with: - # globalPackages: codecov - # - name: Build - # run: yarn build - # - name: Run test - # run: yarn run -s test:front && codecov -C -F front + unit_front: + name: 'unit_front (node: ${{ matrix.node }})' + needs: [lint] + runs-on: ubuntu-latest + env: + CODECOV_TOKEN: ${{ secrets.codecov }} + strategy: + matrix: + node: [12, 14, 16] + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2-beta + with: + node-version: ${{ matrix.node }} + - uses: ./.github/actions/install-modules + with: + globalPackages: codecov + - name: Build + run: yarn build + - name: Run test + run: yarn run -s test:front && codecov -C -F front - # e2e_ce_pg: - # runs-on: ubuntu-latest - # needs: [lint, unit_back, unit_front] - # name: '[CE] E2E (postgres, node: ${{ matrix.node }})' - # strategy: - # matrix: - # node: [12, 14, 16] - # services: - # postgres: - # # Docker Hub image - # image: postgres - # # Provide the password for postgres - # env: - # POSTGRES_USER: strapi - # POSTGRES_PASSWORD: strapi - # POSTGRES_DB: strapi_test - # # Set health checks to wait until postgres has started - # options: >- - # --health-cmd pg_isready - # --health-interval 10s - # --health-timeout 5s - # --health-retries 5 - # ports: - # # Maps tcp port 5432 on service container to the host - # - 5432:5432 - # steps: - # - uses: actions/checkout@v2 - # - uses: actions/setup-node@v2-beta - # with: - # node-version: ${{ matrix.node }} - # - uses: ./.github/actions/install-modules - # - uses: ./.github/actions/run-e2e-tests - # with: - # dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' + e2e_ce_pg: + runs-on: ubuntu-latest + needs: [lint, unit_back, unit_front] + name: '[CE] E2E (postgres, node: ${{ matrix.node }})' + strategy: + matrix: + node: [12, 14, 16] + services: + postgres: + # Docker Hub image + image: postgres + # Provide the password for postgres + env: + POSTGRES_USER: strapi + POSTGRES_PASSWORD: strapi + POSTGRES_DB: strapi_test + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2-beta + with: + node-version: ${{ matrix.node }} + - uses: ./.github/actions/install-modules + - uses: ./.github/actions/run-e2e-tests + with: + dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' - # e2e_ce_mysql: - # runs-on: ubuntu-latest - # needs: [lint, unit_back, unit_front] - # name: '[CE] E2E (mysql, node: ${{ matrix.node }})' - # strategy: - # matrix: - # node: [12, 14, 16] - # services: - # mysql: - # image: mysql - # options: >- - # --health-cmd="mysqladmin ping" - # --health-interval=10s - # --health-timeout=5s - # --health-retries=3 - # -e MYSQL_ROOT_PASSWORD=strapi - # -e MYSQL_ROOT_HOST="%" - # -e MYSQL_USER=strapi - # -e MYSQL_PASSWORD=strapi - # -e MYSQL_DATABASE=strapi_test - # --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" - # ports: - # # Maps tcp port 5432 on service container to the host - # - 3306:3306 - # steps: - # - uses: actions/checkout@v2 - # - uses: actions/setup-node@v2 - # with: - # node-version: ${{ matrix.node }} - # cache: yarn - # - uses: ./.github/actions/install-modules - # - uses: ./.github/actions/run-e2e-tests - # with: - # dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' + e2e_ce_mysql: + runs-on: ubuntu-latest + needs: [lint, unit_back, unit_front] + name: '[CE] E2E (mysql, node: ${{ matrix.node }})' + strategy: + matrix: + node: [12, 14, 16] + services: + mysql: + image: mysql + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + -e MYSQL_ROOT_PASSWORD=strapi + -e MYSQL_ROOT_HOST="%" + -e MYSQL_USER=strapi + -e MYSQL_PASSWORD=strapi + -e MYSQL_DATABASE=strapi_test + --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" + ports: + # Maps tcp port 5432 on service container to the host + - 3306:3306 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + cache: yarn + - uses: ./.github/actions/install-modules + - uses: ./.github/actions/run-e2e-tests + with: + dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' - # e2e_ce_mysql_5: - # runs-on: ubuntu-latest - # needs: [lint, unit_back, unit_front] - # name: '[CE] E2E (mysql:5 , node: ${{ matrix.node }})' - # strategy: - # matrix: - # node: [12, 14, 16] - # services: - # mysql: - # image: mysql:5 - # options: >- - # --health-cmd="mysqladmin ping" - # --health-interval=10s - # --health-timeout=5s - # --health-retries=3 - # -e MYSQL_ROOT_PASSWORD=strapi - # -e MYSQL_ROOT_HOST="%" - # -e MYSQL_USER=strapi - # -e MYSQL_PASSWORD=strapi - # -e MYSQL_DATABASE=strapi_test - # --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" - # ports: - # # Maps tcp port 5432 on service container to the host - # - 3306:3306 - # steps: - # - uses: actions/checkout@v2 - # - uses: actions/setup-node@v2 - # with: - # node-version: ${{ matrix.node }} - # cache: yarn - # - uses: ./.github/actions/install-modules - # - uses: ./.github/actions/run-e2e-tests - # with: - # dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' + e2e_ce_mysql_5: + runs-on: ubuntu-latest + needs: [lint, unit_back, unit_front] + name: '[CE] E2E (mysql:5 , node: ${{ matrix.node }})' + strategy: + matrix: + node: [12, 14, 16] + services: + mysql: + image: mysql:5 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + -e MYSQL_ROOT_PASSWORD=strapi + -e MYSQL_ROOT_HOST="%" + -e MYSQL_USER=strapi + -e MYSQL_PASSWORD=strapi + -e MYSQL_DATABASE=strapi_test + --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" + ports: + # Maps tcp port 5432 on service container to the host + - 3306:3306 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + cache: yarn + - uses: ./.github/actions/install-modules + - uses: ./.github/actions/run-e2e-tests + with: + dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' e2e_ce_sqlite: runs-on: ubuntu-latest - # needs: [lint, unit_back, unit_front] + needs: [lint, unit_back, unit_front] name: '[CE] E2E (sqlite: ${{ matrix.sqlite_pkg }}, node: ${{ matrix.node }})' strategy: matrix: @@ -190,122 +190,106 @@ jobs: with: dbOptions: '--dbclient=sqlite-legacy --dbfile=./tmp/data.db' # EE - # e2e_ee_pg: - # runs-on: ubuntu-latest - # needs: [lint, unit_back, unit_front] - # name: '[EE] E2E (postgres, node: ${{ matrix.node }})' - # if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') - # env: - # STRAPI_LICENSE: ${{ secrets.strapiLicense }} - # strategy: - # matrix: - # node: [12, 14, 16] - # services: - # postgres: - # # Docker Hub image - # image: postgres - # # Provide the password for postgres - # env: - # POSTGRES_USER: strapi - # POSTGRES_PASSWORD: strapi - # POSTGRES_DB: strapi_test - # # Set health checks to wait until postgres has started - # options: >- - # --health-cmd pg_isready - # --health-interval 10s - # --health-timeout 5s - # --health-retries 5 - # ports: - # # Maps tcp port 5432 on service container to the host - # - 5432:5432 - # steps: - # - uses: actions/checkout@v2 - # - uses: actions/setup-node@v2 - # with: - # node-version: ${{ matrix.node }} - # cache: yarn - # - uses: ./.github/actions/install-modules - # - uses: ./.github/actions/run-e2e-tests - # with: - # dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' - # runEE: true - # e2e_ee_mysql: - # runs-on: ubuntu-latest - # needs: [lint, unit_back, unit_front] - # name: '[EE] E2E (mysql, node: ${{ matrix.node }})' - # if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') - # env: - # STRAPI_LICENSE: ${{ secrets.strapiLicense }} - # strategy: - # matrix: - # node: [12, 14, 16] - # services: - # mysql: - # image: mysql - # options: >- - # --health-cmd="mysqladmin ping" - # --health-interval=10s - # --health-timeout=5s - # --health-retries=3 - # -e MYSQL_ROOT_PASSWORD=strapi - # -e MYSQL_ROOT_HOST="%" - # -e MYSQL_USER=strapi - # -e MYSQL_PASSWORD=strapi - # -e MYSQL_DATABASE=strapi_test - # --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" - # ports: - # # Maps tcp port 5432 on service container to the host - # - 3306:3306 - # steps: - # - uses: actions/checkout@v2 - # - uses: actions/setup-node@v2 - # with: - # node-version: ${{ matrix.node }} - # cache: yarn - # - uses: ./.github/actions/install-modules - # - uses: ./.github/actions/run-e2e-tests - # with: - # dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' - # runEE: true - # e2e_ee_sqlite: - # runs-on: ubuntu-latest - # needs: [lint, unit_back, unit_front] - # name: '[EE] E2E (sqlite, node: ${{ matrix.node }})' - # if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') - # env: - # STRAPI_LICENSE: ${{ secrets.strapiLicense }} - # strategy: - # matrix: - # node: [12, 14, 16] - # steps: - # - uses: actions/checkout@v2 - # - uses: actions/setup-node@v2 - # with: - # node-version: ${{ matrix.node }} - # cache: yarn - # - uses: ./.github/actions/install-modules - # - uses: ./.github/actions/run-e2e-tests - # with: - # dbOptions: '--dbclient=sqlite --dbfile=./tmp/data.db' - # runEE: true - # e2e_ee_sqlite_legacy: - # runs-on: ubuntu-latest - # needs: [lint, unit_back, unit_front] - # name: '[EE] E2E (sqlite legacy, node: ${{ matrix.node }})' - # if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') - # env: - # STRAPI_LICENSE: ${{ secrets.strapiLicense }} - # strategy: - # matrix: - # node: [12, 14, 16] - # steps: - # - uses: actions/checkout@v2 - # - uses: actions/setup-node@v2 - # with: - # node-version: ${{ matrix.node }} - # cache: yarn - # - uses: ./.github/actions/install-modules - # - uses: ./.github/actions/run-e2e-tests - # with: - # dbOptions: '--dbclient=sqlite-legacy --dbfile=./tmp/data.db' - # runEE: true + e2e_ee_pg: + runs-on: ubuntu-latest + needs: [lint, unit_back, unit_front] + name: '[EE] E2E (postgres, node: ${{ matrix.node }})' + if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') + env: + STRAPI_LICENSE: ${{ secrets.strapiLicense }} + strategy: + matrix: + node: [12, 14, 16] + services: + postgres: + # Docker Hub image + image: postgres + # Provide the password for postgres + env: + POSTGRES_USER: strapi + POSTGRES_PASSWORD: strapi + POSTGRES_DB: strapi_test + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + cache: yarn + - uses: ./.github/actions/install-modules + - uses: ./.github/actions/run-e2e-tests + with: + dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' + runEE: true + + e2e_ee_mysql: + runs-on: ubuntu-latest + needs: [lint, unit_back, unit_front] + name: '[EE] E2E (mysql, node: ${{ matrix.node }})' + if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') + env: + STRAPI_LICENSE: ${{ secrets.strapiLicense }} + strategy: + matrix: + node: [12, 14, 16] + services: + mysql: + image: mysql + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + -e MYSQL_ROOT_PASSWORD=strapi + -e MYSQL_ROOT_HOST="%" + -e MYSQL_USER=strapi + -e MYSQL_PASSWORD=strapi + -e MYSQL_DATABASE=strapi_test + --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" + ports: + # Maps tcp port 5432 on service container to the host + - 3306:3306 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + cache: yarn + - uses: ./.github/actions/install-modules + - uses: ./.github/actions/run-e2e-tests + with: + dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' + runEE: true + + e2e_ee_sqlite: + runs-on: ubuntu-latest + needs: [lint, unit_back, unit_front] + name: '[EE] E2E (sqlite: ${{ matrix.sqlite_pkg }}, node: ${{ matrix.node }})' + if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') + env: + STRAPI_LICENSE: ${{ secrets.strapiLicense }} + strategy: + matrix: + node: [12, 14, 16] + sqlite_pkg: ['better-sqlite3', 'sqlite3', '@vscode/sqlite3'] + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + cache: yarn + - uses: ./.github/actions/install-modules + - uses: ./.github/actions/run-e2e-tests + env: + SQLITE_PKG: ${{ matrix.sqlite_pkg }} + with: + dbOptions: '--dbclient=sqlite --dbfile=./tmp/data.db' + runEE: true diff --git a/packages/core/database/lib/connection.js b/packages/core/database/lib/connection.js index 1c112ccfe2f..ac23d955dfe 100644 --- a/packages/core/database/lib/connection.js +++ b/packages/core/database/lib/connection.js @@ -49,8 +49,6 @@ const createConnection = config => { if (knexConfig.client === 'sqlite') { const sqlitePackageName = getSqlitePackageName(); - console.log(sqlitePackageName); - knexConfig.client = clientMap[sqlitePackageName]; } From 6c1f044346fa2a81729fc6f1491f3d98c54e6bcb Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 25 Mar 2022 10:11:14 +0100 Subject: [PATCH 09/11] optimize caching --- .github/workflows/tests.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e0dfce6cf84..d28de4c42b6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,9 +15,10 @@ jobs: node: [12, 14, 16] steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} + cache: yarn - uses: ./.github/actions/install-modules - name: Run lint run: yarn run -s lint @@ -33,9 +34,10 @@ jobs: node: [12, 14, 16] steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} + cache: yarn - uses: ./.github/actions/install-modules with: globalPackages: codecov @@ -53,9 +55,10 @@ jobs: node: [12, 14, 16] steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} + cache: yarn - uses: ./.github/actions/install-modules with: globalPackages: codecov @@ -91,9 +94,10 @@ jobs: - 5432:5432 steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} + cache: yarn - uses: ./.github/actions/install-modules - uses: ./.github/actions/run-e2e-tests with: From c52f42c80df62e95876235db368f84a7eda09c97 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 28 Mar 2022 19:24:02 +0200 Subject: [PATCH 10/11] Apply feedbacks --- packages/core/database/lib/connection.js | 4 ++-- packages/core/database/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/database/lib/connection.js b/packages/core/database/lib/connection.js index ac23d955dfe..e03e884cb2c 100644 --- a/packages/core/database/lib/connection.js +++ b/packages/core/database/lib/connection.js @@ -31,12 +31,12 @@ const clientMap = { const getSqlitePackageName = () => { // NOTE: allow forcing the package to use (mostly used for testing purposes) - if (typeof process.env.SQLITE_PKG !== undefined) { + if (typeof process.env.SQLITE_PKG !== 'undefined') { return process.env.SQLITE_PKG; } // NOTE: this tries to find the best sqlite module possible to use - // while keeping retro compatibiity + // while keeping retro compatibility return ( trySqlitePackage('better-sqlite3') || trySqlitePackage('@vscode/sqlite3') || diff --git a/packages/core/database/package.json b/packages/core/database/package.json index aa208d00ba5..be3c964c8b4 100644 --- a/packages/core/database/package.json +++ b/packages/core/database/package.json @@ -34,7 +34,7 @@ "date-fns": "2.22.1", "debug": "4.3.1", "fs-extra": "10.0.0", - "knex": "^1.0.4", + "knex": "1.0.4", "lodash": "4.17.21", "umzug": "2.3.0" }, From 1130511ce3b6762b3b3de972103d891c7bc69520 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 28 Mar 2022 19:48:41 +0200 Subject: [PATCH 11/11] Update yarn.lock --- yarn.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 5b554d33582..192c1b718db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14373,7 +14373,7 @@ klona@^2.0.3, klona@^2.0.4: resolved "https://registry.yarnpkg.com/klona/-/klona-2.0.5.tgz#d166574d90076395d9963aa7a928fabb8d76afbc" integrity sha512-pJiBpiXMbt7dkzXe8Ghj/u4FfXOOa98fPW+bihOJ4SjnoijweJrNThJfd3ifXpXhREjpoF2mZVH1GfS9LV3kHQ== -knex@^1.0.4: +knex@1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/knex/-/knex-1.0.4.tgz#b9db3c60d0e3a4af37239bb879244e50eb748124" integrity sha512-cMQ81fpkVmr4ia20BtyrD3oPere/ir/Q6IGLAgcREKOzRVhMsasQ4nx1VQuDRJjqq6oK5kfcxmvWoYkHKrnuMA==