Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: added feature flags docs #2236

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions docs/content/advanced/backend/feature-flags/toggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Toggle Feature Flags

In this document, you’ll learn about what feature flags are and how to toggle them.

## Overview

Feature flags are used in Medusa to guard beta features that aren’t ready for live and production servers. This allows the Medusa team to keep publishing releases more frequently, while also working on necessary future features behind the scenes.

To use these beta features, you must enable their feature flags.

## Available Feature Flags

You can view a list of available feature flags that you can toggle in [the Medusa GitHub mono-repository](https:/medusajs/medusa/tree/master/packages/medusa/src/loaders/feature-flags). In each feature flag file, you can find the default value of the feature flag, its name, environment variable name, and more.

:::info

If a feature flag is enabled/disabled by default, you don’t need to manually enable/disable it. Only set the feature flag’s value if it’s different than the default.

:::

## Enable Feature Flags

:::caution

Features guarded by feature flags are experimental and beta features. Enable them with caution.

:::

There are two ways to enable a feature flag.

### Method One: Using Environment Variables

You can enable a feature by setting the value of its environment variable to `true`. You can find [the name of a feature flag’s environment variable in the loader file](https:/medusajs/medusa/tree/master/packages/medusa/src/loaders/feature-flags) it’s defined in. It is defined under the property `env_key` in the exported object.

For example, to enable the Tax-Inclusive Pricing beta feature, add the following environment variable:

```jsx
MEDUSA_FF_TAX_INCLUSIVE_PRICING=true
```

### Method Two: Using Server Settings

You can enable a feature by using the server settings in `medusa-config.js`. You can find [a feature flag’s key in the loader file](https:/medusajs/medusa/tree/master/packages/medusa/src/loaders/feature-flags) it’s defined in. It is defined under the property `key` in the exported object.

For example, to enable the Tax-Inclusive Pricing beta feature, add the following to the exported object in `medusa-config.js`:

```jsx
module.exports = {
featureFlags: {
tax_inclusive_pricing: true
},
//...
}
```

### Note About Precedence

The environment variable’s value has higher precedence over the server settings. So, if you use both these methods on your server, the value of the environment variable will be used.

For example, if the value of the environment variable is set to `false`, but the value of the feature flag in the server settings is set to `true`, the feature flag will take the value of the environment variable and will be disabled.

### Running Migrations

As feature flags generally include adding new entities or making changes to entities in the database, you must run the migrations after enabling the feature flag:

```bash
medusa migrations run
```

:::info

You can learn more about migrations in this documentation.

:::

## Disable Feature Flags

Disabling feature flags follows the same process as enabling the feature flags. All you have to do is change the value in the environment variables or the server settings to `false`.

Once you disable a feature flag, all endpoints, entities, services, or other related classes and functionalities are disabled.

### Revert Migrations

If you had the feature flag previously enabled, and you want to disable this feature flag completely, you might need to revert the migrations you ran when you enabled it.

You can follow [this documentation to learn how to revert the last migration you ran](https://docs.medusajs.com/cli/reference#migrations).

## What’s Next 🚀

- Learn more about [Migrations](../migrations/overview.md).
- Learn how to [configure your Medusa server](../../../usage/configurations.md).
9 changes: 4 additions & 5 deletions docs/content/advanced/backend/subscribers/events-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -1687,13 +1687,12 @@ This section holds all events related to sales channels.

:::note

As of Medusa v1.3.5, Sales Channels are available but guarded by a feature flag. To use Sales Channels, add the following environment variable:
As of Medusa v1.3.5, Sales Channels are available but guarded by a feature flag. To use Sales Channels either:

```bash
MEDUSA_FF_SALES_CHANNELS=true
```
1. Enable the `MEDUSA_FF_SALES_CHANNELS` environment variable;
2. Or enable the `sales_channels` key in the Medusa server's settings.

Then, run the [migrations](../migrations/overview.md#how-to-run-migrations).
You can learn more about enabling it in the [feature flags](../feature-flags/toggle.md) documentation.

:::

Expand Down
7 changes: 6 additions & 1 deletion docs/content/advanced/backend/taxes/inclusive-pricing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ In this document, you’ll learn how tax-inclusive pricing works in Medusa.

:::note

Tax Inclusive Pricing is currently in beta mode and guarded by a feature flag. To enable it, set the environment variable `MEDUSA_FF_TAX_INCLUSIVE_PRICING` to `true`, and [run migrations](../migrations/index.md#run-migration).
Tax Inclusive Pricing is currently in beta mode and guarded by a feature flag. To use Tax-Inclusive Pricing either:

1. Enable the `MEDUSA_FF_TAX_INCLUSIVE_PRICING` environment variable;
2. Or enable the `tax_inclusive_pricing` key in the Medusa server's settings.

You can learn more about enabling it in the [feature flags](../feature-flags/toggle.md) documentation.

:::

Expand Down
4 changes: 2 additions & 2 deletions docs/content/advanced/backend/upgrade-guides/1-3-6.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Following the addition of feature flags in version v1.3.3 and the addition of th

:::note

In version 1.3.6, Sales Channels are available but hidden behind feature flags. If you don’t have Sales Channels enabled, you don’t need to follow the steps detailed in this migration script.
In version 1.3.6, Sales Channels are available but guraded by [feature flags](../feature-flags/toggle.md). If you don’t have Sales Channels enabled, you don’t need to follow the steps detailed in this migration script.

:::

Expand All @@ -24,7 +24,7 @@ These environment variables are used in the data migration scripts in this upgra

## Sales Channels

Sales Channels were introduced in v1.3.5 behind a feature flag. By enabling Sales Channels, developers and users can associate products and other entities with a specific Sales Channel.
Sales Channels were introduced in v1.3.5 guarded by a [feature flag](../feature-flags/toggle.md). By enabling Sales Channels, developers and users can associate products and other entities with a specific Sales Channel.

However, if you upgraded Medusa to v1.3.5 and enabled Sales Channels, you must add every product to at least one Sales Channel manually. Otherwise, products can’t be added to carts in different Sales Channels.

Expand Down
5 changes: 5 additions & 0 deletions www/docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ module.exports = {
id: "advanced/backend/migrations/index",
label: "Create a Migration"
},
{
type: "doc",
id: "advanced/backend/feature-flags/toggle",
label: "Toggle Feature Flags"
},
{
type: "doc",
id: "advanced/backend/cron-jobs/create",
Expand Down