### Run the Metabase Embedding SDK Quickstart CLI Source: https://www.metabase.com/docs/latest/embedding/sdk/quickstart-cli Execute this command in your React application's root directory to start the setup process. The CLI will guide you through the necessary steps for embedding Metabase. ```bash npx @metabase/embedding-sdk-react@latest start ``` -------------------------------- ### Start the application server Source: https://www.metabase.com/docs/latest/embedding/sdk/quickstart-with-sample-app Starts the backend server for the sample application. This command should be executed after installing dependencies in the 'server' directory. ```bash npm start ``` -------------------------------- ### Start Metabase after Migration (PostgreSQL Example) Source: https://www.metabase.com/docs/latest/installation-and-operation/migrating-from-h2 After successfully migrating your database, start Metabase using the new application database configuration. This example shows how to start Metabase with PostgreSQL connection details. ```bash export MB_DB_TYPE=postgres export MB_DB_CONNECTION_URI="jdbc:postgresql://:5432/metabase?user=&password=" java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar ``` -------------------------------- ### Start a New SQL Query Source: https://www.metabase.com/docs/latest/questions/native-editor/writing-sql Paste this query into the SQL editor to get started. Ensure the Sample Database is selected. ```sql SELECT sum(subtotal), created_at FROM orders GROUP BY created_at; ``` -------------------------------- ### Run Metabase Development Environment Source: https://www.metabase.com/docs/latest/developers-guide/devenv Starts both the frontend and backend development servers simultaneously. Ensure you have completed the initial setup. ```bash bun run dev ``` -------------------------------- ### Metabase Initialization Log Source: https://www.metabase.com/docs/latest/installation-and-operation/running-the-metabase-jar-file Example log output indicating that Metabase has successfully started. Look for 'Metabase Initialization COMPLETE' to confirm. ```text ...\n06-19 10:29:34 INFO metabase.task :: Initializing task CheckForNewVersions\n06-19 10:29:34 INFO metabase.task :: Initializing task SendAnonymousUsageStats\n06-19 10:29:34 INFO metabase.task :: Initializing task SendAbandomentEmails\n06-19 10:29:34 INFO metabase.task :: Initializing task SendPulses\n06-19 10:29:34 INFO metabase.task :: Initializing task SendFollowUpEmails\n06-19 10:29:34 INFO metabase.task :: Initializing task TaskHistoryCleanup\n06-19 10:29:34 INFO metabase.core :: Metabase Initialization COMPLETE ``` -------------------------------- ### Start the Mock Express Server for JWTs Source: https://www.metabase.com/docs/latest/embedding/sdk/quickstart-cli After the CLI sets up the mock server for JWTs, navigate to the mock server directory and run this command to start the server. This is necessary for multi-tenancy and permissions setup. ```bash npm run start ``` -------------------------------- ### Start Backend REPL and Server Source: https://www.metabase.com/docs/latest/developers-guide/devenv Starts the backend server and REPL. This is an alternative way to start the server, often used when initiating from an editor. ```clojure (do (dev) (start!)) ``` -------------------------------- ### Start Sample App with Docker Source: https://www.metabase.com/docs/latest/embedding/sdk/quickstart-with-sample-app Run the yarn start script to build and launch the sample application along with a Metabase Docker container. ```bash yarn start ``` -------------------------------- ### Automated Development Environment Installation Source: https://www.metabase.com/docs/latest/developers-guide/devenv Run this script to install mise, set up your shell, and install all required development tools like Node.js, Java, Clojure, Bun, and Babashka. ```bash ./bin/dev-install ``` -------------------------------- ### Docker Compose Command for LocalStack Setup Source: https://www.metabase.com/docs/latest/data-studio/transforms/python-runner Command to start the services defined in the Docker Compose file for local testing. ```bash docker compose up -d ``` -------------------------------- ### Start REPL for Driver Development Source: https://www.metabase.com/docs/latest/developers-guide/drivers/multimethods Command to start a Clojure REPL with development dependencies for Metabase drivers, enabling interactive development. ```bash clojure -A:dev:drivers:drivers-dev ``` -------------------------------- ### Setup API Operations Source: https://www.metabase.com/docs/latest/api Endpoint for initiating the Metabase setup process. ```APIDOC ## POST /api/setup ### Description Initiates the Metabase setup process. ### Method POST ### Endpoint /api/setup ``` -------------------------------- ### Install Java and Node.js on Ubuntu/Debian Source: https://www.metabase.com/docs/latest/developers-guide/build Install OpenJDK 21 and Node.js on recent Ubuntu/Debian systems. Clojure and Bun need to be installed separately. ```bash sudo apt install openjdk-21-jdk nodejs ``` -------------------------------- ### Start Metabase Backend Source: https://www.metabase.com/docs/latest/developers-guide/build Starts the Metabase backend server. Keep this terminal tab running while Metabase is active. ```shell clojure -M:run ``` -------------------------------- ### Install server dependencies Source: https://www.metabase.com/docs/latest/embedding/sdk/quickstart-with-sample-app Installs all the necessary Node.js packages for the server application using npm. This command should be run from the 'server' directory. ```bash npm install ``` -------------------------------- ### Install Docker using Homebrew Source: https://www.metabase.com/docs/latest/developers-guide/dev-branch-docker Use this command to install Docker Desktop if you prefer using Homebrew for package management. ```bash brew install --cask docker ``` -------------------------------- ### Get Help for a MAGE Task Source: https://www.metabase.com/docs/latest/developers-guide/mage To get detailed usage information and examples for a specific MAGE task, append the -h flag to the task command. This example shows how to get help for the 'kondo' task. ```bash ./bin/mage kondo -h ``` -------------------------------- ### Get Substring from Left Source: https://www.metabase.com/docs/latest/questions/query-builder/expressions/substring Extracts a specified number of characters starting from a given position from the left of a string. Use this to get a fixed-length segment from the beginning of a string. ```Metabase Expression substring([Mission ID], 9, 3) ``` -------------------------------- ### Metabase JWT SSO GET Request Example Source: https://www.metabase.com/docs/latest/people-and-groups/authenticating-with-jwt This is the GET request format Metabase expects from your SSO provider after a successful login. It includes the JWT and the original URI to return to. ```http http://localhost:3000/auth/sso?jwt=TOKEN_GOES_HERE&return_to=/question/1-superb-question ``` -------------------------------- ### Metabase Database and User Configuration Source: https://www.metabase.com/docs/latest/configuring-metabase/config-file Example of setting up an initial admin user and a single PostgreSQL database connection using the configuration file. This is useful for new Metabase instances. ```yaml version: 1 config: users: - first_name: Cam last_name: Era password: 2cans3cans4cans email: cam@example.com databases: - name: test-data (Postgres) engine: postgres details: host: localhost port: 5432 user: dbuser password: "{{ env POSTGRES_TEST_DATA_PASSWORD }}" dbname: test-data ``` -------------------------------- ### Install Metabase Embedding SDK for Metabase 55 Source: https://www.metabase.com/docs/latest/embedding/sdk/version For Metabase 56 and earlier, the SDK major version must match the Metabase major version. Use the matching `@major-stable` dist-tag. This example shows installation for Metabase 55. ```bash npm install @metabase/embedding-sdk-react@55-stable ``` -------------------------------- ### Example INSERT Action Source: https://www.metabase.com/docs/latest/actions/custom This snippet shows how to insert new records into a table. It includes examples of various data types and how to reference variables for each column. ```sql INSERT INTO invoices ( account_id ,payment ,expected_invoice ,plan ,date_received ) VALUES ( {{ account_id }} ,{{ payment }} ,CAST ({{expected_invoice}} AS boolean) ,{{plan}} ,({{date_received}}) ); ``` -------------------------------- ### Clone Metabase Sample App Repository Source: https://www.metabase.com/docs/latest/embedding/sdk/quickstart-with-sample-app Clone the sample React app repository to get started with Metabase embedding. ```bash git clone git@github.com:metabase/metabase-nodejs-react-sdk-embedding-sample.git ``` -------------------------------- ### Copy .env.example to .env Source: https://www.metabase.com/docs/latest/embedding/sdk/quickstart-with-sample-app Copies the example environment file to a new file named .env. This is the first step in configuring the sample application's environment variables. ```bash cp .env.example .env ``` -------------------------------- ### Metabase Configuration File Template Example Source: https://www.metabase.com/docs/latest/configuring-metabase/config-template An example of a Metabase configuration file template, showing sections for databases, users, and settings. It includes guidance on updating these sections and using environment variables. ```clojure # A config file template for Metabase. # You'll need to update (or remove) the `users` and `databases` sections. # The settings in `settings` include default values. We recommend removing # or commenting out settings that you don't set. # To use an env var, you can use a template string: "" # Note the quote marks wrapping the env var template. # For more on the configuration file, see: # https://www.metabase.com/docs/latest/configuring-metabase/config-file # For more on what each setting does, check out: ``` -------------------------------- ### Navigate to server directory Source: https://www.metabase.com/docs/latest/embedding/sdk/quickstart-with-sample-app Changes the current directory to the 'server' subdirectory of the sample application. This is necessary to perform server-specific setup tasks. ```bash cd server ``` -------------------------------- ### Multiple Optional Clauses in SQL Source: https://www.metabase.com/docs/latest/questions/native-editor/optional-variables Example of using multiple optional clauses in SQL, requiring a regular WHERE clause followed by optional clauses starting with AND. ```sql SELECT count(*) FROM products WHERE TRUE [[AND id = {{id}}]] [[AND {{category}}]] ``` -------------------------------- ### Set Site URL for Containerized Setups Source: https://www.metabase.com/docs/latest/ai/mcp Environment variable to set the Site URL for containerized Metabase instances, ensuring correct OAuth discovery. Example for localhost. ```yaml MB_SITE_URL: http://localhost:3000 ``` -------------------------------- ### Loading New Metabase with Premium Embedding Token Source: https://www.metabase.com/docs/latest/configuring-metabase/config-file For new installations, supply the `MB_PREMIUM_EMBEDDING_TOKEN` environment variable when starting Metabase to enable configuration file loading, which is a Pro/Enterprise feature. ```bash MB_PREMIUM_EMBEDDING_TOKEN="[your token]" java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar ``` -------------------------------- ### Enable Metabase Service on Boot Source: https://www.metabase.com/docs/latest/installation-and-operation/running-metabase-as-service Command to ensure the Metabase service starts automatically when the system boots up. ```bash sudo systemctl enable metabase.service ``` -------------------------------- ### Get Shell Access to Heroku Server Source: https://www.metabase.com/docs/latest/cloud/migrate/heroku Use Heroku Exec to gain shell access to your Metabase application running on Heroku. This command requires the Heroku CLI to be installed. ```bash heroku ps:exec --app your-metabase-app-name-in-heroku ``` -------------------------------- ### Copy Docker Environment Template Source: https://www.metabase.com/docs/latest/embedding/sdk/quickstart-with-sample-app Copy the example environment file to create your Docker environment configuration. ```bash cp .env.docker.example .env.docker ``` -------------------------------- ### Setup Pattern for Unit Tests Source: https://www.metabase.com/docs/latest/developers-guide/frontend This pattern demonstrates how to set up test components using `renderWithProviders` for app context and data mocking. It includes a mock collection and tests updating the collection name. ```javascript import React from "react"; import userEvent from "@testing-library/user-event"; import { Collection } from "metabase-types/api"; import { createMockCollection } from "metabase-types/api/mocks"; import { renderWithProviders, screen } from "__support__/ui"; import CollectionHeader from "./CollectionHeader"; interface SetupOpts { collection: Collection; } const setup = ({ collection }: SetupOpts) => { const onUpdateCollection = jest.fn(); renderWithProviders( , ); return { onUpdateCollection }; }; describe("CollectionHeader", () => { it("should be able to update the name of the collection", () => { const collection = createMockCollection({ name: "Old name", }); const { onUpdateCollection } = setup({ collection, }); await userEvent.clear(screen.getByDisplayValue("Old name")); await userEvent.type(screen.getByPlaceholderText("Add title"), "New title"); await userEvent.tab(); expect(onUpdateCollection).toHaveBeenCalledWith({ ...collection, name: "New name", }); }); }); ``` -------------------------------- ### Metabase JWT SSO POST Request Example Source: https://www.metabase.com/docs/latest/people-and-groups/authenticating-with-jwt An alternative to the GET request, this POST request sends the JWT in the JSON body. The 'return_to' parameter can still be included as a query parameter. ```http POST /auth/sso?return_to=/question/1-superb-question Content-Type: application/json {"jwt": "TOKEN_GOES_HERE"} ``` -------------------------------- ### Get Substring from Right Source: https://www.metabase.com/docs/latest/questions/query-builder/expressions/substring Extracts a specified number of characters from the right of a string. This is achieved by calculating the starting position based on the total length of the string and the desired number of characters from the right. ```Metabase Expression substring([Mission ID], (1 + length([Mission ID]) - 3), 3) ``` -------------------------------- ### Build Metabase Driver Source: https://www.metabase.com/docs/latest/developers-guide/driver-changelog Example command for building a Metabase driver using bash. Ensure you are in the Metabase repository checkout and have the absolute path to your driver project. ```bash # Example for building the driver with bash or similar # switch to the local checkout of the Metabase repo cd /path/to/metabase/repo # get absolute path to the driver project directory DRIVER_PATH=`readlink -f ~/sudoku-driver` ``` -------------------------------- ### Start Python Runner for Production Source: https://www.metabase.com/docs/latest/data-studio/transforms/python-runner Launches the Python Runner in detached mode for production use. It requires an `AUTH_TOKEN` for secure API communication. This setup assumes external S3 storage is configured in Metabase. ```bash docker run -d \ --network metabase-network \ -e AUTH_TOKEN=your-secure-token-here \ --name python-runner metabase/python-runner:latest ``` -------------------------------- ### Implement Honey SQL 2 for a Driver Source: https://www.metabase.com/docs/latest/developers-guide/driver-changelog Example of how to implement the `honey-sql-version` multimethod to opt-in to Honey SQL 2 compilation for a specific driver. This is recommended for SQL drivers. ```clojure (require '[metabase.driver.sql.query-processor :as sql.qp]) ;;; use Honey SQL 2 for :my-driver (defmethod sql.qp/honey-sql-version :my-driver [_driver] 2) ``` -------------------------------- ### Snowflake Schema Filtering with Wildcards Source: https://www.metabase.com/docs/latest/databases/connections/snowflake When using 'Only these...' or 'All except...' schema options, you can use the '*' wildcard to match multiple schemas. This example shows syncing schemas starting with 'B'. ```text B* ``` -------------------------------- ### List All Driver Multimethods Source: https://www.metabase.com/docs/latest/developers-guide/drivers/multimethods Use the `clojure -M:run driver-methods` command to list all available driver namespaces and multimethods. This helps in understanding the full set of methods you can implement. ```bash clojure -M:run driver-methods ``` -------------------------------- ### Substring Function Example Source: https://www.metabase.com/docs/latest/questions/query-builder/expressions/substring Extracts a portion of text from a given string using a starting position and a specified length. The first character of the string is considered position 1, and the length must be a positive number. ```Metabase Query Language substring("user_id@email.com", 1, 7) ``` -------------------------------- ### Split string and get nth part Source: https://www.metabase.com/docs/latest/questions/query-builder/expressions-list Use `splitPart` to divide a string by a delimiter and retrieve a specific substring based on its position. The position index starts at 1. This function is available in PostgreSQL, MySQL/MariaDB, BigQuery, Redshift, Clickhouse, and Snowflake. ```Metabase Expression Language splitPart([Date string], " ", 1) ``` ```Metabase Expression Language splitPart("First name, Middle Name, Last name", ", ", 3) ``` -------------------------------- ### Initialize a Bare Git Repository Source: https://www.metabase.com/docs/latest/installation-and-operation/remote-sync Create a bare Git repository on the same filesystem as your Metabase process. A bare repository is required for Remote Sync to push changes. ```bash git init --bare /path/to/your-repo.git ``` -------------------------------- ### PostgreSQL Role and Policy Setup for Impersonation Source: https://www.metabase.com/docs/latest/permissions/impersonation This SQL example demonstrates how to create a role, grant select privileges on all tables, and set a row-level security policy for a specific role in PostgreSQL. This is used to restrict data access based on user roles when impersonation is enabled in Metabase. ```sql CREATE ROLE vermont_sales_team; GRANT SELECT ON ALL TABLES IN SCHEMA PUBLIC TO vermont_sales_team; CREATE POLICY vermont ON people FOR SELECT TO vermont_sales_team USING (state = 'VT'); ALTER TABLE people ENABLE ROW LEVEL SECURITY; ``` -------------------------------- ### Metabase Database Configuration with Uploads Enabled Source: https://www.metabase.com/docs/latest/configuring-metabase/config-file Example demonstrating how to configure a database connection along with settings for enabling and configuring uploads, including schema name and table prefix. ```yaml version: 1 config: users: - first_name: Cam last_name: Era password: 2cans3cans4cans email: cam@example.com databases: - name: test-data (Postgres) engine: postgres details: host: localhost port: 5432 user: dbuser password: "{{ env POSTGRES_TEST_DATA_PASSWORD }}" dbname: test-data uploads_enabled: true uploads_schema_name: uploads uploads_table_prefix: uploads_ ```