amsdal_cli 0.4.13__py3-none-any.whl → 0.4.14__py3-none-any.whl
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.
- amsdal_cli/__about__.py +1 -1
- amsdal_cli/commands/build/schemas/data_models/options.py +1 -1
- amsdal_cli/commands/generate/utils/tests/model_utils.py +30 -2
- amsdal_cli/commands/generate/utils/tests/type_utils.py +23 -0
- amsdal_cli/commands/generate/utils/tests/unit.py +1 -0
- amsdal_cli/commands/migrations/sub_commands/apply.py +2 -1
- amsdal_cli/commands/migrations/sub_commands/list.py +4 -2
- amsdal_cli/commands/migrations/sub_commands/make.py +2 -1
- amsdal_cli/commands/register_connection/utils/migrate_models.py +8 -4
- amsdal_cli/commands/restore/command.py +147 -40
- amsdal_cli/commands/serve/services/supervisor.py +2 -1
- amsdal_cli/commands/serve/utils.py +4 -2
- amsdal_cli/commands/tests/command.py +4 -2
- {amsdal_cli-0.4.13.dist-info → amsdal_cli-0.4.14.dist-info}/METADATA +1 -1
- {amsdal_cli-0.4.13.dist-info → amsdal_cli-0.4.14.dist-info}/RECORD +18 -18
- {amsdal_cli-0.4.13.dist-info → amsdal_cli-0.4.14.dist-info}/WHEEL +0 -0
- {amsdal_cli-0.4.13.dist-info → amsdal_cli-0.4.14.dist-info}/entry_points.txt +0 -0
- {amsdal_cli-0.4.13.dist-info → amsdal_cli-0.4.14.dist-info}/licenses/LICENSE.txt +0 -0
amsdal_cli/__about__.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import ast
|
|
2
|
+
import importlib
|
|
2
3
|
import json
|
|
4
|
+
import pkgutil
|
|
5
|
+
import sys
|
|
3
6
|
from pathlib import Path
|
|
4
7
|
|
|
5
8
|
from amsdal_models.schemas.object_schema import model_to_object_schema
|
|
6
9
|
from amsdal_utils.config.manager import AmsdalConfigManager
|
|
7
10
|
from amsdal_utils.schemas.schema import ObjectSchema
|
|
8
|
-
from amsdal_utils.utils.classes import import_class
|
|
9
11
|
from amsdal_utils.utils.text import classify
|
|
10
12
|
from amsdal_utils.utils.text import to_snake_case
|
|
11
13
|
|
|
@@ -17,12 +19,38 @@ from amsdal_cli.utils.cli_config import ModelsFormat
|
|
|
17
19
|
from amsdal_cli.utils.text import rich_highlight
|
|
18
20
|
|
|
19
21
|
|
|
22
|
+
def find_model_class(package: str, class_name: str) -> type:
|
|
23
|
+
importlib.invalidate_caches()
|
|
24
|
+
|
|
25
|
+
prefix = package + '.'
|
|
26
|
+
for mod_name in list(sys.modules):
|
|
27
|
+
if mod_name == package or mod_name.startswith(prefix):
|
|
28
|
+
del sys.modules[mod_name]
|
|
29
|
+
|
|
30
|
+
spec = importlib.util.find_spec(package)
|
|
31
|
+
if not spec or not spec.submodule_search_locations:
|
|
32
|
+
msg = f"Can't find package {package!r} on disk"
|
|
33
|
+
raise ImportError(msg)
|
|
34
|
+
|
|
35
|
+
paths = spec.submodule_search_locations
|
|
36
|
+
|
|
37
|
+
for _, full_name, _ in pkgutil.walk_packages(paths, prefix=prefix):
|
|
38
|
+
module = importlib.import_module(full_name)
|
|
39
|
+
|
|
40
|
+
if hasattr(module, class_name):
|
|
41
|
+
return getattr(module, class_name)
|
|
42
|
+
|
|
43
|
+
msg = f'Could not find class {class_name!r} in package {package!r}'
|
|
44
|
+
raise ImportError(msg)
|
|
45
|
+
|
|
46
|
+
|
|
20
47
|
def get_class_schema(models_dir: Path, class_name: str, cli_config: CliConfig) -> ObjectSchema:
|
|
21
48
|
model_name = classify(class_name)
|
|
22
49
|
name = to_snake_case(model_name)
|
|
23
50
|
|
|
24
51
|
if cli_config.models_format == ModelsFormat.PY:
|
|
25
|
-
model_class = import_class(f'models.{name}.{class_name}')
|
|
52
|
+
# model_class = import_class(f'models.{name}.{class_name}')
|
|
53
|
+
model_class = find_model_class('models', class_name)
|
|
26
54
|
|
|
27
55
|
return model_to_object_schema(model_class)
|
|
28
56
|
else:
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import ast
|
|
2
|
+
from datetime import date
|
|
3
|
+
from datetime import timezone
|
|
2
4
|
from pathlib import Path
|
|
3
5
|
|
|
4
6
|
import faker
|
|
@@ -115,6 +117,27 @@ def _generate_values_for_type(
|
|
|
115
117
|
if test_data_type == TestDataType.DYNAMIC:
|
|
116
118
|
return _faker_call('pybool')
|
|
117
119
|
|
|
120
|
+
elif data_type == 'datetime':
|
|
121
|
+
if test_data_type == TestDataType.DUMMY:
|
|
122
|
+
return ast.Constant(value='2023-01-01T00:00:00Z')
|
|
123
|
+
|
|
124
|
+
if test_data_type == TestDataType.RANDOM:
|
|
125
|
+
dt = FAKER.date_time(tzinfo=timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0)
|
|
126
|
+
return ast.Constant(value=dt)
|
|
127
|
+
if test_data_type == TestDataType.DYNAMIC:
|
|
128
|
+
return _faker_call('date_time')
|
|
129
|
+
|
|
130
|
+
elif data_type == 'date':
|
|
131
|
+
if test_data_type == TestDataType.DUMMY:
|
|
132
|
+
return ast.Constant(value=date(2023, 1, 1))
|
|
133
|
+
|
|
134
|
+
if test_data_type == TestDataType.RANDOM:
|
|
135
|
+
dt = FAKER.date_time(tzinfo=timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0)
|
|
136
|
+
return ast.Constant(value=dt.date())
|
|
137
|
+
|
|
138
|
+
if test_data_type == TestDataType.DYNAMIC:
|
|
139
|
+
return _faker_call('date')
|
|
140
|
+
|
|
118
141
|
elif data_type == 'array':
|
|
119
142
|
if not type_data:
|
|
120
143
|
msg = 'Type data is required for array type.'
|
|
@@ -590,6 +590,7 @@ def generate_unit_tests(
|
|
|
590
590
|
|
|
591
591
|
# Add necessary imports
|
|
592
592
|
module.body.append(ast.Import(names=[ast.alias(name='pytest', asname=None)]))
|
|
593
|
+
module.body.append(ast.Import(names=[ast.alias(name='datetime', asname=None)]))
|
|
593
594
|
module.body.append(
|
|
594
595
|
ast.ImportFrom(module='faker', names=[ast.alias(name='Faker')], level=0),
|
|
595
596
|
)
|
|
@@ -111,7 +111,8 @@ async def _async_sync_apply(
|
|
|
111
111
|
from amsdal_cli.utils.text import rich_warning
|
|
112
112
|
|
|
113
113
|
amsdal_manager = AsyncAmsdalManager()
|
|
114
|
-
|
|
114
|
+
if not amsdal_manager.is_setup:
|
|
115
|
+
await amsdal_manager.setup()
|
|
115
116
|
|
|
116
117
|
try:
|
|
117
118
|
amsdal_manager.authenticate()
|
|
@@ -16,7 +16,8 @@ def _fetch_migrations(app_migrations_path: Path) -> list['MigrationFile']:
|
|
|
16
16
|
from amsdal_models.migration.file_migration_store import FileMigrationStore
|
|
17
17
|
|
|
18
18
|
amsdal_manager = AmsdalManager()
|
|
19
|
-
amsdal_manager.
|
|
19
|
+
if not amsdal_manager.is_setup:
|
|
20
|
+
amsdal_manager.setup()
|
|
20
21
|
amsdal_manager.authenticate()
|
|
21
22
|
amsdal_manager.post_setup()
|
|
22
23
|
|
|
@@ -29,7 +30,8 @@ async def _async_fetch_migrations(app_migrations_path: Path) -> list['MigrationF
|
|
|
29
30
|
from amsdal_models.migration.file_migration_store import AsyncFileMigrationStore
|
|
30
31
|
|
|
31
32
|
amsdal_manager = AsyncAmsdalManager()
|
|
32
|
-
|
|
33
|
+
if not amsdal_manager.is_setup:
|
|
34
|
+
await amsdal_manager.setup()
|
|
33
35
|
|
|
34
36
|
try:
|
|
35
37
|
amsdal_manager.authenticate()
|
|
@@ -86,7 +86,8 @@ async def _async_make_migrations(
|
|
|
86
86
|
from amsdal_cli.utils.text import rich_success
|
|
87
87
|
|
|
88
88
|
amsdal_manager = AsyncAmsdalManager()
|
|
89
|
-
|
|
89
|
+
if not amsdal_manager.is_setup:
|
|
90
|
+
await amsdal_manager.setup()
|
|
90
91
|
amsdal_manager.authenticate()
|
|
91
92
|
await amsdal_manager.post_setup()
|
|
92
93
|
|
|
@@ -86,7 +86,8 @@ def _migrate_models(config_path: Path) -> None:
|
|
|
86
86
|
# setup the new manager and connections
|
|
87
87
|
AmsdalConfigManager().load_config(config_path)
|
|
88
88
|
new_manager = AmsdalManager()
|
|
89
|
-
new_manager.
|
|
89
|
+
if not new_manager.is_setup:
|
|
90
|
+
new_manager.setup()
|
|
90
91
|
new_manager.post_setup()
|
|
91
92
|
|
|
92
93
|
schemas = MigrationSchemas()
|
|
@@ -175,7 +176,8 @@ async def _async_migrate_models(config_path: Path) -> None:
|
|
|
175
176
|
# setup the new manager and connections
|
|
176
177
|
AmsdalConfigManager().load_config(config_path)
|
|
177
178
|
new_manager = AsyncAmsdalManager()
|
|
178
|
-
|
|
179
|
+
if not new_manager.is_setup:
|
|
180
|
+
await new_manager.setup()
|
|
179
181
|
await new_manager.post_setup()
|
|
180
182
|
|
|
181
183
|
schemas = MigrationSchemas()
|
|
@@ -253,7 +255,8 @@ def _migrate_data(new_connection_name: str) -> None:
|
|
|
253
255
|
from amsdal_utils.models.enums import ModuleType
|
|
254
256
|
|
|
255
257
|
origin_manager = AmsdalManager()
|
|
256
|
-
origin_manager.
|
|
258
|
+
if not origin_manager.is_setup:
|
|
259
|
+
origin_manager.setup()
|
|
257
260
|
origin_manager.post_setup()
|
|
258
261
|
|
|
259
262
|
model_class_loader = ModelClassLoader(settings.USER_MODELS_MODULE)
|
|
@@ -305,7 +308,8 @@ async def _async_migrate_data(new_connection_name: str) -> None:
|
|
|
305
308
|
from amsdal_utils.models.enums import ModuleType
|
|
306
309
|
|
|
307
310
|
origin_manager = AsyncAmsdalManager()
|
|
308
|
-
|
|
311
|
+
if not origin_manager.is_setup:
|
|
312
|
+
await origin_manager.setup()
|
|
309
313
|
await origin_manager.post_setup()
|
|
310
314
|
|
|
311
315
|
model_class_loader = ModelClassLoader(settings.USER_MODELS_MODULE)
|
|
@@ -91,7 +91,8 @@ def _sync_restore_models(app_source_path: Path, cli_config: 'CliConfig') -> None
|
|
|
91
91
|
from amsdal_cli.utils.text import rich_success
|
|
92
92
|
|
|
93
93
|
amsdal_manager = AmsdalManager()
|
|
94
|
-
amsdal_manager.
|
|
94
|
+
if not amsdal_manager.is_setup:
|
|
95
|
+
amsdal_manager.setup()
|
|
95
96
|
amsdal_manager.authenticate()
|
|
96
97
|
amsdal_manager.register_internal_classes()
|
|
97
98
|
class_manager = ClassManager()
|
|
@@ -187,7 +188,8 @@ async def _async_restore_models(app_source_path: Path, cli_config: 'CliConfig')
|
|
|
187
188
|
from amsdal_cli.utils.text import rich_success
|
|
188
189
|
|
|
189
190
|
amsdal_manager = AsyncAmsdalManager()
|
|
190
|
-
|
|
191
|
+
if not amsdal_manager.is_setup:
|
|
192
|
+
await amsdal_manager.setup()
|
|
191
193
|
amsdal_manager.authenticate()
|
|
192
194
|
amsdal_manager.register_internal_classes()
|
|
193
195
|
class_manager = ClassManager()
|
|
@@ -274,27 +276,39 @@ def _restore_state_db(cli_config: 'CliConfig', config_path: Path | None) -> None
|
|
|
274
276
|
state_connection = _get_state_connection(config_manager.get_config())
|
|
275
277
|
|
|
276
278
|
class_object_ref, class_object_meta_ref = _get_class_object_reference(lakehouse_connection)
|
|
277
|
-
model_pks, model_fks = _fetch_model_pks_and_fks(lakehouse_connection, class_object_ref)
|
|
278
|
-
|
|
279
|
-
for table_ref, schema in _get_user_schemas(
|
|
279
|
+
model_pks, model_fks, model_m2ms = _fetch_model_pks_and_fks(lakehouse_connection, class_object_ref)
|
|
280
|
+
user_schemas = _get_user_schemas(
|
|
280
281
|
lakehouse_connection,
|
|
281
282
|
class_object_ref,
|
|
282
283
|
class_object_meta_ref,
|
|
283
284
|
model_fks=model_fks,
|
|
284
285
|
model_pks=model_pks, # type: ignore[arg-type]
|
|
285
|
-
)
|
|
286
|
+
)
|
|
287
|
+
user_scheams_with_tries = [(table_ref, schema, 0) for table_ref, schema in user_schemas]
|
|
288
|
+
refs_by_name = {table_ref.name: table_ref for table_ref, _ in user_schemas}
|
|
289
|
+
|
|
290
|
+
m2m_all_data = []
|
|
291
|
+
while user_scheams_with_tries:
|
|
292
|
+
table_ref, schema, current_iteration = user_scheams_with_tries.pop(0)
|
|
286
293
|
rprint(rich_info(f'Restoring {table_ref.name}'))
|
|
287
294
|
glue_schema = object_schema_to_glue_schema(schema, use_foreign_keys=True)
|
|
288
295
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
296
|
+
try:
|
|
297
|
+
state_connection.run_schema_command(
|
|
298
|
+
glue.SchemaCommand(
|
|
299
|
+
mutations=[
|
|
300
|
+
glue.RegisterSchema(
|
|
301
|
+
schema=glue_schema,
|
|
302
|
+
),
|
|
303
|
+
],
|
|
304
|
+
),
|
|
305
|
+
)
|
|
306
|
+
except Exception:
|
|
307
|
+
if current_iteration < 3: # noqa: PLR2004
|
|
308
|
+
user_scheams_with_tries.append((table_ref, schema, current_iteration + 1))
|
|
309
|
+
continue
|
|
310
|
+
else:
|
|
311
|
+
raise
|
|
298
312
|
|
|
299
313
|
for item in _get_all_latest_data(lakehouse_connection, table_ref):
|
|
300
314
|
item.pop(SECONDARY_PARTITION_KEY, None)
|
|
@@ -302,6 +316,16 @@ def _restore_state_db(cli_config: 'CliConfig', config_path: Path | None) -> None
|
|
|
302
316
|
|
|
303
317
|
from amsdal_data.connections.historical.data_query_transform import META_CLASS_NAME
|
|
304
318
|
|
|
319
|
+
data, m2m_data = _build_data(
|
|
320
|
+
item,
|
|
321
|
+
model_name=table_ref.metadata[META_CLASS_NAME], # type: ignore[index]
|
|
322
|
+
model_pks=model_pks,
|
|
323
|
+
model_fks=model_fks,
|
|
324
|
+
model_m2ms=model_m2ms,
|
|
325
|
+
refs_by_name=refs_by_name,
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
m2m_all_data.extend(m2m_data)
|
|
305
329
|
state_connection.run_mutations(
|
|
306
330
|
mutations=[
|
|
307
331
|
glue.InsertData(
|
|
@@ -310,18 +334,18 @@ def _restore_state_db(cli_config: 'CliConfig', config_path: Path | None) -> None
|
|
|
310
334
|
version=glue.Version.LATEST,
|
|
311
335
|
metadata=table_ref.metadata,
|
|
312
336
|
),
|
|
313
|
-
data=[
|
|
314
|
-
_build_data(
|
|
315
|
-
item,
|
|
316
|
-
model_name=table_ref.metadata[META_CLASS_NAME], # type: ignore[index]
|
|
317
|
-
model_pks=model_pks,
|
|
318
|
-
model_fks=model_fks,
|
|
319
|
-
),
|
|
320
|
-
],
|
|
337
|
+
data=[data],
|
|
321
338
|
),
|
|
322
339
|
],
|
|
323
340
|
)
|
|
324
341
|
rprint('.', end='')
|
|
342
|
+
rprint('Inserting m2m data...')
|
|
343
|
+
for _m2m_data in m2m_all_data:
|
|
344
|
+
try:
|
|
345
|
+
state_connection.run_mutations(mutations=[_m2m_data])
|
|
346
|
+
except Exception:
|
|
347
|
+
rprint('Error inserting m2m data')
|
|
348
|
+
|
|
325
349
|
rprint(rich_success('Done! All classes are restored.'))
|
|
326
350
|
|
|
327
351
|
|
|
@@ -330,14 +354,22 @@ def _build_data(
|
|
|
330
354
|
model_name: str,
|
|
331
355
|
model_pks: dict[str, dict[str, type | glue.Schema | glue.SchemaReference]],
|
|
332
356
|
model_fks: dict[str, Any],
|
|
333
|
-
|
|
357
|
+
model_m2ms: dict[str, Any],
|
|
358
|
+
refs_by_name: dict[str, glue.SchemaReference],
|
|
359
|
+
) -> tuple[glue.Data, list[glue.InsertData]]:
|
|
360
|
+
from amsdal_data.connections.historical.data_query_transform import META_FOREIGN_KEYS
|
|
361
|
+
from amsdal_data.connections.historical.data_query_transform import META_PRIMARY_KEY_FIELDS
|
|
362
|
+
|
|
334
363
|
pks = model_pks[model_name]
|
|
335
364
|
fks = model_fks.get(model_name, {})
|
|
365
|
+
m2ms = model_m2ms.get(model_name, {})
|
|
336
366
|
data = {}
|
|
337
367
|
foreign_keys_meta = {}
|
|
368
|
+
m2m_inserts = []
|
|
338
369
|
|
|
339
370
|
for _name, _value in item.items():
|
|
340
371
|
fk = fks.get(_name)
|
|
372
|
+
m2m = m2ms.get(_name)
|
|
341
373
|
|
|
342
374
|
if fk:
|
|
343
375
|
_fields = list(fk[0].keys())
|
|
@@ -353,19 +385,73 @@ def _build_data(
|
|
|
353
385
|
|
|
354
386
|
for _field, object_id in zip(_fields, _object_id, strict=False):
|
|
355
387
|
data[_field] = object_id
|
|
388
|
+
elif m2m:
|
|
389
|
+
target_model_name = m2m[1]
|
|
390
|
+
|
|
391
|
+
m2m_table_name = f'{model_name}{target_model_name}'
|
|
392
|
+
m2m_table_ref = refs_by_name.get(m2m_table_name)
|
|
393
|
+
if not m2m_table_ref:
|
|
394
|
+
continue
|
|
395
|
+
|
|
396
|
+
_datas = []
|
|
397
|
+
|
|
398
|
+
for _val in _value:
|
|
399
|
+
_datas.append(
|
|
400
|
+
glue.Data(
|
|
401
|
+
data={
|
|
402
|
+
f'{model_name.lower()}_partition_key': item['partition_key'],
|
|
403
|
+
f'{target_model_name.lower()}_partition_key': _val['ref']['object_id'],
|
|
404
|
+
},
|
|
405
|
+
metadata={
|
|
406
|
+
META_PRIMARY_KEY_FIELDS: {
|
|
407
|
+
f'{model_name.lower()}_partition_key': str,
|
|
408
|
+
f'{target_model_name.lower()}_partition_key': str,
|
|
409
|
+
},
|
|
410
|
+
META_FOREIGN_KEYS: {
|
|
411
|
+
f'{model_name.lower()}_partition_key': {
|
|
412
|
+
'ref': {
|
|
413
|
+
'resource': 'statedb',
|
|
414
|
+
'class_name': model_name,
|
|
415
|
+
'object_id': item['partition_key'],
|
|
416
|
+
'class_version': 'LATEST',
|
|
417
|
+
'object_version': 'LATEST',
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
f'{target_model_name.lower()}_partition_key': {
|
|
421
|
+
'ref': {
|
|
422
|
+
'resource': 'statedb',
|
|
423
|
+
'class_name': target_model_name,
|
|
424
|
+
'object_id': _val['ref']['object_id'],
|
|
425
|
+
'class_version': 'LATEST',
|
|
426
|
+
'object_version': 'LATEST',
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
)
|
|
432
|
+
)
|
|
433
|
+
|
|
434
|
+
m2m_inserts.append(
|
|
435
|
+
glue.InsertData(
|
|
436
|
+
schema=glue.SchemaReference(
|
|
437
|
+
name=m2m_table_ref.name,
|
|
438
|
+
version=glue.Version.LATEST,
|
|
439
|
+
metadata=m2m_table_ref.metadata,
|
|
440
|
+
),
|
|
441
|
+
data=_datas,
|
|
442
|
+
),
|
|
443
|
+
)
|
|
356
444
|
else:
|
|
357
445
|
data[_name] = _value
|
|
358
446
|
|
|
359
|
-
|
|
360
|
-
from amsdal_data.connections.historical.data_query_transform import META_PRIMARY_KEY_FIELDS
|
|
361
|
-
|
|
362
|
-
return glue.Data(
|
|
447
|
+
_data = glue.Data(
|
|
363
448
|
data=data,
|
|
364
449
|
metadata={
|
|
365
450
|
META_PRIMARY_KEY_FIELDS: pks,
|
|
366
451
|
META_FOREIGN_KEYS: foreign_keys_meta,
|
|
367
452
|
},
|
|
368
453
|
)
|
|
454
|
+
return _data, m2m_inserts
|
|
369
455
|
|
|
370
456
|
|
|
371
457
|
def _get_lakehouse_connection(config: 'AmsdalConfig') -> glue.SqliteConnection | glue.PostgresConnection:
|
|
@@ -399,6 +485,7 @@ def _fetch_model_pks_and_fks(
|
|
|
399
485
|
) -> tuple[
|
|
400
486
|
dict[str, dict[str, type | glue.Schema | glue.SchemaReference]],
|
|
401
487
|
dict[str, dict[str, tuple[dict[str, Any], str, list[str]]]],
|
|
488
|
+
dict[str, dict[str, tuple[dict[str, Any], str, list[str]]]],
|
|
402
489
|
]:
|
|
403
490
|
from amsdal_data.connections.constants import PRIMARY_PARTITION_KEY
|
|
404
491
|
|
|
@@ -407,33 +494,50 @@ def _fetch_model_pks_and_fks(
|
|
|
407
494
|
pk_data: dict[str, dict[str, type | glue.Schema | glue.SchemaReference]] = {
|
|
408
495
|
schema[PRIMARY_PARTITION_KEY]: _build_pks(schema, all_schemas=schemas) for schema in schemas
|
|
409
496
|
}
|
|
410
|
-
fk_data: dict[str, dict[str, tuple[dict[str, Any], str, list[str]]]] = {
|
|
411
|
-
|
|
412
|
-
|
|
497
|
+
fk_data: dict[str, dict[str, tuple[dict[str, Any], str, list[str]]]] = {}
|
|
498
|
+
m2m_data: dict[str, dict[str, tuple[dict[str, Any], str, list[str]]]] = {}
|
|
499
|
+
|
|
500
|
+
for schema in schemas:
|
|
501
|
+
fk_data[schema[PRIMARY_PARTITION_KEY]], m2m_data[schema[PRIMARY_PARTITION_KEY]] = _build_fks(
|
|
502
|
+
schema, all_schemas=schemas
|
|
503
|
+
)
|
|
413
504
|
|
|
414
|
-
return pk_data, fk_data
|
|
505
|
+
return pk_data, fk_data, m2m_data
|
|
415
506
|
|
|
416
507
|
|
|
417
508
|
def _build_fks(
|
|
418
509
|
schema: dict[str, Any],
|
|
419
510
|
all_schemas: list[dict[str, Any]],
|
|
420
|
-
) ->
|
|
511
|
+
) -> tuple[
|
|
512
|
+
dict[str, tuple[dict[str, Any], str, list[str]]],
|
|
513
|
+
dict[str, tuple[dict[str, Any], str, list[str]]],
|
|
514
|
+
]:
|
|
421
515
|
fks: dict[str, tuple[dict[str, str], str, list[str]]] = {}
|
|
516
|
+
m2ms: dict[str, tuple[dict[str, str], str, list[str]]] = {}
|
|
422
517
|
|
|
423
518
|
for prop_name, prop in schema['properties'].items():
|
|
424
519
|
if prop['type'] == CoreTypes.ARRAY.value:
|
|
425
520
|
_type = prop['items']['type']
|
|
521
|
+
is_m2m = True
|
|
426
522
|
else:
|
|
427
523
|
_type = prop['type']
|
|
524
|
+
is_m2m = False
|
|
428
525
|
|
|
429
526
|
schema_type = get_schema_ref(_type, all_schemas)
|
|
430
527
|
if schema_type:
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
528
|
+
if is_m2m:
|
|
529
|
+
m2ms[prop_name] = (
|
|
530
|
+
_build_fields(prop_name, prop.get('db_field'), schema_type, all_schemas),
|
|
531
|
+
schema_type['table_name'],
|
|
532
|
+
schema_type['primary_key'],
|
|
533
|
+
)
|
|
534
|
+
else:
|
|
535
|
+
fks[prop_name] = (
|
|
536
|
+
_build_fields(prop_name, prop.get('db_field'), schema_type, all_schemas),
|
|
537
|
+
schema_type['table_name'],
|
|
538
|
+
schema_type['primary_key'],
|
|
539
|
+
)
|
|
540
|
+
return fks, m2ms
|
|
437
541
|
|
|
438
542
|
|
|
439
543
|
def _build_pks(
|
|
@@ -690,7 +794,10 @@ def _get_user_schemas(
|
|
|
690
794
|
|
|
691
795
|
if meta_props:
|
|
692
796
|
for prop in meta_props:
|
|
693
|
-
schema_data['properties']
|
|
797
|
+
if prop not in schema_data['properties']:
|
|
798
|
+
schema_data['properties'][prop] = meta_props[prop]
|
|
799
|
+
else:
|
|
800
|
+
schema_data['properties'][prop].update(meta_props[prop])
|
|
694
801
|
|
|
695
802
|
for name, prop in schema_data['properties'].items():
|
|
696
803
|
prop['field_name'] = name
|
|
@@ -351,7 +351,8 @@ class Supervisor:
|
|
|
351
351
|
config_manager.load_config(config_path)
|
|
352
352
|
|
|
353
353
|
amsdal_manager = AmsdalManager()
|
|
354
|
-
amsdal_manager.
|
|
354
|
+
if not amsdal_manager.is_setup:
|
|
355
|
+
amsdal_manager.setup()
|
|
355
356
|
amsdal_manager.authenticate()
|
|
356
357
|
amsdal_manager.init_classes()
|
|
357
358
|
|
|
@@ -87,7 +87,8 @@ def build_app_and_check_migrations(
|
|
|
87
87
|
|
|
88
88
|
amsdal_manager = AmsdalManager()
|
|
89
89
|
amsdal_manager.pre_setup()
|
|
90
|
-
amsdal_manager.
|
|
90
|
+
if not amsdal_manager.is_setup:
|
|
91
|
+
amsdal_manager.setup()
|
|
91
92
|
|
|
92
93
|
if skip_migrations_check:
|
|
93
94
|
return amsdal_manager
|
|
@@ -345,7 +346,8 @@ async def async_build_app_and_check_migrations(
|
|
|
345
346
|
|
|
346
347
|
amsdal_manager = AsyncAmsdalManager()
|
|
347
348
|
amsdal_manager.pre_setup()
|
|
348
|
-
|
|
349
|
+
if not amsdal_manager.is_setup:
|
|
350
|
+
await amsdal_manager.setup()
|
|
349
351
|
|
|
350
352
|
if skip_migrations_check:
|
|
351
353
|
return amsdal_manager
|
|
@@ -20,7 +20,8 @@ PYTEST_COMMAND = 'pytest'
|
|
|
20
20
|
|
|
21
21
|
def _init(cli_config: CliConfig, app_source_path: Path, config_path: Path) -> None:
|
|
22
22
|
manager = AmsdalManager()
|
|
23
|
-
manager.
|
|
23
|
+
if not manager.is_setup:
|
|
24
|
+
manager.setup()
|
|
24
25
|
build_app_and_check_migrations(
|
|
25
26
|
cli_config=cli_config,
|
|
26
27
|
output_path=cli_config.app_directory,
|
|
@@ -37,7 +38,8 @@ def _init(cli_config: CliConfig, app_source_path: Path, config_path: Path) -> No
|
|
|
37
38
|
|
|
38
39
|
async def _async_init(cli_config: CliConfig, app_source_path: Path, config_path: Path) -> None:
|
|
39
40
|
amsdal_manager = AsyncAmsdalManager()
|
|
40
|
-
|
|
41
|
+
if not amsdal_manager.is_setup:
|
|
42
|
+
await amsdal_manager.setup()
|
|
41
43
|
await async_build_app_and_check_migrations(
|
|
42
44
|
cli_config=cli_config,
|
|
43
45
|
output_path=cli_config.app_directory,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
amsdal_cli/Third-Party Materials - AMSDAL Dependencies - License Notices.md,sha256=eHOIhsC6pZv3Wf8aKfaBNJhVi20gM6Rm2PakZTrdIOQ,66641
|
|
2
|
-
amsdal_cli/__about__.py,sha256=
|
|
2
|
+
amsdal_cli/__about__.py,sha256=wXplutfyWxsByTpCqDxH2K23UsxxTLWbEWChA8Fk9CE,125
|
|
3
3
|
amsdal_cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
amsdal_cli/app.py,sha256=_ucuLT5ospf1ifFKEG0IMfVnxKjnvPUQ4iMhkvOfCrc,466
|
|
5
5
|
amsdal_cli/main.py,sha256=LtH-BD1eJrAUecjKzC8Gx7kYFUstOMH1erdeJUVqFB8,144
|
|
@@ -13,7 +13,7 @@ amsdal_cli/commands/build/schemas/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeR
|
|
|
13
13
|
amsdal_cli/commands/build/schemas/schema_json_loader.py,sha256=l8u3WftSH4l-a9PbWo2jb-Ks6jzOhmYT14Lesm3WB8A,4776
|
|
14
14
|
amsdal_cli/commands/build/schemas/data_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
15
|
amsdal_cli/commands/build/schemas/data_models/custom_code.py,sha256=slXyNHvhYW79CzBU5UH2Lnsj4DZHsoY0VAIl_oe4_JM,977
|
|
16
|
-
amsdal_cli/commands/build/schemas/data_models/options.py,sha256=
|
|
16
|
+
amsdal_cli/commands/build/schemas/data_models/options.py,sha256=nOf7n-wremduK56G-vMYCezmyo-HnO_fhxepC8mPWps,622
|
|
17
17
|
amsdal_cli/commands/build/schemas/data_models/schemas_directory.py,sha256=E1BonuLhxw4W5upVYKRDH43OcTmmpGk5u_iQjcg0lo0,579
|
|
18
18
|
amsdal_cli/commands/build/schemas/extenders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
19
|
amsdal_cli/commands/build/schemas/extenders/custom_code_extender.py,sha256=wE3jvJkaanPWFiafLWDiIry70WMLxeF6_GEppT1jgvw,1586
|
|
@@ -125,9 +125,9 @@ amsdal_cli/commands/generate/utils/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5
|
|
|
125
125
|
amsdal_cli/commands/generate/utils/tests/async_mode_utils.py,sha256=iub84Pj5TMa38W90Pr5HgkFQLXpUdbmcm9HOx98Oh6o,309
|
|
126
126
|
amsdal_cli/commands/generate/utils/tests/conftest_utils.py,sha256=8KzHtDh7eQGghhj5aZkY7Mu2rrlkBgM4Khf857iGG1Y,838
|
|
127
127
|
amsdal_cli/commands/generate/utils/tests/function_utils.py,sha256=Bkk9JDbANX2aSreNRr1Bste5rPwVKc2HV5xLFg2dQK4,496
|
|
128
|
-
amsdal_cli/commands/generate/utils/tests/model_utils.py,sha256=
|
|
129
|
-
amsdal_cli/commands/generate/utils/tests/type_utils.py,sha256=
|
|
130
|
-
amsdal_cli/commands/generate/utils/tests/unit.py,sha256=
|
|
128
|
+
amsdal_cli/commands/generate/utils/tests/model_utils.py,sha256=EjxZ3AH8ElHndpwkfFa0GUw1cMgYBcHQuzMofusgb7A,3844
|
|
129
|
+
amsdal_cli/commands/generate/utils/tests/type_utils.py,sha256=PkPmSvLCKOK5wWw1Q9oVMUZ0nUpHEtj6PlBsO7enmzY,9247
|
|
130
|
+
amsdal_cli/commands/generate/utils/tests/unit.py,sha256=KRqBhk_jy_1vp0RZub7HdYxfhn3Bra2v0heDNNPldeE,27741
|
|
131
131
|
amsdal_cli/commands/generate/utils/tests/templates/async/conftest.py,sha256=9GfoV_HzwuWtglI7uz0fP5_pOsPk2f56elaoinuPa80,1632
|
|
132
132
|
amsdal_cli/commands/generate/utils/tests/templates/sync/conftest.py,sha256=wMmnKQnVTSJsS5MdH25ChRcc-aQevQYqIZhXwLnZl0U,1564
|
|
133
133
|
amsdal_cli/commands/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -135,9 +135,9 @@ amsdal_cli/commands/migrations/app.py,sha256=0HsKjZ5D2j9xkOi2Fuvs3VdlhWyQnS8XJ6p
|
|
|
135
135
|
amsdal_cli/commands/migrations/command.py,sha256=jlpdYZAc02ZUBxSdzGSzkDxEb1nlHNzoq05FdRCSzus,206
|
|
136
136
|
amsdal_cli/commands/migrations/constants.py,sha256=846-DQ-Iqcxw2akd5aBAmbnXHDmRFqEKu6vai2ZFBkU,35
|
|
137
137
|
amsdal_cli/commands/migrations/sub_commands/__init__.py,sha256=_rWbDyY3DPdN-6vE60djCtHejvSkl6d1e2Z4ScM52bo,976
|
|
138
|
-
amsdal_cli/commands/migrations/sub_commands/apply.py,sha256=
|
|
139
|
-
amsdal_cli/commands/migrations/sub_commands/list.py,sha256=
|
|
140
|
-
amsdal_cli/commands/migrations/sub_commands/make.py,sha256
|
|
138
|
+
amsdal_cli/commands/migrations/sub_commands/apply.py,sha256=26wMVtzBpJawbFPpiXSUGItmzd1XORymcIBgbonVZgw,9475
|
|
139
|
+
amsdal_cli/commands/migrations/sub_commands/list.py,sha256=xOfonot6JAs3ApXe-QRLKfJf2kVsj7TalEMwK3V_uC4,5439
|
|
140
|
+
amsdal_cli/commands/migrations/sub_commands/make.py,sha256=y-SWaGzWx2apuTA57prStSo09VjH7Q9ZNjzEvbVzwo8,6272
|
|
141
141
|
amsdal_cli/commands/new/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
142
142
|
amsdal_cli/commands/new/command.py,sha256=NDuDZNwreyuHsv4tbE-yrNOJViB8wk35IcKvGKQXPXo,3302
|
|
143
143
|
amsdal_cli/commands/new/templates/.amsdal-cli,sha256=PdXPovcT8AfPhqwDLI_4EWFYAS6e3J5JcsHVityBdF8,304
|
|
@@ -156,22 +156,22 @@ amsdal_cli/commands/register_connection/utils/config_updater.py,sha256=CDsaCuli5
|
|
|
156
156
|
amsdal_cli/commands/register_connection/utils/credentials.py,sha256=iaAF5STbKJNIoT8vL30DafTn4uzYnrjumtM3XNHuOS8,1066
|
|
157
157
|
amsdal_cli/commands/register_connection/utils/initialize.py,sha256=PMFoqAIxFB1xzY56FFX2-pRJ_CZbwUbgD25m0Pk1b48,1080
|
|
158
158
|
amsdal_cli/commands/register_connection/utils/meta.py,sha256=PDs2miN0SPW2hCATLY8uGe1WOzDyw-D6my90P-mpcl8,709
|
|
159
|
-
amsdal_cli/commands/register_connection/utils/migrate_models.py,sha256=
|
|
159
|
+
amsdal_cli/commands/register_connection/utils/migrate_models.py,sha256=XN7pPE7KsqEVcQzTCymIn7lIgX4n6UEZkv1v_HlBdgU,13902
|
|
160
160
|
amsdal_cli/commands/register_connection/utils/model_generator.py,sha256=w0vz-i-tMdimcQYmFbtfpOZJF8heTTRIzu1yTdbKBpc,10853
|
|
161
161
|
amsdal_cli/commands/register_connection/utils/tables.py,sha256=FOwbWOpEw485Leoqe8LXCVY5osGKTKlMqWD9oqosapk,474
|
|
162
162
|
amsdal_cli/commands/restore/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
163
|
-
amsdal_cli/commands/restore/command.py,sha256=
|
|
163
|
+
amsdal_cli/commands/restore/command.py,sha256=ya3aHpMLpgF_vMAGSTbBuSHIUwC4FaHhMiwrD6AglTo,32833
|
|
164
164
|
amsdal_cli/commands/restore/enums.py,sha256=6SiKMRGlSjiLyepfbfQFXGAYqlM6Bkoeko2KscntTUQ,307
|
|
165
165
|
amsdal_cli/commands/serve/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
166
166
|
amsdal_cli/commands/serve/command.py,sha256=tjm1T0yrA2P6nlk_KDNv6Gih2Dkt5nMIN-_WUrLhn58,6541
|
|
167
|
-
amsdal_cli/commands/serve/utils.py,sha256=
|
|
167
|
+
amsdal_cli/commands/serve/utils.py,sha256=h-t6trB0nf7bJyz2vU42AQYdbi5DDmF3qHwtqb5R_Yc,17381
|
|
168
168
|
amsdal_cli/commands/serve/filters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
169
169
|
amsdal_cli/commands/serve/filters/models_watch_filter.py,sha256=cnoAjrn-PYDAFq5MtgbQ6QeCvJJmcNisVNlA8QtFv4A,170
|
|
170
170
|
amsdal_cli/commands/serve/filters/static_files_watch_filter.py,sha256=jKAF5RHq1au2v0kcOrqaAHP1x5IUjt_KgZURJLm29Tw,552
|
|
171
171
|
amsdal_cli/commands/serve/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
172
|
-
amsdal_cli/commands/serve/services/supervisor.py,sha256=
|
|
172
|
+
amsdal_cli/commands/serve/services/supervisor.py,sha256=YAt8pT8qev5DN_u8zpiEsDvAKJpPdoqczxAwSSlSJpU,15216
|
|
173
173
|
amsdal_cli/commands/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
174
|
-
amsdal_cli/commands/tests/command.py,sha256=
|
|
174
|
+
amsdal_cli/commands/tests/command.py,sha256=26fOKdCRzQ54NsrY2pSbqr8g6_J89jCg1f5Rey_UgP0,3843
|
|
175
175
|
amsdal_cli/commands/verify/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
176
176
|
amsdal_cli/commands/verify/command.py,sha256=Dgg0brt1pBqyI4ZMM02NgBg7GC5oKAwvv298teIUT0I,2242
|
|
177
177
|
amsdal_cli/commands/verify/models.py,sha256=u9kvoRqNv0wbp0hDUi1GvgWbk417RifFmRvT6AVr2NE,444
|
|
@@ -199,8 +199,8 @@ amsdal_cli/utils/vcs/base.py,sha256=jC05ExJZDnyHAsW7_4IDf8gQcYgK4dXq3zNlFIX66T4,
|
|
|
199
199
|
amsdal_cli/utils/vcs/dummy.py,sha256=Lk8MT-b0YlHHUsiXsq5cvmPwcl4jTYdo8piN5_C8ORA,434
|
|
200
200
|
amsdal_cli/utils/vcs/enums.py,sha256=tYR9LN1IOr8BZFbSeX_vDlhn8fPl4IU-Yakii8lRDYs,69
|
|
201
201
|
amsdal_cli/utils/vcs/git.py,sha256=xHynbZcV6p2D3RFCwu1MGGpV9D7eK-pGUtO8kVexTQM,1269
|
|
202
|
-
amsdal_cli-0.4.
|
|
203
|
-
amsdal_cli-0.4.
|
|
204
|
-
amsdal_cli-0.4.
|
|
205
|
-
amsdal_cli-0.4.
|
|
206
|
-
amsdal_cli-0.4.
|
|
202
|
+
amsdal_cli-0.4.14.dist-info/METADATA,sha256=SBk7ErSaRWFtW5SJNvmhag3LuXHPDXv1mw8fG2YnMX0,57050
|
|
203
|
+
amsdal_cli-0.4.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
204
|
+
amsdal_cli-0.4.14.dist-info/entry_points.txt,sha256=GC-8LZsD3W--Pd9_gD4W3tw3ZZyPbSvkZ-qWc9Fx0NI,47
|
|
205
|
+
amsdal_cli-0.4.14.dist-info/licenses/LICENSE.txt,sha256=hG-541PFYfNJi9WRZi_hno91UyqNg7YLK8LR3vLblZA,27355
|
|
206
|
+
amsdal_cli-0.4.14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|