Skip to content

Commit 805310c

Browse files
authored
Merge pull request #227 from UW-Macrostrat/match-api
Match API
2 parents 4700923 + 13a2c36 commit 805310c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3864
-3076
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.venv
22
__pycache__
3-
macrostrat.toml
3+
macrostrat.toml
4+
*.egg-info
5+
*.pyc

.idea/data_source_mapping.xml

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

.idea/macrostrat.iml

Lines changed: 8 additions & 3 deletions
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 & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Setting the `MACROSTRAT_PYROOT` environment variable allows a different root
4646
Python version to be installed. This can be used to add new plugins
4747
or application dependencies.
4848

49+
### Debugging the installation
50+
51+
- Run `macrostrat uv sync` to ensure that all dependencies are installed.
52+
4953
## Usage
5054

5155
Once a Macrostrat configuration file is defined, the Macrostrat command-line app

bin/macrostrat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ if [ "$1" = "uv" ]; then
7272
echo -e "MACROSTRAT_PYROOT is set to \033[36m$BASE_DIR\033[0m"
7373
echo ""
7474
fi
75-
$_uv --directory "$BASE_DIR" "$@"
75+
$_uv --project "$BASE_DIR" "$@"
7676
exit $?
7777
fi
7878

cli/macrostrat/cli/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
__version__ = "2.0.0"
2-
3-
from .entrypoint import main

cli/macrostrat/cli/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from . import main
1+
from .entrypoint import main
22

33
main()

py-modules/match-utils/macrostrat/match_utils/test_match_utils.py renamed to cli/macrostrat/cli/database/migrations/composite_projects/__init__.py

File renamed without changes.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
ALTER TABLE macrostrat.projects ADD COLUMN IF NOT EXISTS is_composite BOOLEAN DEFAULT FALSE;
3+
4+
5+
CREATE TABLE IF NOT EXISTS macrostrat.project_composite (
6+
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
7+
parent_project_id integer REFERENCES macrostrat.projects(id) ON DELETE CASCADE,
8+
child_project_id integer REFERENCES macrostrat.projects(id) ON DELETE CASCADE,
9+
UNIQUE (parent_project_id, child_project_id)
10+
);
11+
12+
-- Ensure that only composite projects can be parent of other projects
13+
CREATE OR REPLACE FUNCTION macrostrat.check_composite_parent()
14+
RETURNS TRIGGER AS $$
15+
BEGIN
16+
IF NOT (SELECT is_composite FROM macrostrat.projects WHERE id = NEW.parent_project_id) THEN
17+
RAISE EXCEPTION 'Parent project must be a composite project';
18+
END IF;
19+
RETURN NEW;
20+
END;
21+
$$ LANGUAGE plpgsql;
22+
23+
-- Create the trigger on the project_composite table
24+
CREATE TRIGGER trg_check_composite_parent
25+
BEFORE INSERT OR UPDATE ON macrostrat.project_composite
26+
FOR EACH ROW EXECUTE FUNCTION macrostrat.check_composite_parent();
27+
28+
/**
29+
Ensure that only non-composite projects can have columns as children.
30+
This is probably not strictly necessary, but it makes the composite project
31+
system a bit more straightforward at the start.
32+
*/
33+
CREATE OR REPLACE FUNCTION macrostrat.check_column_project_non_composite()
34+
RETURNS TRIGGER AS $$
35+
BEGIN
36+
IF (SELECT is_composite FROM macrostrat.projects WHERE id = NEW.project_id)
37+
THEN
38+
RAISE EXCEPTION 'A composite project cannot itself contain columns. We may relax this restriction in the future.';
39+
END IF;
40+
RETURN NEW;
41+
END;
42+
$$ LANGUAGE plpgsql;
43+
44+
-- Add the trigger on the macrostrat.cols table
45+
CREATE TRIGGER trg_check_column_project_non_composite
46+
BEFORE INSERT OR UPDATE ON macrostrat.cols
47+
FOR EACH ROW EXECUTE FUNCTION macrostrat.check_column_project_non_composite();
48+
49+
50+
/** Take the opportunity to add a slug for nicer URLs **/
51+
ALTER TABLE macrostrat.projects ADD COLUMN IF NOT EXISTS slug TEXT UNIQUE;
52+
53+
/** Function to generate slugs from project names **/
54+
CREATE OR REPLACE FUNCTION macrostrat.generate_project_slug()
55+
RETURNS VOID AS $$
56+
DECLARE
57+
proj RECORD;
58+
base_slug TEXT;
59+
unique_slug TEXT;
60+
suffix INT;
61+
BEGIN
62+
FOR proj IN SELECT id, name FROM macrostrat.projects WHERE slug IS NULL LOOP
63+
base_slug := lower(regexp_replace(proj.name, '[^a-zA-Z0-9]+', '-', 'g'));
64+
unique_slug := base_slug;
65+
suffix := 1;
66+
WHILE EXISTS (SELECT 1 FROM macrostrat.projects WHERE slug = unique_slug) LOOP
67+
suffix := suffix + 1;
68+
unique_slug := base_slug || '-' || suffix;
69+
END LOOP;
70+
UPDATE macrostrat.projects SET slug = unique_slug WHERE id = proj.id;
71+
END LOOP;
72+
END;
73+
$$ LANGUAGE plpgsql;

0 commit comments

Comments
 (0)