pgcraft 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. pgcraft-0.1.2/LICENSE +21 -0
  2. pgcraft-0.1.2/PKG-INFO +160 -0
  3. pgcraft-0.1.2/README.md +126 -0
  4. pgcraft-0.1.2/pyproject.toml +109 -0
  5. pgcraft-0.1.2/src/pgcraft/__init__.py +0 -0
  6. pgcraft-0.1.2/src/pgcraft/alembic/__init__.py +0 -0
  7. pgcraft-0.1.2/src/pgcraft/alembic/dependency.py +778 -0
  8. pgcraft-0.1.2/src/pgcraft/alembic/register.py +45 -0
  9. pgcraft-0.1.2/src/pgcraft/alembic/renderer.py +234 -0
  10. pgcraft-0.1.2/src/pgcraft/alembic/rewriter.py +54 -0
  11. pgcraft-0.1.2/src/pgcraft/alembic/role.py +0 -0
  12. pgcraft-0.1.2/src/pgcraft/alembic/schema.py +56 -0
  13. pgcraft-0.1.2/src/pgcraft/check.py +79 -0
  14. pgcraft-0.1.2/src/pgcraft/cli.py +20 -0
  15. pgcraft-0.1.2/src/pgcraft/columns.py +60 -0
  16. pgcraft-0.1.2/src/pgcraft/config.py +45 -0
  17. pgcraft-0.1.2/src/pgcraft/declarative.py +247 -0
  18. pgcraft-0.1.2/src/pgcraft/errors.py +5 -0
  19. pgcraft-0.1.2/src/pgcraft/factory/__init__.py +17 -0
  20. pgcraft-0.1.2/src/pgcraft/factory/base.py +200 -0
  21. pgcraft-0.1.2/src/pgcraft/factory/context.py +156 -0
  22. pgcraft-0.1.2/src/pgcraft/factory/dimension/__init__.py +17 -0
  23. pgcraft-0.1.2/src/pgcraft/factory/dimension/append_only.py +41 -0
  24. pgcraft-0.1.2/src/pgcraft/factory/dimension/eav.py +35 -0
  25. pgcraft-0.1.2/src/pgcraft/factory/dimension/simple.py +32 -0
  26. pgcraft-0.1.2/src/pgcraft/models/__init__.py +0 -0
  27. pgcraft-0.1.2/src/pgcraft/models/roles.py +51 -0
  28. pgcraft-0.1.2/src/pgcraft/patches/__init__.py +6 -0
  29. pgcraft-0.1.2/src/pgcraft/patches/view_render.py +77 -0
  30. pgcraft-0.1.2/src/pgcraft/plugin.py +273 -0
  31. pgcraft-0.1.2/src/pgcraft/plugins/__init__.py +0 -0
  32. pgcraft-0.1.2/src/pgcraft/plugins/api.py +71 -0
  33. pgcraft-0.1.2/src/pgcraft/plugins/append_only.py +292 -0
  34. pgcraft-0.1.2/src/pgcraft/plugins/check.py +217 -0
  35. pgcraft-0.1.2/src/pgcraft/plugins/created_at.py +34 -0
  36. pgcraft-0.1.2/src/pgcraft/plugins/eav.py +430 -0
  37. pgcraft-0.1.2/src/pgcraft/plugins/pk.py +34 -0
  38. pgcraft-0.1.2/src/pgcraft/plugins/simple.py +126 -0
  39. pgcraft-0.1.2/src/pgcraft/plugins/templates/append_only/delete.mako +4 -0
  40. pgcraft-0.1.2/src/pgcraft/plugins/templates/append_only/insert.mako +10 -0
  41. pgcraft-0.1.2/src/pgcraft/plugins/templates/append_only/update.mako +12 -0
  42. pgcraft-0.1.2/src/pgcraft/plugins/templates/check/validate.mako +8 -0
  43. pgcraft-0.1.2/src/pgcraft/plugins/templates/eav/delete.mako +4 -0
  44. pgcraft-0.1.2/src/pgcraft/plugins/templates/eav/insert.mako +16 -0
  45. pgcraft-0.1.2/src/pgcraft/plugins/templates/eav/update.mako +21 -0
  46. pgcraft-0.1.2/src/pgcraft/plugins/templates/simple/delete.mako +4 -0
  47. pgcraft-0.1.2/src/pgcraft/plugins/templates/simple/insert.mako +6 -0
  48. pgcraft-0.1.2/src/pgcraft/plugins/templates/simple/update.mako +7 -0
  49. pgcraft-0.1.2/src/pgcraft/resource.py +32 -0
  50. pgcraft-0.1.2/src/pgcraft/utils/__init__.py +0 -0
  51. pgcraft-0.1.2/src/pgcraft/utils/naming.py +29 -0
  52. pgcraft-0.1.2/src/pgcraft/utils/naming_convention.py +56 -0
  53. pgcraft-0.1.2/src/pgcraft/utils/query.py +12 -0
  54. pgcraft-0.1.2/src/pgcraft/utils/template.py +18 -0
  55. pgcraft-0.1.2/src/pgcraft/utils/trigger.py +78 -0
  56. pgcraft-0.1.2/src/pgcraft/validator.py +61 -0
