diff --git a/www/apps/cloud/app/database/page.mdx b/www/apps/cloud/app/database/page.mdx index 58b5f1b301..efca3f995b 100644 --- a/www/apps/cloud/app/database/page.mdx +++ b/www/apps/cloud/app/database/page.mdx @@ -32,13 +32,33 @@ If you need to restore a database backup, you can contact support to request a p --- -## Accessing the Database +## Connect to the Database -In some cases, you may need to access the database directly, such as to export or import data. However, since Cloud is a managed service, you can't directly access your database. Medusa also doesn't expose the database connection details. +In some cases, you may need to access the database directly, such as to export or import data. -This section provides alternative ways to interact with your database based on your needs. +Medusa gives you read access to your database, which is useful when you need to export data, perform analytics, or troubleshoot issues. -### Option 1: Database Dump +To get the read-only connection string for an environment's database: + +1. From the [organization's dashboard](../organizations/page.mdx), click on the environment's project. +2. In the project's dashboard, click on the name of the environment. For example, "Production". +3. In the environment's dashboard, click on the "Settings" tab. +4. Choose the "Database" tab from the sidebar. +5. Copy the read-only connection string in the code block. + +![Read-only connection string in Database settings](https://res.cloudinary.com/dza7lstvk/image/upload/v1755271713/Cloud/CleanShot_2025-08-15_at_18.27.58_2x_fqlync.png) + +Then, you can connect to your database using a PostgreSQL client. For example, using the `psql` command-line tool: + +```bash +psql "postgresql://..." +``` + +After connecting to the database, you can run SQL queries to interact with your data. + +--- + +## Import/Export Database Dumps Medusa allows you to export and import database dumps for any environment. This is useful for seeding the database with initial data, migrating from other hosting platforms, or debugging issues locally. @@ -47,7 +67,7 @@ To import or export a database dump for an environment: 1. From the [organization's dashboard](../organizations/page.mdx), click on the environment's project. 2. In the project's dashboard, click on the name of the environment. For example, "Production". 3. In the environment's dashboard, click on the "Settings" tab. -4. Scroll down to the "Database dump" section. +4. Choose the "Database" tab from the sidebar and find the "Database dump" section. ![Database dump section highlighted in the environment settings](https://res.cloudinary.com/dza7lstvk/image/upload/v1750169625/Cloud/CleanShot_2025-06-17_at_17.13.21_2x_l7vw3w.png) @@ -71,36 +91,6 @@ Make sure you're generating the database dump from PostgreSQL v16 and that [pg_d pg_restore --no-acl --no-owner --no-privileges --clean --if-exists -d 'postgres://postgres:secret@localhost:5432/mydatabase' mydata.dump ``` -### Option 2: Custom API Routes - -In some cases, you may need more flexibility interacting with the database. For example, you might need to retrieve specific data for analysis, or update data coming from an external source. - -To interact with an environment's database with more flexibility, you can: - -- [Create a custom API route](!docs!/learn/fundamentals/api-routes) that retrieves or updates data in the database. - - Make sure to create the API route under the `/admin` prefix, or [protect the API route with an API key](!docs!/learn/fundamentals/api-routes/protected-routes). -- Create a secret API key for a user using the [Medusa Admin](!user-guide!/settings/developer/secret-api-keys#create-secret-api-key). -- Call the API route to perform database operations, [passing the API key in the header](!api!/admin#2-api-token). For example, to send the request in a Node.js application: - -```ts -const api_key_token = "YOUR_API_KEY" -fetch(`https://my-project.medusajs.app/admin/my-route`, { - headers: { - Authorization: `Basic ${ - Buffer.from(`${api_key_token}:`).toString("base64") - }`, - }, -}) -``` - -Where: - -- `YOUR_API_KEY` is the secret API key you created. -- `my-project.medusajs.app` is the [environment's URL](../deployments/page.mdx#find-environments-url). -- `my-route` is the path to the custom API route you created. - -This approach allows you to perform any database operations you need, such as retrieving or updating data, without directly accessing the database. - --- ## Change Preview Environment Database diff --git a/www/apps/cloud/app/environments/environment-variables/page.mdx b/www/apps/cloud/app/environments/environment-variables/page.mdx index ac27c4002e..f326c0b1e1 100644 --- a/www/apps/cloud/app/environments/environment-variables/page.mdx +++ b/www/apps/cloud/app/environments/environment-variables/page.mdx @@ -46,7 +46,8 @@ The following environment variable names are reserved by Cloud and you can't use To add environment variables to an environment: 1. In the [environment's dashboard](../long-lived/page.mdx#open-environment-dashboard), click on the "Settings" tab. -2. In the "Add new environment variables" section, there are different ways you can add environment variables: +2. Choose the "Environment Variables" tab from the sidebar. +3. In the "Add new environment variables" section, there are different ways you can add environment variables: - **Manually**: - Enter the key and value of the environment variable in the respective fields. - Click the "Add another" button to add another variable. @@ -54,7 +55,7 @@ To add environment variables to an environment: - If you copied environment variables in a `.env` file format, you can paste them directly into the "Key" field. The environment variables will be pre-filled for you. - **Import `.env` file**: - If you have a `.env` file that defines your environment variables, click the "Import .env" button to upload the file. The environment variables will be automatically extracted and added to the list. -3. Once you're done, click the "Save" button to save the environment variables. +4. Once you're done, click the "Save" button to save the environment variables. @@ -71,14 +72,15 @@ After adding the environment variables, you must [redeploy the environment](../l To edit an environment variable: 1. In the [environment's dashboard](../long-lived/page.mdx#open-environment-dashboard), click on the "Settings" tab. -2. In the "Environment variables" section, find the variable you want to edit. -3. Click the icon at the variable's right side. -4. Choose "Edit" from the dropdown menu. +2. Choose the "Environment Variables" tab from the sidebar. +3. In the "Environment variables" section, find the variable you want to edit. +4. Click the icon at the variable's right side. +5. Choose "Edit" from the dropdown menu. ![Edit environment variable in the environment's settings tab](https://res.cloudinary.com/dza7lstvk/image/upload/v1749816223/Cloud/CleanShot_2025-06-13_at_15.03.21_2x_a38dch.png) -5. In the side window that opens, you can edit the variable's key, value, and whether it's sensitive. -6. Once you're done, click the "Save" button. +6. In the side window that opens, you can edit the variable's key, value, and whether it's sensitive. +7. Once you're done, click the "Save" button. @@ -95,9 +97,10 @@ After editing the environment variable, you must [redeploy the environment](../l To delete an environment variable: 1. In the [environment's dashboard](../long-lived/page.mdx#open-environment-dashboard), click on the "Settings" tab. -2. In the "Environment variables" section, find the variable you want to delete. -3. Click the icon at the variable's right side. -4. Choose "Delete" from the dropdown menu. +2. Choose the "Environment Variables" tab from the sidebar. +3. In the "Environment variables" section, find the variable you want to delete. +4. Click the icon at the variable's right side. +5. Choose "Delete" from the dropdown menu. @@ -116,7 +119,8 @@ You can export an environment's variables as a `.env` file. This is useful for d To export an environment's variables: 1. In the [environment's dashboard](../long-lived/page.mdx#open-environment-dashboard), click on the "Settings" tab. -2. In the "Environment variables" section, click on the "Export .env" button at the top right of the section. +2. Choose the "Environment Variables" tab from the sidebar. +3. In the "Environment variables" section, click on the "Export .env" button at the top right of the section. A file download will start with the name `env.txt`, which contains the environment variables in `.env` format. diff --git a/www/apps/cloud/app/environments/long-lived/page.mdx b/www/apps/cloud/app/environments/long-lived/page.mdx index 8290659879..dcd6903e11 100644 --- a/www/apps/cloud/app/environments/long-lived/page.mdx +++ b/www/apps/cloud/app/environments/long-lived/page.mdx @@ -190,10 +190,11 @@ In an environment's "Settings" tab, you can manage the deployment rules for the To change the branch associated with an environment using deployment rules: 1. In the [environment's dashboard](#open-environment-dashboard), click on the "Settings" tab. -2. In the "Deployment rules" section, click the icon at the right side of the `branch` rule. -3. Choose "Edit" from the dropdown menu. -4. In the side window that opens, you can change the branch associated with the environment. -5. Once you're done, click the "Save" button. +2. Choose the "Deployment rules" tab from the sidebar. +3. Click the icon at the right side of the `branch` rule. +4. Choose "Edit" from the dropdown menu. +5. In the side window that opens, you can change the branch associated with the environment. +6. Once you're done, click the "Save" button. Changes will take effect the next time you push a commit to the new branch. The environment will be redeployed with the latest changes from the new branch. @@ -224,7 +225,6 @@ You can delete any environment in your project, except for the Production enviro To delete an environment: 1. In the environment's dashboard, click on the "Settings" tab. -2. Scroll down to the "Delete environment" section. -3. Click the "Delete Environment" button. +2. Click the "Delete Environment" button. ![Delete environment button in the environment's settings tab](https://res.cloudinary.com/dza7lstvk/image/upload/v1749816910/Cloud/CleanShot_2025-06-13_at_15.14.50_2x_qm8hfi.png) diff --git a/www/apps/cloud/generated/edit-dates.mjs b/www/apps/cloud/generated/edit-dates.mjs index 05c6a7b6bd..94b69b3477 100644 --- a/www/apps/cloud/generated/edit-dates.mjs +++ b/www/apps/cloud/generated/edit-dates.mjs @@ -6,7 +6,7 @@ export const generatedEditDates = { "app/deployments/page.mdx": "2025-06-25T07:57:13.059Z", "app/organizations/page.mdx": "2025-06-25T07:13:02.263Z", "app/notifications/page.mdx": "2025-06-25T07:27:37.642Z", - "app/database/page.mdx": "2025-06-25T07:54:40.231Z", + "app/database/page.mdx": "2025-08-15T15:30:37.814Z", "app/redis/page.mdx": "2025-06-25T07:57:23.246Z", "app/s3/page.mdx": "2025-06-25T07:57:24.832Z", "app/draft-order-plugin/page.mdx": "2025-06-25T07:57:14.898Z", @@ -15,8 +15,8 @@ export const generatedEditDates = { "app/logs/page.mdx": "2025-06-19T07:44:38.336Z", "app/update-medusa/page.mdx": "2025-06-25T07:57:30.170Z", "app/connect-storefront/page.mdx": "2025-06-25T07:47:00.499Z", - "app/environments/environment-variables/page.mdx": "2025-06-25T07:42:53.521Z", - "app/environments/long-lived/page.mdx": "2025-07-14T11:01:54.536Z", + "app/environments/environment-variables/page.mdx": "2025-08-15T15:35:24.085Z", + "app/environments/long-lived/page.mdx": "2025-08-15T15:38:19.187Z", "app/environments/preview/page.mdx": "2025-06-25T08:00:00.839Z", "app/faq/page.mdx": "2025-08-15T14:32:23.372Z" } \ No newline at end of file