Skip to content

Commit cf24572

Browse files
authored
Merge pull request #105 from UW-Macrostrat/saved_locations
Saved locations
2 parents 07cdd93 + 2fe4b8d commit cf24572

File tree

16 files changed

+112
-14
lines changed

16 files changed

+112
-14
lines changed

.idea/macrostrat.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/macrostrat/__init__.py

Whitespace-only changes.

cli/macrostrat/cli/database/mariadb/postgresql_migration/pgloader-pre-script.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* SQL script that
1+
/* sql script that
22
- alters the MariaDB tables by adding a new column for geom -> text data,
33
- sets the datatype of the new column data to WKT format,
44
- drops the old geometry column,

cli/macrostrat/cli/database/mariadb/restore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _log_command(url: URL, cmd: list[str]):
6161

6262

6363
async def _restore_mariadb(engine: Engine, *args, **kwargs):
64-
"""Load MariaDB dump (GZipped SQL file) into a database, using centrally managed credentials,
64+
"""Load MariaDB dump (GZipped sql file) into a database, using centrally managed credentials,
6565
a Docker containerized `mariadb` client, and a streaming approach."""
6666
overwrite = kwargs.pop("overwrite", False)
6767
create = kwargs.pop("create", overwrite)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from psycopg2.sql import Identifier
2+
3+
from macrostrat.core.migrations import Migration, exists
4+
from macrostrat.database import Database
5+
6+
7+
class UserSavedLocationsMigration(Migration):
8+
name = "user-saved-locations"
9+
subsystem = "user_features"
10+
description = """
11+
Create user-saved-locations db schema, permissions, and views.
12+
"""
13+
14+
# depends_on = ["baseline", "macrostrat-mariadb"]
15+
16+
preconditions = [exists("macrostrat_auth", "user")]
17+
18+
postconditions = [
19+
exists(
20+
"user_features", "user_locations, location_tags, location_tags_intersect"
21+
),
22+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CREATE OR REPLACE VIEW macrostrat_api.user_locations AS
2+
SELECT *
3+
FROM user_features.user_locations;
4+
5+
6+
CREATE OR REPLACE VIEW macrostrat_api.location_tags AS
7+
SELECT *
8+
FROM user_features.location_tags;
9+
10+
--this will change from web_anon to an authorized user once that workflow has been implemented.
11+
--web_anon is used for testing only right now.
12+
GRANT SELECT, INSERT, UPDATE, DELETE ON macrostrat_api.user_locations TO web_anon;
13+
GRANT SELECT, INSERT, UPDATE, DELETE ON macrostrat_api.location_tags TO web_anon;
14+
15+
16+
NOTIFY pgrst, 'reload schema';
17+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
CREATE SCHEMA user_features;
2+
CREATE EXTENSION IF NOT EXISTS postgis;
3+
--changed map_layers from enum to array in order to save multiple layers at a time
4+
create table user_features.user_locations
5+
(
6+
id serial primary key,
7+
user_id integer not null constraint fk_user references macrostrat_auth."user" on delete cascade,
8+
name varchar(120) not null,
9+
description text,
10+
point public.geometry(POINT, 4326),
11+
zoom numeric,
12+
meters_from_point numeric,
13+
elevation numeric,
14+
azimuth numeric,
15+
pitch numeric,
16+
map_layers text [],
17+
created_at timestamp default now() not null,
18+
updated_at timestamp default now() not null
19+
);
20+
21+
22+
create table user_features.location_tags
23+
(
24+
id serial PRIMARY KEY,
25+
name varchar(120) not NULL,
26+
description text,
27+
color varchar(30)
28+
);
29+
30+
--intersection table for ids joins with the location_tags table
31+
--remove category and add NULL user_ids
32+
create table user_features.location_tags_intersect (
33+
tag_id integer constraint fk_tag_id references user_features."location_tags" on delete cascade,
34+
user_id integer constraint fk_user_id references macrostrat_auth."user" on delete cascade,
35+
location_id integer not null constraint fk_location_id references user_features."user_locations" on delete cascade,
36+
PRIMARY KEY (tag_id, user_id, location_id)
37+
);
38+
39+
40+
alter table user_features.user_locations owner to "macrostrat-admin";
41+
alter table user_features.location_tags owner to "macrostrat-admin";
42+
alter table user_features.location_tags_intersect owner to "macrostrat-admin";
43+
44+
grant insert, select, update on user_locations to web_anon;
45+
grant insert, select, update on location_tags to web_anon;
46+
47+
grant delete, insert, select, update on user_locations to web_user;
48+
grant delete, insert, select, update on location_tags to web_user;
49+
50+
51+
52+
53+
54+
55+
56+

cli/macrostrat/cli/subsystems/macrostrat_api/schema/01-column-builder-views.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ ON c.id = cr.col_id
196196
LEFT JOIN macrostrat.refs r
197197
ON cr.ref_id = r.id;
198198

199+
200+
201+
199202
CREATE OR REPLACE VIEW macrostrat_api.strat_names_meta AS
200203
SELECT * FROM macrostrat.strat_names_meta;
201204

cli/macrostrat/cli/subsystems/xdd/ref/update-xdd-schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** SQL run during a mostly manual conversion of the knowledge graph database (2024-09-11)
1+
/** sql run during a mostly manual conversion of the knowledge graph database (2024-09-11)
22
* to use an overall simpler schema. Major changes include:
33
* - Using integer ids instead of UUIDs
44
* - Using an extensible, foreign-keyed table for entity and relationship types (instead of a custom enum)

0 commit comments

Comments
 (0)