- ONLY FOR DEVELOPMENT. DO-NOT USE IN PRODUCTION
This repository contains a collection of two Features - cockroachdb
and postgres
. These Features serve as development only.
Each sub-section below shows a sample devcontainer.json
alongside example usage of the Feature.
Running cocckroachdb
inside will create a single-node
cluster. The cockroachdb
Feature will also expose the cockroachdb
UI on port 8080
by default. You can change this by setting the ui
option to a different port.
Available Options
Option | Default Value | Description |
---|---|---|
version |
v25.1.2 |
Specifies the version of CockroachDB to use. |
port |
26257 |
Port for accessing the CockroachDB cluster. |
ui |
8080 |
Port for accessing the CockroachDB UI. |
intallMolt |
true |
Install molt for migrations tasks. |
autoStart |
true |
Automatically start the CockroachDB instance. |
Example Usage
.devcontainer/devcontainer.json
Running postgres
inside the built container will create a postgres
instance. This feature will also expose the postgres
on port 5432
by default. You can change this by setting the port
option to a different port.
Available Options
Option | Default Value | Description |
---|---|---|
version |
14 |
Specifies the version of PostgreSQL to use. |
port |
5432 |
Port for accessing the PostgreSQL cluster. |
users |
none |
A list of users with format: user:pass. Multiple users, use ; for separation. Example: user1:pass1;user2:pass2 |
autoStart |
true |
Automatically start the PostgreSQL instance. |
sql |
none |
SQL file to run on startup. Must be relative to the main project |
Example Usage
.devcontainer/devcontainer.json
{
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/cockroachlabs/cockroach-university-devcontainers/postgres:1.0.1": {
"version": "14",
"users": "vscode:vscode",
"sql": "schemas/test.sql"
}
}
}
Requirements
- You need either Docker Desktop, Podman Desktop or Rancher Desktop installed and running (ONLY ONE).
- VS Code installed.
- DevContainers pluging installed. ID:
ms-vscode-remote.remote-containers
.
This example is about migrate PostgreSQL databases to CockroachDB using the provided features. This example will use MOLT.
-
Open a Terminal and create a folder for your project.
mkdir migration-example cd migration example
-
Start VSCode and open that folder. If you had installed the
code
command line, just execute:code .
-
In VSCode create a folder (
schemas
) and a file (test.sql
) for the PostgreSQL migration. The content of thetest.sql
is:CREATE TABLE products ( product_id SERIAL PRIMARY KEY, product_name VARCHAR(255), description TEXT, price DECIMAL(10, 2) ); CREATE TABLE inventory ( inventory_id SERIAL PRIMARY KEY, product_id INT, quantity INT, location VARCHAR(255), FOREIGN KEY (product_id) REFERENCES products(product_id) ); CREATE TABLE shipments ( shipment_id SERIAL PRIMARY KEY, order_id INT, product_id INT, quantity INT, shipment_date DATE, FOREIGN KEY (product_id) REFERENCES products(product_id) );
-
In VSCode create a folder
.devcontainer
and a file nameddevcontainer.json
and add the following content:{ "image": "mcr.microsoft.com/devcontainers/base:ubuntu", "features": { "ghcr.io/cockroachlabs/cockroach-university-devcontainers/cockroachdb:1": { "version": "v25.1.2" }, "ghcr.io/cockroachlabs/cockroach-university-devcontainers/postgres:1":{ "version": "14", "users": "vscode:vscode", "sql": "test.sql" } } }
- In VsCode access to your Command Palette by pressing
Ctrl+Shift+P
orCmd+Shift+P
on macOS to run commands. - Type
Remote-Containers: Reopen in Container
and select it to start the container. - Once the container is running, open a terminal in VSCode and execute the migration commands.
-
In the Terminal run the following command:
molt convert postgres --schema schema/test.sql --url '' --out crdb-migration.sql
.... more coming soon.