pgcraft-0.1.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rodda John
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pgcraft-0.1.2/PKG-INFO ADDED
@@ -0,0 +1,160 @@
1
+ Metadata-Version: 2.3
2
+ Name: pgcraft
3
+ Version: 0.1.2
4
+ Summary: Configuration-driven PostgreSQL dimension tables, migrations, and APIs.
5
+ Author: Rodda John
6
+ Author-email: Rodda John <roddarjohn@protonmail.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2026 Rodda John
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ Requires-Dist: pglast>=7.11
29
+ Requires-Dist: pydantic>=2.12.5
30
+ Requires-Dist: sqlalchemy-declarative-extensions>=0.16.8
31
+ Requires-Dist: typer>=0.24.1
32
+ Requires-Python: >=3.12
33
+ Description-Content-Type: text/markdown
34
+
35
+ # pgcraft
36
+
37
+ [Documentation](https://roddarjohn.github.io/pgcraft/)
38
+
39
+ **Configuration-driven PostgreSQL dimension tables, migrations, and APIs.**
40
+
41
+ pgcraft generates SQLAlchemy models, Alembic migrations, and
42
+ [PostgREST](https://postgrest.org) API views from declarative dimension
43
+ configurations. Define your schema once; pgcraft handles the rest.
44
+
45
+ ---
46
+
47
+ ## Features
48
+
49
+ - **Dimension types** — Simple, Append-Only (SCD Type 2), and
50
+ Entity-Attribute-Value, each with generated backing tables, views, and
51
+ triggers.
52
+ - **Plugin architecture** — Composable plugins with `@requires` / `@produces`
53
+ decorators, executed in topological order.
54
+ - **Automatic migrations** — Alembic integration with SQL-formatted migration
55
+ scripts via sqlglot.
56
+ - **PostgREST API layer** — API views, roles, and grants declared alongside
57
+ your models.
58
+ - **Postgres is king** — Logic lives in the database (views, triggers, check
59
+ constraints). Python orchestrates; Postgres enforces.
60
+
61
+ ## Quick start
62
+
63
+ ### Install
64
+
65
+ ```bash
66
+ pip install pgcraft # or: uv add pgcraft
67
+ ```
68
+
69
+ ### Define a dimension
70
+
71
+ ```python
72
+ from sqlalchemy import Column, MetaData, String
73
+ from pgcraft.factory.dimension import SimpleDimensionResourceFactory
74
+
75
+ metadata = MetaData()
76
+
77
+ SimpleDimensionResourceFactory(
78
+ tablename="users",
79
+ schemaname="public",
80
+ metadata=metadata,
81
+ schema_items=[
82
+ Column("name", String, nullable=False),
83
+ Column("email", String),
84
+ ],
85
+ )
86
+ ```
87
+
88
+ This creates:
89
+
90
+ - A `public.users` table with `id`, `name`, and `email` columns.
91
+ - An `api.users` view exposing the same columns for PostgREST.
92
+ - Alembic migration support out of the box.
93
+
94
+ ### Generate migrations
95
+
96
+ ```bash
97
+ pgcraft migrate revision --autogenerate -m "add users"
98
+ pgcraft migrate upgrade head
99
+ ```
100
+
101
+ ## Dimension types
102
+
103
+ pgcraft ships with three built-in dimension types:
104
+
105
+ | Type | Use case | History? |
106
+ |------|----------|----------|
107
+ | **Simple** | Static reference data | No |
108
+ | **Append-Only** (SCD Type 2) | Track changes over time | Yes |
109
+ | **EAV** | Flexible / sparse attributes with full audit trail | Yes |
110
+
111
+ See the [dimensions documentation](https://roddarjohn.github.io/pgcraft/dimensions.html) for ERD diagrams, schema details, and worked examples.
112
+
113
+ ## Documentation
114
+
115
+ Full documentation is available at
116
+ [roddarjohn.github.io/pgcraft](https://roddarjohn.github.io/pgcraft/).
117
+
118
+ - [Setup & installation](https://roddarjohn.github.io/pgcraft/setup.html)
119
+ - [Built-in dimensions](https://roddarjohn.github.io/pgcraft/dimensions.html)
120
+ - [Plugin system](https://roddarjohn.github.io/pgcraft/plugins.html)
121
+ - [API reference](https://roddarjohn.github.io/pgcraft/api.html)
122
+ - [Development guide](https://roddarjohn.github.io/pgcraft/development.html)
123
+ - [Playground](https://roddarjohn.github.io/pgcraft/playground.html)
124
+
125
+ ## Development
126
+
127
+ ```bash
128
+ # Clone and install
129
+ git clone https://github.com/<username>/pgcraft.git
130
+ cd pgcraft
131
+ uv sync --all-groups
132
+
133
+ # Run checks
134
+ just lint # ruff check + format
135
+ just type-check # ty check src/
136
+ just dev-test # pytest (fast, needs DATABASE_URL)
137
+ just test # tox (full isolation)
138
+ just docs # build Sphinx HTML docs
139
+ ```
140
+
141
+ Tests require a running PostgreSQL instance:
142
+
143
+ ```bash
144
+ DATABASE_URL=postgresql+psycopg:///pgcraft just dev-test
145
+ ```
146
+
147
+ ## Design philosophy
148
+
149
+ See [PLAN.md](PLAN.md) for the full design philosophy. The short version:
150
+
151
+ - **Postgres is king.** Push logic into the database when it is obviously
152
+ correct and declarative.
153
+ - **Explicit over implicit.** No magic — if behavior is not obvious from
154
+ reading the code, it needs a docstring explaining *why*.
155
+ - **Simple over clever.** Three similar lines are better than a premature
156
+ abstraction.
157
+
158
+ ## License
159
+
160
+ See [LICENSE](LICENSE) for details.
@@ -0,0 +1,126 @@
1
+ # pgcraft
2
+
3
+ [Documentation](https://roddarjohn.github.io/pgcraft/)
4
+
5
+ **Configuration-driven PostgreSQL dimension tables, migrations, and APIs.**
6
+
7
+ pgcraft generates SQLAlchemy models, Alembic migrations, and
8
+ [PostgREST](https://postgrest.org) API views from declarative dimension
9
+ configurations. Define your schema once; pgcraft handles the rest.
10
+
11
+ ---
12
+
13
+ ## Features
14
+
15
+ - **Dimension types** — Simple, Append-Only (SCD Type 2), and
16
+ Entity-Attribute-Value, each with generated backing tables, views, and
17
+ triggers.
18
+ - **Plugin architecture** — Composable plugins with `@requires` / `@produces`
19
+ decorators, executed in topological order.
20
+ - **Automatic migrations** — Alembic integration with SQL-formatted migration
21
+ scripts via sqlglot.
22
+ - **PostgREST API layer** — API views, roles, and grants declared alongside
23
+ your models.
24
+ - **Postgres is king** — Logic lives in the database (views, triggers, check
25
+ constraints). Python orchestrates; Postgres enforces.
26
+
27
+ ## Quick start
28
+
29
+ ### Install
30
+
31
+ ```bash
32
+ pip install pgcraft # or: uv add pgcraft
33
+ ```
34
+
35
+ ### Define a dimension
36
+
37
+ ```python
38
+ from sqlalchemy import Column, MetaData, String
39
+ from pgcraft.factory.dimension import SimpleDimensionResourceFactory
40
+
41
+ metadata = MetaData()
42
+
43
+ SimpleDimensionResourceFactory(
44
+ tablename="users",
45
+ schemaname="public",
46
+ metadata=metadata,
47
+ schema_items=[
48
+ Column("name", String, nullable=False),
49
+ Column("email", String),
50
+ ],
51
+ )
52
+ ```
53
+
54
+ This creates:
55
+
56
+ - A `public.users` table with `id`, `name`, and `email` columns.
57
+ - An `api.users` view exposing the same columns for PostgREST.
58
+ - Alembic migration support out of the box.
59
+
60
+ ### Generate migrations
61
+
62
+ ```bash
63
+ pgcraft migrate revision --autogenerate -m "add users"
64
+ pgcraft migrate upgrade head
65
+ ```
66
+
67
+ ## Dimension types
68
+
69
+ pgcraft ships with three built-in dimension types:
70
+
71
+ | Type | Use case | History? |
72
+ |------|----------|----------|
73
+ | **Simple** | Static reference data | No |
74
+ | **Append-Only** (SCD Type 2) | Track changes over time | Yes |
75
+ | **EAV** | Flexible / sparse attributes with full audit trail | Yes |
76
+
77
+ See the [dimensions documentation](https://roddarjohn.github.io/pgcraft/dimensions.html) for ERD diagrams, schema details, and worked examples.
78
+
79
+ ## Documentation
80
+
81
+ Full documentation is available at
82
+ [roddarjohn.github.io/pgcraft](https://roddarjohn.github.io/pgcraft/).
83
+
84
+ - [Setup & installation](https://roddarjohn.github.io/pgcraft/setup.html)
85
+ - [Built-in dimensions](https://roddarjohn.github.io/pgcraft/dimensions.html)
86
+ - [Plugin system](https://roddarjohn.github.io/pgcraft/plugins.html)
87
+ - [API reference](https://roddarjohn.github.io/pgcraft/api.html)
88
+ - [Development guide](https://roddarjohn.github.io/pgcraft/development.html)
89
+ - [Playground](https://roddarjohn.github.io/pgcraft/playground.html)
90
+
91
+ ## Development
92
+
93
+ ```bash
94
+ # Clone and install
95
+ git clone https://github.com/<username>/pgcraft.git
96
+ cd pgcraft
97
+ uv sync --all-groups
98
+
99
+ # Run checks
100
+ just lint # ruff check + format
101
+ just type-check # ty check src/
102
+ just dev-test # pytest (fast, needs DATABASE_URL)
103
+ just test # tox (full isolation)
104
+ just docs # build Sphinx HTML docs
105
+ ```
106
+
107
+ Tests require a running PostgreSQL instance:
108
+
109
+ ```bash
110
+ DATABASE_URL=postgresql+psycopg:///pgcraft just dev-test
111
+ ```
112
+
113
+ ## Design philosophy
114
+
115
+ See [PLAN.md](PLAN.md) for the full design philosophy. The short version:
116
+
117
+ - **Postgres is king.** Push logic into the database when it is obviously
118
+ correct and declarative.
119
+ - **Explicit over implicit.** No magic — if behavior is not obvious from
120
+ reading the code, it needs a docstring explaining *why*.
121
+ - **Simple over clever.** Three similar lines are better than a premature
122
+ abstraction.
123
+
124
+ ## License
125
+
126
+ See [LICENSE](LICENSE) for details.
@@ -0,0 +1,109 @@
1
+ [project]
2
+ name = "pgcraft"
3
+ version = "0.1.2"
4
+ description = "Configuration-driven PostgreSQL dimension tables, migrations, and APIs."
5
+ readme = "README.md"
6
+ license = { file = "LICENSE" }
7
+ authors = [{ name = "Rodda John", email = "roddarjohn@protonmail.com" }]
8
+ requires-python = ">=3.12"
9
+ dependencies = [
10
+ "pglast>=7.11",
11
+ "pydantic>=2.12.5",
12
+ "sqlalchemy-declarative-extensions>=0.16.8",
13
+ "typer>=0.24.1",
14
+ ]
15
+
16
+ [project.scripts]
17
+ pgcraft = "pgcraft.cli:app"
18
+
19
+ [build-system]
20
+ requires = ["uv_build>=0.10.8,<0.11.0"]
21
+ build-backend = "uv_build"
22
+
23
+
24
+ [dependency-groups]
25
+ dev = [
26
+ "alembic>=1.18.4",
27
+ "psycopg[binary]>=3.3.3",
28
+ "pytest>=8",
29
+ "pytest-alembic>=0.12.1",
30
+ "python-dotenv>=1.2.2",
31
+ "slipcover>=1.0.17",
32
+ "sqlalchemy>=2.0.48",
33
+ "tox>=4.49.1",
34
+ "tox-uv>=1.33.2",
35
+ ]
36
+ docs = [
37
+ "furo>=2025.12.19",
38
+ "sphinx>=7.0",
39
+ "sphinx-autobuild>=2025.8.25",
40
+ "sphinx-autodoc-typehints>=3.0.1",
41
+ "sphinx-copybutton>=0.5.2",
42
+ ]
43
+ lint = ["ruff>=0.15.5", "ty>=0.0.20"]
44
+
45
+ [tool.ruff]
46
+ line-length = 80
47
+ exclude = ["docs", "playground", "tests/db/migrations"]
48
+
49
+
50
+ [tool.ruff.lint]
51
+ select = ["ALL"]
52
+ ignore = [
53
+ # Conflicts with formatter
54
+ "COM812",
55
+ "ISC001",
56
+ # Docstring convention (use D211 + D212)
57
+ "D203",
58
+ "D213",
59
+ # Only enforce docstrings on public classes, functions, and methods
60
+ "D100", # missing docstring in public module
61
+ "D104", # missing docstring in public package
62
+ # Not applicable to this project
63
+ "AIR",
64
+ "DJ",
65
+ "FAST",
66
+ "NPY",
67
+ "PD",
68
+ "INT",
69
+ "CPY",
70
+ ]
71
+
72
+ [tool.ruff.lint.per-file-ignores]
73
+ "scripts/**" = [
74
+ "INP001", # scripts/ doesn't need __init__.py
75
+ "T201", # print is fine in scripts
76
+ ]
77
+ "tests/**" = [
78
+ "S101", # assert is fine in tests
79
+ "S608", # f-string SQL in tests uses controlled schema names, not user input
80
+ "S702", # Mako templates in tests are not serving HTML
81
+ "ANN", # no annotations required in tests
82
+ "D", # no docstrings required in tests
83
+ "PLR2004", # magic numbers are fine in test assertions
84
+ "PLC0415", # local imports acceptable in test methods
85
+ "RUF003", # unicode × in comments is fine
86
+ "RUF059", # unpacked dummy variables are fine in tests
87
+ ]
88
+ "**/migrations/versions/*.py" = [
89
+ "INP001", # migration versions aren't a package
90
+ "D400", # migration docstrings don't need to end with a period
91
+ "D415", # migration docstrings don't need closing punctuation
92
+ "W291", # trailing whitespace on "Revises:" line when there's no parent
93
+ ]
94
+
95
+ [tool.ty.environment]
96
+ extra-paths = ["tests/db"]
97
+
98
+ [tool.ty.analysis]
99
+ # pglast has no type stubs.
100
+ allowed-unresolved-imports = ["pglast.**"]
101
+
102
+ [tool.tox]
103
+ requires = ["tox-uv>=1"]
104
+ env_list = ["3.12", "3.13", "3.14"]
105
+
106
+ [tool.tox.env_run_base]
107
+ dependency_groups = ["dev"]
108
+ pass_env = ["DATABASE_URL"]
109
+ commands = [["pytest", "{posargs:}"]]
File without changes
File without changes