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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.venv
__pycache__
deps
macrostrat.toml
2 changes: 1 addition & 1 deletion .idea/macrostrat.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added cli/macrostrat/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SQL script that
/* sql script that
- alters the MariaDB tables by adding a new column for geom -> text data,
- sets the datatype of the new column data to WKT format,
- drops the old geometry column,
Expand Down
2 changes: 1 addition & 1 deletion cli/macrostrat/cli/database/mariadb/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _log_command(url: URL, cmd: list[str]):


async def _restore_mariadb(engine: Engine, *args, **kwargs):
"""Load MariaDB dump (GZipped SQL file) into a database, using centrally managed credentials,
"""Load MariaDB dump (GZipped sql file) into a database, using centrally managed credentials,
a Docker containerized `mariadb` client, and a streaming approach."""
overwrite = kwargs.pop("overwrite", False)
create = kwargs.pop("create", overwrite)
Expand Down
22 changes: 22 additions & 0 deletions cli/macrostrat/cli/database/migrations/user_features/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from psycopg2.sql import Identifier

from macrostrat.core.migrations import Migration, exists
from macrostrat.database import Database


class UserSavedLocationsMigration(Migration):
name = "user-saved-locations"
subsystem = "user_features"
description = """
Create user-saved-locations db schema, permissions, and views.
"""

# depends_on = ["baseline", "macrostrat-mariadb"]

preconditions = [exists("macrostrat_auth", "user")]

postconditions = [
exists(
"user_features", "user_locations, location_tags, location_tags_intersect"
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE OR REPLACE VIEW macrostrat_api.user_locations AS
SELECT *
FROM user_features.user_locations;


CREATE OR REPLACE VIEW macrostrat_api.location_tags AS
SELECT *
FROM user_features.location_tags;

--this will change from web_anon to an authorized user once that workflow has been implemented.
--web_anon is used for testing only right now.
GRANT SELECT, INSERT, UPDATE, DELETE ON macrostrat_api.user_locations TO web_anon;
GRANT SELECT, INSERT, UPDATE, DELETE ON macrostrat_api.location_tags TO web_anon;


NOTIFY pgrst, 'reload schema';

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
CREATE SCHEMA user_features;
CREATE EXTENSION IF NOT EXISTS postgis;
--changed map_layers from enum to array in order to save multiple layers at a time
create table user_features.user_locations
(
id serial primary key,
user_id integer not null constraint fk_user references macrostrat_auth."user" on delete cascade,
name varchar(120) not null,
description text,
point public.geometry(POINT, 4326),
zoom numeric,
meters_from_point numeric,
elevation numeric,
azimuth numeric,
pitch numeric,
map_layers text [],
created_at timestamp default now() not null,
updated_at timestamp default now() not null
);


create table user_features.location_tags
(
id serial PRIMARY KEY,
name varchar(120) not NULL,
description text,
color varchar(30)
);

--intersection table for ids joins with the location_tags table
--remove category and add NULL user_ids
create table user_features.location_tags_intersect (
tag_id integer constraint fk_tag_id references user_features."location_tags" on delete cascade,
user_id integer constraint fk_user_id references macrostrat_auth."user" on delete cascade,
location_id integer not null constraint fk_location_id references user_features."user_locations" on delete cascade,
PRIMARY KEY (tag_id, user_id, location_id)
);


alter table user_features.user_locations owner to "macrostrat-admin";
alter table user_features.location_tags owner to "macrostrat-admin";
alter table user_features.location_tags_intersect owner to "macrostrat-admin";

grant insert, select, update on user_locations to web_anon;
grant insert, select, update on location_tags to web_anon;

grant delete, insert, select, update on user_locations to web_user;
grant delete, insert, select, update on location_tags to web_user;








Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ ON c.id = cr.col_id
LEFT JOIN macrostrat.refs r
ON cr.ref_id = r.id;




CREATE OR REPLACE VIEW macrostrat_api.strat_names_meta AS
SELECT * FROM macrostrat.strat_names_meta;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** SQL run during a mostly manual conversion of the knowledge graph database (2024-09-11)
/** sql run during a mostly manual conversion of the knowledge graph database (2024-09-11)
* to use an overall simpler schema. Major changes include:
* - Using integer ids instead of UUIDs
* - Using an extensible, foreign-keyed table for entity and relationship types (instead of a custom enum)
Expand Down
6 changes: 3 additions & 3 deletions core/macrostrat/core/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ApplicationStatus(Enum):


class Migration:
"""Class defining a set of SQL changes to be applied to the database, as well as checks for
"""Class defining a set of sql changes to be applied to the database, as well as checks for
whether the migration can be applied to the current state of the database
"""

Expand All @@ -125,10 +125,10 @@ class Migration:
# List of checks on the database that should all evaluate to true after the migration has run successfully
postconditions: list[DbEvaluator] = []

# Should SQL be loaded from the directory of the migration class
# Should sql be loaded from the directory of the migration class
load_sql_files: bool | Path = True

# Fixtures to run after loaded SQL
# Fixtures to run after loaded sql
fixtures: list[Path | DBCallable] = []

# Flag for whether running this migration will cause data changes in the database in addition to
Expand Down
2 changes: 1 addition & 1 deletion map-integration/macrostrat/map_integration/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def database_connection():


def sql_file(key: str) -> str:
"""Return the contents of a SQL file."""
"""Return the contents of a sql file."""
return (Path(__file__).parent / "procedures" / (key + ".sql")).read_text()


Expand Down
2 changes: 1 addition & 1 deletion map-integration/macrostrat/map_integration/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

def normalize_slug(slug: str) -> str:
"""
Replace characters that are invalid in an SQL table name with an underscore.
Replace characters that are invalid in an sql table name with an underscore.
"""
return re.sub(r"\W", "_", slug).lower()

Expand Down
7 changes: 4 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion schema/dev-schema-2024-01-31.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ CREATE SCHEMA weaver_macrostrat;
CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public;

-- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner:
COMMENT ON EXTENSION pg_stat_statements IS 'track planning and execution statistics of all SQL statements executed';
COMMENT ON EXTENSION pg_stat_statements IS 'track planning and execution statistics of all sql statements executed';

-- Name: pgaudit; Type: EXTENSION; Schema: -; Owner: -
CREATE EXTENSION IF NOT EXISTS pgaudit WITH SCHEMA public;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ HOW LOGIN WORKS --> {
if login successful --> return json token
}

Generate JWT in SQL ---> pgjwt
Generate JWT in sql ---> pgjwt
https://github.com/michelp/pgjwt
https://app.bountysource.com/issues/89971002-example-code-to-show-how-to-install-pgjwt-extension-in-docker

Expand Down