@ai-devtools/dbspec-macos-arm64 1.6.1 → 1.6.2
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.
- package/bin/dbspec/_internal/base_library.zip +0 -0
- package/bin/dbspec/_internal/dbspec.egg-info/PKG-INFO +1 -1
- package/bin/dbspec/_internal/dbspec.egg-info/SOURCES.txt +2 -0
- package/bin/dbspec/_internal/pyproject.toml +1 -1
- package/bin/dbspec/_internal/src/resources/sqlalchemy_templates/README.md +23 -0
- package/bin/dbspec/_internal/src/resources/sqlalchemy_templates/domain_init.py.j2 +3 -3
- package/bin/dbspec/_internal/src/resources/sqlalchemy_templates/model.py.j2 +50 -50
- package/bin/dbspec/_internal/src/resources/sqlalchemy_templates/package_init.py.j2 +4 -4
- package/bin/dbspec/dbspec +0 -0
- package/package.json +1 -1
|
Binary file
|
|
@@ -40,6 +40,7 @@ src/db_import/types.py
|
|
|
40
40
|
src/db_import/validation.py
|
|
41
41
|
src/generators/__init__.py
|
|
42
42
|
src/generators/sqlalchemy/__init__.py
|
|
43
|
+
src/generators/sqlalchemy/attribute_names.py
|
|
43
44
|
src/generators/sqlalchemy/constraints.py
|
|
44
45
|
src/generators/sqlalchemy/context.py
|
|
45
46
|
src/generators/sqlalchemy/domains.py
|
|
@@ -54,6 +55,7 @@ src/generators/sqlalchemy/sequences.py
|
|
|
54
55
|
src/generators/sqlalchemy/tables.py
|
|
55
56
|
src/generators/sqlalchemy/templates.py
|
|
56
57
|
src/generators/sqlalchemy/types.py
|
|
58
|
+
src/generators/sqlalchemy/validation.py
|
|
57
59
|
src/logic/__init__.py
|
|
58
60
|
src/logic/check_rules.py
|
|
59
61
|
src/logic/db_validation.py
|
|
@@ -70,3 +70,26 @@ Jinja-параметров, зависящий только от стандар
|
|
|
70
70
|
изолированным subprocess без site-packages.
|
|
71
71
|
|
|
72
72
|
В 1.6.0 IndexContext содержит directions (ASC/DESC/пустая строка) в порядке columns и has_directions. Для направленных unique indexes используйте Index(unique=True), а не UniqueConstraint. Направления передаются методами SQLAlchemy .asc()/.desc(). Проектные шаблоны обновляются отдельно.
|
|
73
|
+
|
|
74
|
+
## Безопасные Python-атрибуты (1.6.2)
|
|
75
|
+
|
|
76
|
+
`col.name` хранит исходное SQL-имя, `col.attr_name` — уникальный Python-атрибут.
|
|
77
|
+
При различии передавайте `col.name` первым аргументом `mapped_column`, как в штатном
|
|
78
|
+
шаблоне. Ключевые слова и служебные имена получают безопасные атрибуты; допустимые
|
|
79
|
+
`match`, `case`, `type` сохраняются. Коллизии распределяются детерминированно в общей
|
|
80
|
+
области колонок и связей, без изменения имён SQL-колонок или ограничений.
|
|
81
|
+
|
|
82
|
+
`rel.fk_columns` сохраняет прежний контракт: локальные имена FK-атрибутов для
|
|
83
|
+
дочерней связи и пустой список для обратной. Новое необязательное поле
|
|
84
|
+
`rel.fk_expression` содержит строку списка class-qualified ссылок
|
|
85
|
+
(`[Child.sender_id]`). Штатный шаблон передаёт её через `py_repr` в
|
|
86
|
+
`relationship.foreign_keys`, разрешая обе стороны после импорта моделей.
|
|
87
|
+
Прежние проектные шаблоны простых связей продолжают работать без обновления.
|
|
88
|
+
|
|
89
|
+
До замены результата генератор проверяет синтаксис всех Python-файлов, импорт,
|
|
90
|
+
настройку ORM, полноту колонок metadata и разрешение FK в отдельном процессе.
|
|
91
|
+
Это изоляция состояния Python, а не security sandbox пользовательского кода.
|
|
92
|
+
Внешний `base_import` должен импортироваться в окружении генерации; его существующие
|
|
93
|
+
таблицы допустимы, но состав каждой генерируемой таблицы должен совпасть с SSOT.
|
|
94
|
+
При ошибке прежний выходной каталог сохраняется. Установка приложения или соединение
|
|
95
|
+
с БД для штатных шаблонов не требуются.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
{{ ("Domain package: " ~ domain.name) | py_repr }}
|
|
2
2
|
|
|
3
3
|
{% if model_mode == "core" %}
|
|
4
4
|
{% for table in domain.tables %}
|
|
@@ -7,7 +7,7 @@ from .{{ table.module_name }} import {{ table.module_name }}
|
|
|
7
7
|
|
|
8
8
|
__all__ = [
|
|
9
9
|
{% for table in domain.tables %}
|
|
10
|
-
|
|
10
|
+
{{ table.module_name | py_string }},
|
|
11
11
|
{% endfor %}
|
|
12
12
|
]
|
|
13
13
|
{% else %}
|
|
@@ -23,7 +23,7 @@ from .{{ table.module_name }} import {{ table.export_name }}
|
|
|
23
23
|
|
|
24
24
|
__all__ = [
|
|
25
25
|
{% for table in domain.tables %}
|
|
26
|
-
|
|
26
|
+
{{ table.export_name | py_string }},
|
|
27
27
|
{% endfor %}
|
|
28
28
|
]
|
|
29
29
|
{% endif %}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
{{ (table.description if include_comments and table.description else table.class_name ~ " model.") | py_repr }}
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -32,11 +32,11 @@ from ..{{ common_dir_name }}.base import metadata
|
|
|
32
32
|
{% for enum in table.enums %}
|
|
33
33
|
{{ enum.var_name }} = ENUM(
|
|
34
34
|
{% for v in enum.values %}
|
|
35
|
-
|
|
35
|
+
{{ v | py_string }}{% if not loop.last %}, {% endif +%}
|
|
36
36
|
{% endfor %}
|
|
37
37
|
,
|
|
38
|
-
name=
|
|
39
|
-
schema=
|
|
38
|
+
name={{ enum.name | py_string }},
|
|
39
|
+
schema={{ enum.schema | py_string }},
|
|
40
40
|
create_type={{ "True" if enum.create_type else "False" }},
|
|
41
41
|
)
|
|
42
42
|
{% endfor %}
|
|
@@ -45,24 +45,24 @@ from ..{{ common_dir_name }}.base import metadata
|
|
|
45
45
|
{% if table.sequences %}
|
|
46
46
|
{% for seq in table.sequences %}
|
|
47
47
|
{{ seq.var_name }} = Sequence(
|
|
48
|
-
|
|
48
|
+
{{ seq.name | py_string }},
|
|
49
49
|
{% if seq.schema %}
|
|
50
|
-
schema=
|
|
50
|
+
schema={{ seq.schema | py_string }},
|
|
51
51
|
{% endif %}
|
|
52
52
|
)
|
|
53
53
|
{% endfor %}
|
|
54
54
|
{% endif %}
|
|
55
55
|
|
|
56
56
|
{{ table.module_name }} = Table(
|
|
57
|
-
|
|
57
|
+
{{ table.table | py_string }},
|
|
58
58
|
metadata,
|
|
59
59
|
{% for col in table.columns %}
|
|
60
60
|
Column(
|
|
61
|
-
|
|
61
|
+
{{ col.name | py_string }},
|
|
62
62
|
{{ col.sa_type }},
|
|
63
63
|
{% set col_args = [] -%}
|
|
64
64
|
{% if col.fk_target -%}
|
|
65
|
-
{% set _ = col_args.append('ForeignKey(
|
|
65
|
+
{% set _ = col_args.append('ForeignKey(' ~ (col.fk_target | py_string) ~ ')') -%}
|
|
66
66
|
{% endif -%}
|
|
67
67
|
{% if col.sequence -%}
|
|
68
68
|
{% set _ = col_args.append(col.sequence.var_name) -%}
|
|
@@ -81,7 +81,7 @@ from ..{{ common_dir_name }}.base import metadata
|
|
|
81
81
|
{% if col.sequence -%}
|
|
82
82
|
{% set _ = col_args.append('server_default=' ~ col.sequence.var_name ~ '.next_value()') -%}
|
|
83
83
|
{% elif col.server_default -%}
|
|
84
|
-
{% set _ = col_args.append('server_default=text(
|
|
84
|
+
{% set _ = col_args.append('server_default=text(' ~ (col.server_default | py_string) ~ ')') -%}
|
|
85
85
|
{% endif -%}
|
|
86
86
|
{% if include_comments and col.description -%}
|
|
87
87
|
{% set _ = col_args.append('comment=' ~ (col.description | py_repr)) -%}
|
|
@@ -94,9 +94,9 @@ from ..{{ common_dir_name }}.base import metadata
|
|
|
94
94
|
{% if table.pk_constraint and table.pk_constraint.columns %}
|
|
95
95
|
PrimaryKeyConstraint(
|
|
96
96
|
{% for pk_col in table.pk_constraint.columns %}
|
|
97
|
-
|
|
97
|
+
{{ pk_col | py_string }},
|
|
98
98
|
{% endfor %}
|
|
99
|
-
name=
|
|
99
|
+
name={{ table.pk_constraint.name | py_string }},
|
|
100
100
|
),
|
|
101
101
|
{% endif %}
|
|
102
102
|
{% for check in table.check_constraints %}
|
|
@@ -105,9 +105,9 @@ from ..{{ common_dir_name }}.base import metadata
|
|
|
105
105
|
{% for constraint in table.unique_constraints %}
|
|
106
106
|
UniqueConstraint(
|
|
107
107
|
{% for c in constraint.columns %}
|
|
108
|
-
|
|
108
|
+
{{ c | py_string }},
|
|
109
109
|
{% endfor %}
|
|
110
|
-
name=
|
|
110
|
+
name={{ constraint.name | py_string }},
|
|
111
111
|
{% if constraint.nulls_not_distinct %}
|
|
112
112
|
postgresql_nulls_not_distinct=True,
|
|
113
113
|
{% endif %}
|
|
@@ -117,13 +117,13 @@ from ..{{ common_dir_name }}.base import metadata
|
|
|
117
117
|
{% if idx.unique and not idx.where and not idx.has_directions %}
|
|
118
118
|
UniqueConstraint(
|
|
119
119
|
{% for c in idx.columns %}
|
|
120
|
-
|
|
120
|
+
{{ c | py_string }},
|
|
121
121
|
{% endfor %}
|
|
122
|
-
name=
|
|
122
|
+
name={{ idx.name | py_string }},
|
|
123
123
|
),
|
|
124
124
|
{% endif %}
|
|
125
125
|
{% endfor %}
|
|
126
|
-
schema=
|
|
126
|
+
schema={{ table.schema | py_string }},
|
|
127
127
|
{% if include_comments and table.description %}
|
|
128
128
|
comment={{ table.description | py_repr }},
|
|
129
129
|
{% endif %}
|
|
@@ -131,7 +131,7 @@ from ..{{ common_dir_name }}.base import metadata
|
|
|
131
131
|
{% for idx in table.indexes %}
|
|
132
132
|
{% if idx.where or not idx.unique or idx.has_directions %}
|
|
133
133
|
Index(
|
|
134
|
-
|
|
134
|
+
{{ idx.name | py_string }},
|
|
135
135
|
{% for c in idx.columns %}
|
|
136
136
|
{{ table.module_name }}.c[{{ c | py_repr }}]{% if idx.directions[loop.index0] %}.{{ idx.directions[loop.index0] | lower }}(){% endif %},
|
|
137
137
|
{% endfor %}
|
|
@@ -139,7 +139,7 @@ Index(
|
|
|
139
139
|
unique=True,
|
|
140
140
|
{% endif %}
|
|
141
141
|
{% if idx.where %}
|
|
142
|
-
postgresql_where=text(
|
|
142
|
+
postgresql_where=text({{ idx.where | py_string }}),
|
|
143
143
|
{% endif %}
|
|
144
144
|
)
|
|
145
145
|
{% endif %}
|
|
@@ -186,11 +186,11 @@ if TYPE_CHECKING:
|
|
|
186
186
|
{% for enum in table.enums %}
|
|
187
187
|
{{ enum.var_name }} = ENUM(
|
|
188
188
|
{% for v in enum.values %}
|
|
189
|
-
|
|
189
|
+
{{ v | py_string }}{% if not loop.last %}, {% endif +%}
|
|
190
190
|
{% endfor %}
|
|
191
191
|
,
|
|
192
|
-
name=
|
|
193
|
-
schema=
|
|
192
|
+
name={{ enum.name | py_string }},
|
|
193
|
+
schema={{ enum.schema | py_string }},
|
|
194
194
|
create_type={{ "True" if enum.create_type else "False" }},
|
|
195
195
|
)
|
|
196
196
|
{% endfor %}
|
|
@@ -199,9 +199,9 @@ if TYPE_CHECKING:
|
|
|
199
199
|
{% if table.sequences %}
|
|
200
200
|
{% for seq in table.sequences %}
|
|
201
201
|
{{ seq.var_name }} = Sequence(
|
|
202
|
-
|
|
202
|
+
{{ seq.name | py_string }},
|
|
203
203
|
{% if seq.schema %}
|
|
204
|
-
schema=
|
|
204
|
+
schema={{ seq.schema | py_string }},
|
|
205
205
|
{% endif %}
|
|
206
206
|
)
|
|
207
207
|
{% endfor %}
|
|
@@ -209,9 +209,9 @@ if TYPE_CHECKING:
|
|
|
209
209
|
|
|
210
210
|
|
|
211
211
|
class {{ table.class_name }}({{ base_class }}):
|
|
212
|
-
|
|
212
|
+
{{ (table.description if include_comments and table.description else table.class_name ~ " table.") | py_repr }}
|
|
213
213
|
|
|
214
|
-
__tablename__ =
|
|
214
|
+
__tablename__ = {{ table.table | py_string }} # type: ignore[assignment]
|
|
215
215
|
|
|
216
216
|
{% set has_table_level_args = (table.indexes and (table.indexes | length > 0)) or (table.unique_constraints and (table.unique_constraints | length > 0)) or (table.pk_constraint and table.pk_constraint.columns) or (table.check_constraints and (table.check_constraints | length > 0)) %}
|
|
217
217
|
{% if has_table_level_args %}
|
|
@@ -219,9 +219,9 @@ class {{ table.class_name }}({{ base_class }}):
|
|
|
219
219
|
{% if table.pk_constraint and table.pk_constraint.columns %}
|
|
220
220
|
PrimaryKeyConstraint(
|
|
221
221
|
{% for pk_col in table.pk_constraint.columns %}
|
|
222
|
-
|
|
222
|
+
{{ pk_col | py_string }},
|
|
223
223
|
{% endfor %}
|
|
224
|
-
name=
|
|
224
|
+
name={{ table.pk_constraint.name | py_string }},
|
|
225
225
|
),
|
|
226
226
|
{% endif %}
|
|
227
227
|
{% for check in table.check_constraints %}
|
|
@@ -230,9 +230,9 @@ class {{ table.class_name }}({{ base_class }}):
|
|
|
230
230
|
{% for constraint in table.unique_constraints %}
|
|
231
231
|
UniqueConstraint(
|
|
232
232
|
{% for c in constraint.columns %}
|
|
233
|
-
|
|
233
|
+
{{ c | py_string }},
|
|
234
234
|
{% endfor %}
|
|
235
|
-
name=
|
|
235
|
+
name={{ constraint.name | py_string }},
|
|
236
236
|
{% if constraint.nulls_not_distinct %}
|
|
237
237
|
postgresql_nulls_not_distinct=True,
|
|
238
238
|
{% endif %}
|
|
@@ -252,49 +252,49 @@ class {{ table.class_name }}({{ base_class }}):
|
|
|
252
252
|
),
|
|
253
253
|
{% elif idx.where and idx.unique %}
|
|
254
254
|
Index(
|
|
255
|
-
|
|
255
|
+
{{ idx.name | py_string }},
|
|
256
256
|
{% for c in idx.columns %}
|
|
257
|
-
|
|
257
|
+
{{ c | py_string }},
|
|
258
258
|
{% endfor %}
|
|
259
259
|
unique=True,
|
|
260
|
-
postgresql_where=text(
|
|
260
|
+
postgresql_where=text({{ idx.where | py_string }}),
|
|
261
261
|
),
|
|
262
262
|
{% elif idx.where %}
|
|
263
263
|
Index(
|
|
264
|
-
|
|
264
|
+
{{ idx.name | py_string }},
|
|
265
265
|
{% for c in idx.columns %}
|
|
266
|
-
|
|
266
|
+
{{ c | py_string }},
|
|
267
267
|
{% endfor %}
|
|
268
|
-
postgresql_where=text(
|
|
268
|
+
postgresql_where=text({{ idx.where | py_string }}),
|
|
269
269
|
),
|
|
270
270
|
{% elif idx.unique %}
|
|
271
271
|
UniqueConstraint(
|
|
272
272
|
{% for c in idx.columns %}
|
|
273
|
-
|
|
273
|
+
{{ c | py_string }},
|
|
274
274
|
{% endfor %}
|
|
275
|
-
name=
|
|
275
|
+
name={{ idx.name | py_string }},
|
|
276
276
|
),
|
|
277
277
|
{% else %}
|
|
278
278
|
Index(
|
|
279
|
-
|
|
279
|
+
{{ idx.name | py_string }},
|
|
280
280
|
{% for c in idx.columns %}
|
|
281
|
-
|
|
281
|
+
{{ c | py_string }},
|
|
282
282
|
{% endfor %}
|
|
283
283
|
),
|
|
284
284
|
{% endif %}
|
|
285
285
|
{% endfor %}
|
|
286
286
|
{
|
|
287
|
-
"schema":
|
|
287
|
+
"schema": {{ table.schema | py_string }},
|
|
288
288
|
{% if include_comments and table.description %}
|
|
289
|
-
"comment":
|
|
289
|
+
"comment": {{ table.description | py_string }},
|
|
290
290
|
{% endif %}
|
|
291
291
|
},
|
|
292
292
|
)
|
|
293
293
|
{% else %}
|
|
294
294
|
__table_args__ = {
|
|
295
|
-
"schema":
|
|
295
|
+
"schema": {{ table.schema | py_string }},
|
|
296
296
|
{% if include_comments and table.description %}
|
|
297
|
-
"comment":
|
|
297
|
+
"comment": {{ table.description | py_string }},
|
|
298
298
|
{% endif %}
|
|
299
299
|
}
|
|
300
300
|
{% endif %}
|
|
@@ -307,7 +307,7 @@ class {{ table.class_name }}({{ base_class }}):
|
|
|
307
307
|
{{ col.sa_type }},
|
|
308
308
|
{% set col_args = [] -%}
|
|
309
309
|
{% if col.fk_target -%}
|
|
310
|
-
{% set _ = col_args.append('ForeignKey(
|
|
310
|
+
{% set _ = col_args.append('ForeignKey(' ~ (col.fk_target | py_string) ~ ')') -%}
|
|
311
311
|
{% endif -%}
|
|
312
312
|
{% if col.sequence -%}
|
|
313
313
|
{% set _ = col_args.append(col.sequence.var_name) -%}
|
|
@@ -326,7 +326,7 @@ class {{ table.class_name }}({{ base_class }}):
|
|
|
326
326
|
{% if col.sequence -%}
|
|
327
327
|
{% set _ = col_args.append('server_default=' ~ col.sequence.var_name ~ '.next_value()') -%}
|
|
328
328
|
{% elif col.server_default -%}
|
|
329
|
-
{% set _ = col_args.append('server_default=text(
|
|
329
|
+
{% set _ = col_args.append('server_default=text(' ~ (col.server_default | py_string) ~ ')') -%}
|
|
330
330
|
{% endif -%}
|
|
331
331
|
{% if include_comments and col.description -%}
|
|
332
332
|
{% set _ = col_args.append('comment=' ~ (col.description | py_repr)) -%}
|
|
@@ -340,10 +340,10 @@ class {{ table.class_name }}({{ base_class }}):
|
|
|
340
340
|
# Relationships
|
|
341
341
|
{% for rel in table.relationships %}
|
|
342
342
|
{{ rel.attr_name }}: Mapped[{{ rel.python_type }}] = relationship(
|
|
343
|
-
|
|
344
|
-
back_populates=
|
|
345
|
-
{% if rel.
|
|
346
|
-
foreign_keys=
|
|
343
|
+
{{ rel.target_class | py_string }},
|
|
344
|
+
back_populates={{ rel.back_populates | py_string }},
|
|
345
|
+
{% if rel.fk_expression %}
|
|
346
|
+
foreign_keys={{ rel.fk_expression | py_repr }},
|
|
347
347
|
{% endif %}
|
|
348
348
|
)
|
|
349
349
|
{% endfor %}
|
|
@@ -14,7 +14,7 @@ __all__ = [
|
|
|
14
14
|
"metadata",
|
|
15
15
|
{% for domain in domains %}
|
|
16
16
|
{% for table in domain.tables %}
|
|
17
|
-
|
|
17
|
+
{{ table.module_name | py_string }},
|
|
18
18
|
{% endfor %}
|
|
19
19
|
{% endfor %}
|
|
20
20
|
]
|
|
@@ -41,14 +41,14 @@ from .{{ domain.module_name }}.{{ table.module_name }} import {{ table.export_na
|
|
|
41
41
|
{% endfor %}
|
|
42
42
|
|
|
43
43
|
__all__ = [
|
|
44
|
-
|
|
44
|
+
{{ base_class | py_string }},
|
|
45
45
|
{% for domain in domains %}
|
|
46
46
|
{% for table in domain.tables %}
|
|
47
|
-
|
|
47
|
+
{{ table.export_name | py_string }},
|
|
48
48
|
{% endfor %}
|
|
49
49
|
{% endfor %}
|
|
50
50
|
]
|
|
51
51
|
{% else %}
|
|
52
|
-
__all__ = [
|
|
52
|
+
__all__ = [{{ base_class | py_string }}]
|
|
53
53
|
{% endif %}
|
|
54
54
|
{% endif %}
|
package/bin/dbspec/dbspec
CHANGED
|
Binary file
|
package/package.json
CHANGED