Skip to content

Commit

Permalink
#443 Add Database docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Oct 24, 2023
1 parent 11e0653 commit 6e0d9ed
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 0 deletions.
Binary file added docs/assets/images/database_schemas/ancillary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions docs/pages/Database/Ancillary/Ancillary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
layout: page
title: Ancillary
permalink: /database/ancillary
parent: Database
nav_order: 4
---

# Ancillary

![](/MMGIS/assets/images/database_schemas/ancillary.png)

## Tables

### url_shorteners

The `url_shorteners` table stores mappings between short links (a short character sequence) and full links as well as the user who created the short link. Short links enable the sharing of a concise link (such as mmgis.jpl.nasa.gov/?s=mdxeg) instead of a full 1k+ character deep link.
41 changes: 41 additions & 0 deletions docs/pages/Database/Configuration/Configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
layout: page
title: Configuration
permalink: /database/configuration
parent: Database
has_children: false
nav_order: 1
---

# Configuration

![](/MMGIS/assets/images/database_schemas/configuration.png)

## Tables

### configs

The `configs` table stores versioned configuration json objects per mission.

#### Columns

- `mission`: The mission name this configuration object belongs to.
- `config`: The full JSON configuration object. This is the exact object the MMGIS client uses to set up a mission's page.
- `version`: The version of the configuration object for the mission. Saving a configuration object adds a row to the table with the next version
- `createdAt`: Standard Postgres creation time field.

### long_term_tokens

The `long_term_tokens` table stores a list of tokens to be used as authentication for the Configuration API. The are manually created by a Site Admin through the /configure page and can be set to expire.

### webhooks

The `webhooks` table contains a json list of all active webhook configurations. When their trigger action is performed, they will execute their request.

### datasets

The `datasets` table is a list of names and references to other tables that store the actual dataset. The `table` field is the name of it's associated table and often follows the form "d{int}\_dataset". The d{int}\_dataset tables are merely a tabular representation of a CSV file. Datasets in MMGIS are useful in MMGIS when each vector layer's feature has tons of metadata as this provides a way to only grab that metadata when a user clicks on the feature instead of loading all the metadata up front.

### geodatasets

Similar to the `datasets` table, the `geodatasets` table is a list of names and references to other tables that store the actual geodataset. The `table` field is the name of it's associated table and often follows the form "g{int}\_geodataset". The g{int}\_geodataset tables are merely a tabular representation of a GeoJSON file. The `geom` column encodes each feature's geometry via PostGIS and in order to optimize spatial operations on the data.
7 changes: 7 additions & 0 deletions docs/pages/Database/Database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
layout: page
title: Database
permalink: /database/
has_children: true
nav_order: 7
---
75 changes: 75 additions & 0 deletions docs/pages/Database/DrawTool/DrawTool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
layout: page
title: Draw Tool
permalink: /database/drawtool
parent: Database
nav_order: 3
---

# Draw Tool

![](/MMGIS/assets/images/database_schemas/drawtool.png)

## Tables

### user_files

The `user_files` table stores an entry for each file a user created via the Draw Tool and contains common file metadata such as owner, name, description, whether it was deleted or not, who can see it, etc. This table does not store the actual features that are within it. To reference those, the user_files' id passes through the `file_histories` table first.

#### Columns

- `file_owner`: Username who owns the file.
- `file_owner_group`: In special cases, a group of users can be the owner of a file. This is currently hardcoded only for Lead users.
- `file_name`: The name of the drawing file.
- `file_description`: The description of the file. File tags also get encoded into this description field.
- `is_master`: Is this file one of the default Lead files.
- `intent`: States the purpose of the file. While being deprecated, Lead Maps still uses this to differentiate between ROIs, Campaigns, etc. This field is important when uses the review/publish functionality.
- `public`: Is the file visible to all users or just its owner.
- `hidden`: If true, behaves like a (recoverable) delete.
- `created_on`: Standard Postgres creation time field.
- `updated_on`: Standard Postgres update time field.
- `template`: A JSON defining rules that each feature's metadata must comply to. Templates can be set on files at creation or through an existing file's information modal.
- `publicity_type`: If the file is public, how public? Read-only, list out other users who can draw and edit in it, all users can draw and edit in it.
- `public_editors`: If the file is public and the publicity type is "list-editors", this is the list of usernames who can draw and edit in this file.

### file_histories

The `file_histories` table provides a complete representation of all Draw Tool files at any point in time. To do this, every time a feature is drawn or edited, a new entry appears in the `file_histories` table that state what action what performed, by whom, when and a list of all the `user_features` ids that now belong in the file. For instance, if the latest `file_histories` entry for `file_id=7` has `history=[1,25,63,85,86,87,88]`, then the rows with ids 1, 25, 63, 85, 86, 87, and 88 are in the `user_file` file with an id of 7. The "History" tab in the Drawl Tool allows users to traverse these history trees.

#### Columns

- `file_id`: The id of the `user_files` file this history entry belongs to.
- `history_id`: An incrementing id that work per file_id.
- `time`: A Unix timestamp of when the drawing action occured.
- `action_index`: An id for what action was performed.
- 0: add
- 1: edit
- 2: delete
- 3: undo
- 4: (unused)
- 5: Clip (add over)
- 6: Merge
- 7: Clip (add under)
- 8: Split
- `history`: An array of `user_features` ids that are contained in this file at this time.
- `author`: The user who performed this action.

### user_features

The `user_features` table stores every Draw Tool feature and with PostGIS encoded geometries.

#### Columns

- `file_id`: The id of the `user_files` file this feature belongs to.
- `level`: Stores the order in which the feature is to be drawn when rendering the file.
- `intent`: A per-feature intent that takes precedence over the `user_files` file's intent.
- `properties`: The GeoJSON feature's properties object.
- `geom`: PostGIS encoded feature geometry.

### published_stores

In the Draw Tool, Lead users can copy features from various layers into a Lead layer and then publish that layer. Publishing requires various checks to take place such as no duplicate names, no duplicate uuids, certain features must be fully contained within others, what are a polygon's children, etc. The `published_stores` table stores the intermediary spatial, relational and heirarchical metadata in performing this validation. This metadata speeds up a spatial search API that is not yet released publically.

### publisheds

The `publisheds` table stores every feature from the last published file and does so with PostGIS encoded geometries.
25 changes: 25 additions & 0 deletions docs/pages/Database/Infrastructural/Infrastructural.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
layout: page
title: Infrastructural
permalink: /database/infrastructural
parent: Database
nav_order: 2
---

# Infrastructural

![](/MMGIS/assets/images/database_schemas/infrastructural.png)

## Tables

### session

The `session` table enables the MMGIS Server to keep track of and authenticated user sessions. Storing session tokens in a table instead of in memory allows the MMGIS Backend to scale up machines without losing track of users.

### spatial_ref_sys

The `spatial_ref_sys` is used by the PostGIS extension to maintain a catalog of common spatial reference systems such as EPSG and ESRI codes

### users

The `users` table is used when the ENV `AUTH=local` and for the Site Admin's account. It stores usernames, emails and encrypted passwords.

0 comments on commit 6e0d9ed

Please sign in to comment.