Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ The dashboard makes it easy to compare different algorithms or hyperparameters a
See it in action — <a href="https://cloud.postgresml.org/" target="_blank">cloud.postgresml.org</a>
</h2>

Please see the [quick start instructions](https://postgresml.org/user_guides/setup/quick_start_with_docker/) for general information on installing or deploying PostgresML. A [developer guide](https://postgresml.org/developer_guide/overview/) is also available for those who would like to contribute.

## What's in the box
See the documentation for a complete **[list of functionality](https://postgresml.org/)**.

Expand Down
33 changes: 1 addition & 32 deletions pgml-dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,4 @@

PostgresML provides a dashboard with analytical views of the training data and model performance, as well as integrated notebooks for rapid iteration. It is primarily written in Rust using [Rocket](https://rocket.rs/) as a lightweight web framework and [SQLx](https://github.com/launchbadge/sqlx) to interact with the database.

Please see the [online documentation](https://postgresml.org/user_guides/setup/quick_start_with_docker/) for general information on installing or deploying PostgresML. This document is intended to help developers set up a local copy of the dashboard.

## Requirements

The dashboard requires a Postgres database with the [pgml-extension](https://github.com/postgresml/postgresml/tree/master/pgml-extension) to generate the core schema. See that subproject for developer setup.

We develop and test this web application on Linux, OS X, and Windows using WSL2.

## Build process

You'll need to specify a database url for the extension to interact with via an environment variable:

```commandline
export DATABASE_URL=postgres://user_name:password@localhost:5432/database_name
```

Build and run:

```commandline
cargo run
```

Incremental and automatic compilation for development cycles is supported with:

```commandline
cargo watch --exec run
```

Run tests:
```commandline
cargo test
```
Please see the [quick start instructions](https://postgresml.org/user_guides/setup/quick_start_with_docker/) for general information on installing or deploying PostgresML. A [developer guide](https://postgresml.org/developer_guide/overview/) is also available for those who would like to contribute.
4 changes: 2 additions & 2 deletions pgml-dashboard/migrations/20221125201109_notebook.down.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-- Add down migration script here
DROP TABLE notebook_cells;
DROP TABLE notebooks;
DROP TABLE pgml.notebook_cells;
DROP TABLE pgml.notebooks;
6 changes: 3 additions & 3 deletions pgml-dashboard/migrations/20221125201109_notebook.up.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
-- Add up migration script here
CREATE TABLE notebooks (
CREATE TABLE pgml.notebooks (
id BIGSERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT NOW()
);

CREATE TABLE notebook_cells (
CREATE TABLE pgml.notebook_cells (
id BIGSERIAL PRIMARY KEY,
notebook_id BIGINT NOT NULL REFERENCES notebooks(id),
notebook_id BIGINT NOT NULL REFERENCES pgml.notebooks(id),
cell_type INT NOT NULL,
cell_number INT NOT NULL,
version INT NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-- Add down migration script here
TRUNCATE notebook_cells CASCADE;
TRUNCATE notebooks CASCADE;
TRUNCATE pgml.notebook_cells CASCADE;
TRUNCATE pgml.notebooks CASCADE;
366 changes: 183 additions & 183 deletions pgml-dashboard/migrations/20221129170843_notebooks_data.up.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-- Add down migration script here
DROP TABLE uploaded_files;
DROP TABLE pgml.uploaded_files;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Add up migration script here
-- Add up migration script here
CREATE TABLE uploaded_files (
CREATE TABLE pgml.uploaded_files (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT NOW()
);
2 changes: 1 addition & 1 deletion pgml-dashboard/src/guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ impl<'r> FromRequest<'r> for Cluster {
pub fn default_database_url() -> String {
match var("DATABASE_URL") {
Ok(val) => val,
Err(_) => "postgres:///dashboard".to_string(),
Err(_) => "postgres:///pgml".to_string(),
}
}
5 changes: 5 additions & 0 deletions pgml-dashboard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod templates;

use guards::Cluster;
use responses::{BadRequest, ResponseOk};
use sqlx::Executor;

/// This struct contains information specific to the cluster being displayed in the dashboard.
///
Expand Down Expand Up @@ -50,6 +51,10 @@ impl Clusters {
.max_connections(5)
.idle_timeout(std::time::Duration::from_millis(15_000))
.min_connections(0)
.after_connect(|conn, _meta| Box::pin(async move {
conn.execute("SET application_name = 'pgml_dashboard';").await?;
Ok(())
}))
.connect_lazy(database_url)?;

pools.insert(cluster_id, pool.clone());
Expand Down
26 changes: 13 additions & 13 deletions pgml-dashboard/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub struct Notebook {
impl Notebook {
pub async fn get_by_id(pool: &PgPool, id: i64) -> anyhow::Result<Notebook> {
Ok(
sqlx::query_as!(Notebook, "SELECT * FROM notebooks WHERE id = $1", id,)
sqlx::query_as!(Notebook, "SELECT * FROM pgml.notebooks WHERE id = $1", id,)
.fetch_one(pool)
.await?,
)
Expand All @@ -95,23 +95,23 @@ impl Notebook {
pub async fn create(pool: &PgPool, name: &str) -> anyhow::Result<Notebook> {
Ok(sqlx::query_as!(
Notebook,
"INSERT INTO notebooks (name) VALUES ($1) RETURNING *",
"INSERT INTO pgml.notebooks (name) VALUES ($1) RETURNING *",
name,
)
.fetch_one(pool)
.await?)
}

pub async fn all(pool: &PgPool) -> anyhow::Result<Vec<Notebook>> {
Ok(sqlx::query_as!(Notebook, "SELECT * FROM notebooks")
Ok(sqlx::query_as!(Notebook, "SELECT * FROM pgml.notebooks")
.fetch_all(pool)
.await?)
}

pub async fn cells(&self, pool: &PgPool) -> anyhow::Result<Vec<Cell>> {
Ok(sqlx::query_as!(
Cell,
"SELECT * FROM notebook_cells
"SELECT * FROM pgml.notebook_cells
WHERE notebook_id = $1
AND deleted_at IS NULL
ORDER BY cell_number",
Expand All @@ -123,7 +123,7 @@ impl Notebook {

pub async fn reset(&self, pool: &PgPool) -> anyhow::Result<()> {
let _ = sqlx::query!(
"UPDATE notebook_cells
"UPDATE pgml.notebook_cells
SET
execution_time = NULL,
rendering = NULL
Expand Down Expand Up @@ -189,15 +189,15 @@ impl Cell {
"
WITH
lock AS (
SELECT * FROM notebooks WHERE id = $1 FOR UPDATE
SELECT * FROM pgml.notebooks WHERE id = $1 FOR UPDATE
),
max_cell AS (
SELECT COALESCE(MAX(cell_number), 0) AS cell_number
FROM notebook_cells
FROM pgml.notebook_cells
WHERE notebook_id = $1
AND deleted_at IS NULL
)
INSERT INTO notebook_cells
INSERT INTO pgml.notebook_cells
(notebook_id, cell_type, contents, cell_number, version)
VALUES
($1, $2, $3, (SELECT cell_number + 1 FROM max_cell), 1)
Expand Down Expand Up @@ -231,7 +231,7 @@ impl Cell {
cell_number,
version,
deleted_at
FROM notebook_cells
FROM pgml.notebook_cells
WHERE id = $1
",
id,
Expand All @@ -250,7 +250,7 @@ impl Cell {
self.contents = contents.to_string();

let _ = sqlx::query!(
"UPDATE notebook_cells
"UPDATE pgml.notebook_cells
SET
cell_type = $1,
contents = $2,
Expand All @@ -269,7 +269,7 @@ impl Cell {
pub async fn delete(&self, pool: &PgPool) -> anyhow::Result<Cell> {
Ok(sqlx::query_as!(
Cell,
"UPDATE notebook_cells
"UPDATE pgml.notebook_cells
SET deleted_at = NOW()
WHERE id = $1
RETURNING id,
Expand Down Expand Up @@ -337,7 +337,7 @@ impl Cell {
};

sqlx::query!(
"UPDATE notebook_cells SET rendering = $1 WHERE id = $2",
"UPDATE pgml.notebook_cells SET rendering = $1 WHERE id = $2",
rendering,
self.id
)
Expand Down Expand Up @@ -797,7 +797,7 @@ impl UploadedFile {
pub async fn create(pool: &PgPool) -> anyhow::Result<UploadedFile> {
Ok(sqlx::query_as!(
UploadedFile,
"INSERT INTO uploaded_files (id, created_at) VALUES (DEFAULT, DEFAULT)
"INSERT INTO pgml.uploaded_files (id, created_at) VALUES (DEFAULT, DEFAULT)
RETURNING id, created_at"
)
.fetch_one(pool)
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy