Feat(medusa): implement feature flags (#1768)

* feat: add feature flag loading in projects

* fix: make feature flag consume itself

* fix: rename container registration to featureFlagRouter

* fix: refactor

* behavioral feature flags

* add environment to server

* limit "useTemplateDb" to non feature flagged migrations

* filter migrations and entities according to those which are enabled in the environment

* run only migrations that are enabled when running 'medusa migrations run'

* add logging to the featureflag loader

* initial implementation of featureFlagEntity

* column descriptors

* initial startServerWithEnv (to be refactored)

* update commands

* final touches

* update loaders to fix unit tests

* enable all batch job tests

* update seed method

* add api test capabilities

* revert batch job test

* revert formatting changes

* pr feedback

* pr feedback

* remove unused imports

* rename feature flag decorators

* pr feedback

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
This commit is contained in:
Philip Korsholm
2022-07-04 15:39:30 +02:00
committed by GitHub
co-authored by Sebastian Rindom
parent f0704a7e17
commit 41681b45b1
19 changed files with 527 additions and 58 deletions
+21 -3
View File
@@ -31,10 +31,28 @@ class DatabaseFactory {
`@medusajs`,
`medusa`,
`dist`,
`migrations`
`migrations`,
`*.js`
)
)
const { getEnabledMigrations } = require(path.join(
cwd,
`node_modules`,
`@medusajs`,
`medusa`,
`dist`,
`commands`,
`utils`,
`get-migrations`
))
// filter migrations to only include those that dont have feature flags
const enabledMigrations = await getEnabledMigrations(
[migrationDir],
(flag) => false
)
await dropDatabase(
{
databaseName: this.templateDbName,
@@ -51,7 +69,7 @@ class DatabaseFactory {
type: "postgres",
name: "templateConnection",
url: `${DB_URL}/${this.templateDbName}`,
migrations: [`${migrationDir}/*.js`],
migrations: enabledMigrations,
})
await templateDbConnection.runMigrations()
@@ -92,7 +110,7 @@ class DatabaseFactory {
}
async destroy() {
let connection = await this.getMasterConnection()
const connection = await this.getMasterConnection()
await connection.query(`DROP DATABASE IF EXISTS "${this.templateDbName}";`)
await connection.close()