zrb 1.0.0a10__py3-none-any.whl → 1.0.0a14__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.
- zrb/builtin/__init__.py +15 -5
- zrb/builtin/project/add/fastapp.py +32 -17
- zrb/builtin/project/add/fastapp_template/_zrb/column/create_column_task.py +11 -0
- zrb/builtin/project/add/fastapp_template/_zrb/config.py +4 -4
- zrb/builtin/project/add/fastapp_template/_zrb/entity/create_entity_task.py +196 -0
- zrb/builtin/project/add/fastapp_template/_zrb/entity/module_template/service/my_entity/my_entity_usecase.py +66 -0
- zrb/builtin/project/add/fastapp_template/_zrb/entity/module_template/service/my_entity/repository/factory.py +13 -0
- zrb/builtin/project/add/fastapp_template/_zrb/entity/module_template/service/my_entity/repository/my_entity_db_repository.py +33 -0
- zrb/builtin/project/add/fastapp_template/_zrb/entity/module_template/service/my_entity/repository/my_entity_repository.py +39 -0
- zrb/builtin/project/add/fastapp_template/_zrb/entity/schema.template.py +29 -0
- zrb/builtin/project/add/fastapp_template/_zrb/group.py +9 -5
- zrb/builtin/project/add/fastapp_template/_zrb/helper.py +25 -11
- zrb/builtin/project/add/fastapp_template/_zrb/input.py +43 -0
- zrb/builtin/project/add/fastapp_template/_zrb/main.py +30 -21
- zrb/builtin/project/add/fastapp_template/_zrb/module/create_module_task.py +136 -0
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/alembic.ini +117 -0
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/api_client.py +6 -0
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/direct_client.py +6 -0
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/factory.py +9 -0
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/migration/README +1 -0
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/migration/env.py +108 -0
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/migration/script.py.mako +26 -0
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/migration/versions/3093c7336477_add_user_table.py +37 -0
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/migration_metadata.py +3 -0
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/route.py +19 -0
- zrb/builtin/project/add/fastapp_template/_zrb/module/run_module.template.py +26 -0
- zrb/builtin/project/add/fastapp_template/_zrb/venv_task.py +2 -5
- zrb/builtin/project/add/fastapp_template/common/app.py +3 -1
- zrb/builtin/project/add/fastapp_template/config.py +7 -7
- zrb/builtin/project/add/fastapp_template/module/auth/client/any_client.py +27 -0
- zrb/builtin/project/add/fastapp_template/module/auth/client/api_client.py +2 -2
- zrb/builtin/project/add/fastapp_template/module/auth/client/direct_client.py +2 -2
- zrb/builtin/project/add/fastapp_template/module/auth/client/factory.py +1 -1
- zrb/builtin/project/add/fastapp_template/module/auth/route.py +1 -1
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/factory.py +2 -2
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/{db_repository.py → user_db_repository.py} +2 -2
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/{usecase.py → user_usecase.py} +15 -8
- zrb/builtin/project/add/fastapp_template/requirements.txt +5 -6
- zrb/builtin/project/add/fastapp_template/schema/permission.py +31 -0
- zrb/builtin/project/add/fastapp_template/template.env +2 -2
- zrb/builtin/project/create/create.py +2 -2
- zrb/builtin/project/create/project-template/zrb_init.py +0 -4
- zrb/builtin/setup/{dev → asdf}/asdf.py +6 -6
- zrb/builtin/setup/{system/latex → latex}/ubuntu.py +1 -1
- zrb/builtin/setup/{dev → tmux}/tmux.py +1 -1
- zrb/builtin/setup/tmux/tmux_config.sh +12 -0
- zrb/builtin/todo.py +101 -15
- zrb/config.py +2 -2
- zrb/content_transformer/content_transformer.py +14 -2
- zrb/context/context.py +13 -10
- zrb/input/base_input.py +3 -2
- zrb/input/bool_input.py +1 -1
- zrb/input/float_input.py +1 -1
- zrb/input/int_input.py +1 -1
- zrb/input/option_input.py +1 -1
- zrb/input/password_input.py +1 -1
- zrb/input/text_input.py +1 -1
- zrb/runner/cli.py +16 -5
- zrb/runner/web_app.py +30 -18
- zrb/runner/web_controller/task_ui/controller.py +8 -6
- zrb/session/session.py +4 -1
- zrb/task/scaffolder.py +7 -9
- zrb/util/cli/style.py +7 -0
- zrb/util/codemod/add_code_to_module.py +12 -0
- zrb/util/load.py +9 -7
- zrb/util/string/conversion.py +52 -0
- zrb/util/todo.py +152 -34
- {zrb-1.0.0a10.dist-info → zrb-1.0.0a14.dist-info}/METADATA +1 -2
- {zrb-1.0.0a10.dist-info → zrb-1.0.0a14.dist-info}/RECORD +79 -55
- {zrb-1.0.0a10.dist-info → zrb-1.0.0a14.dist-info}/WHEEL +1 -1
- /zrb/builtin/project/add/fastapp_template/{module/auth/client/base_client.py → _zrb/module/module_template/client/any_client.py} +0 -0
- /zrb/builtin/{setup/dev/tmux_config.sh → project/add/fastapp_template/_zrb/module/module_template/service/__init__.py} +0 -0
- /zrb/builtin/project/add/fastapp_template/common/{db_repository.py → base_db_repository.py} +0 -0
- /zrb/builtin/project/add/fastapp_template/common/{usecase.py → base_usecase.py} +0 -0
- /zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/{repository.py → user_repository.py} +0 -0
- /zrb/builtin/setup/{dev → asdf}/asdf_helper.py +0 -0
- /zrb/builtin/setup/{dev → tmux}/tmux_helper.py +0 -0
- /zrb/builtin/setup/{system/ubuntu.py → ubuntu.py} +0 -0
- {zrb-1.0.0a10.dist-info → zrb-1.0.0a14.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
from fastapp_template._zrb.helper import (
|
2
|
+
get_existing_module_names,
|
3
|
+
get_existing_schema_names,
|
4
|
+
)
|
5
|
+
|
6
|
+
from zrb import OptionInput, StrInput
|
7
|
+
from zrb.util.string.conversion import pluralize
|
8
|
+
|
9
|
+
new_module_input = StrInput(
|
10
|
+
name="module", description="Module name", prompt="New module name"
|
11
|
+
)
|
12
|
+
|
13
|
+
existing_module_input = OptionInput(
|
14
|
+
name="module",
|
15
|
+
description="Module name",
|
16
|
+
prompt="Module name",
|
17
|
+
options=lambda _: get_existing_module_names(),
|
18
|
+
)
|
19
|
+
|
20
|
+
new_entity_input = StrInput(
|
21
|
+
name="entity", description="Entity name", prompt="New entity name"
|
22
|
+
)
|
23
|
+
|
24
|
+
existing_entity_input = OptionInput(
|
25
|
+
name="entity",
|
26
|
+
description="Entity name",
|
27
|
+
prompt="Entity name",
|
28
|
+
options=lambda _: get_existing_schema_names(),
|
29
|
+
)
|
30
|
+
|
31
|
+
plural_entity_input = StrInput(
|
32
|
+
name="plural",
|
33
|
+
description="Plural entity name",
|
34
|
+
prompt="Plural entity name",
|
35
|
+
default_str=lambda ctx: pluralize(ctx.input.entity),
|
36
|
+
)
|
37
|
+
|
38
|
+
new_entity_column_input = StrInput(
|
39
|
+
name="column",
|
40
|
+
description="Entity's column name",
|
41
|
+
prompt="New entity's column name",
|
42
|
+
default_str="name",
|
43
|
+
)
|
@@ -1,8 +1,10 @@
|
|
1
1
|
import os
|
2
2
|
|
3
|
+
from fastapp_template._zrb.column.create_column_task import create_my_app_name_column
|
3
4
|
from fastapp_template._zrb.config import ACTIVATE_VENV_SCRIPT, APP_DIR
|
5
|
+
from fastapp_template._zrb.entity.create_entity_task import create_my_app_name_entity
|
4
6
|
from fastapp_template._zrb.group import (
|
5
|
-
|
7
|
+
app_create_migration_group,
|
6
8
|
app_migrate_group,
|
7
9
|
app_run_group,
|
8
10
|
)
|
@@ -11,48 +13,55 @@ from fastapp_template._zrb.helper import (
|
|
11
13
|
migrate_module,
|
12
14
|
run_microservice,
|
13
15
|
)
|
16
|
+
from fastapp_template._zrb.module.create_module_task import create_my_app_name_module
|
14
17
|
from fastapp_template._zrb.venv_task import prepare_venv
|
15
18
|
|
16
19
|
from zrb import CmdTask, Env, EnvFile, Task
|
17
20
|
|
21
|
+
assert create_my_app_name_entity
|
22
|
+
assert create_my_app_name_module
|
23
|
+
assert create_my_app_name_column
|
24
|
+
|
18
25
|
# 🚀 Run/Migrate All ===========================================================
|
19
26
|
|
20
27
|
run_all = app_run_group.add_task(
|
21
28
|
Task(
|
22
|
-
name="run-app-name",
|
29
|
+
name="run-my-app-name",
|
30
|
+
description="🟢 Run My App Name as monolith and microservices",
|
23
31
|
),
|
24
32
|
alias="all",
|
25
33
|
)
|
26
34
|
|
27
35
|
migrate_all = app_migrate_group.add_task(
|
28
36
|
Task(
|
29
|
-
name="migrate-app-name",
|
30
|
-
description="📦 Run App Name DB migration for monolith and microservices",
|
37
|
+
name="migrate-my-app-name",
|
38
|
+
description="📦 Run My App Name DB migration for monolith and microservices",
|
31
39
|
),
|
32
40
|
alias="all",
|
33
41
|
)
|
34
42
|
|
35
|
-
create_all_migration =
|
43
|
+
create_all_migration = app_create_migration_group.add_task(
|
36
44
|
Task(
|
37
|
-
name="create-app-name-migration",
|
45
|
+
name="create-my-app-name-migration",
|
46
|
+
description="📦 Create My App Name DB migration",
|
38
47
|
),
|
39
|
-
alias="
|
48
|
+
alias="all",
|
40
49
|
)
|
41
50
|
|
42
51
|
# 🗿 Run/Migrate Monolith =====================================================
|
43
52
|
|
44
53
|
run_monolith = app_run_group.add_task(
|
45
54
|
CmdTask(
|
46
|
-
name="run-monolith-app-name",
|
47
|
-
description="🗿 Run App Name as a monolith",
|
55
|
+
name="run-monolith-my-app-name",
|
56
|
+
description="🗿 Run My App Name as a monolith",
|
48
57
|
env=[
|
49
58
|
EnvFile(path=os.path.join(APP_DIR, "template.env")),
|
50
|
-
Env(name="
|
59
|
+
Env(name="MY_APP_NAME_MODE", default="monolith"),
|
51
60
|
],
|
52
61
|
cwd=APP_DIR,
|
53
62
|
cmd=[
|
54
63
|
ACTIVATE_VENV_SCRIPT,
|
55
|
-
'fastapi dev main.py --port "${
|
64
|
+
'fastapi dev main.py --port "${MY_APP_NAME_PORT}"',
|
56
65
|
],
|
57
66
|
render_cmd=False,
|
58
67
|
retries=2,
|
@@ -63,8 +72,8 @@ prepare_venv >> run_monolith >> run_all
|
|
63
72
|
|
64
73
|
migrate_monolith = app_migrate_group.add_task(
|
65
74
|
Task(
|
66
|
-
name="migrate-monolith-app-name",
|
67
|
-
description="🗿 Run App Name DB migration for monolith",
|
75
|
+
name="migrate-monolith-my-app-name",
|
76
|
+
description="🗿 Run My App Name DB migration for monolith",
|
68
77
|
),
|
69
78
|
alias="monolith",
|
70
79
|
)
|
@@ -74,8 +83,8 @@ migrate_monolith >> migrate_all
|
|
74
83
|
|
75
84
|
run_microservices = app_run_group.add_task(
|
76
85
|
Task(
|
77
|
-
name="run-microservices-app-name",
|
78
|
-
description="🌐 Run App Name as microservices",
|
86
|
+
name="run-microservices-my-app-name",
|
87
|
+
description="🌐 Run My App Name as microservices",
|
79
88
|
),
|
80
89
|
alias="microservices",
|
81
90
|
)
|
@@ -83,8 +92,8 @@ run_microservices >> run_all
|
|
83
92
|
|
84
93
|
migrate_microservices = app_migrate_group.add_task(
|
85
94
|
Task(
|
86
|
-
name="migrate-microservices-app-name",
|
87
|
-
description="🌐 Run App Name DB migration for microservices",
|
95
|
+
name="migrate-microservices-my-app-name",
|
96
|
+
description="🌐 Run My App Name DB migration for microservices",
|
88
97
|
),
|
89
98
|
alias="microservices",
|
90
99
|
)
|
@@ -97,8 +106,8 @@ run_gateway = app_run_group.add_task(
|
|
97
106
|
)
|
98
107
|
prepare_venv >> run_gateway >> run_microservices
|
99
108
|
|
100
|
-
create_gateway_migration =
|
101
|
-
create_migration("gateway", "gateway"), alias="gateway
|
109
|
+
create_gateway_migration = app_create_migration_group.add_task(
|
110
|
+
create_migration("gateway", "gateway"), alias="gateway"
|
102
111
|
)
|
103
112
|
prepare_venv >> create_gateway_migration >> create_all_migration
|
104
113
|
|
@@ -118,8 +127,8 @@ run_auth = app_run_group.add_task(
|
|
118
127
|
)
|
119
128
|
prepare_venv >> run_auth >> run_microservices
|
120
129
|
|
121
|
-
create_auth_migration =
|
122
|
-
create_migration("auth", "auth"), alias="auth
|
130
|
+
create_auth_migration = app_create_migration_group.add_task(
|
131
|
+
create_migration("auth", "auth"), alias="auth"
|
123
132
|
)
|
124
133
|
prepare_venv >> create_auth_migration >> create_all_migration
|
125
134
|
|
@@ -0,0 +1,136 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
from fastapp_template._zrb.config import APP_DIR
|
4
|
+
from fastapp_template._zrb.group import app_create_group
|
5
|
+
from fastapp_template._zrb.helper import get_existing_module_names
|
6
|
+
from fastapp_template._zrb.input import new_module_input
|
7
|
+
|
8
|
+
from zrb import AnyContext, Scaffolder, Task, make_task
|
9
|
+
from zrb.util.string.conversion import to_kebab_case, to_pascal_case, to_snake_case
|
10
|
+
|
11
|
+
|
12
|
+
@make_task(
|
13
|
+
name="validate-create-my-app-name-module",
|
14
|
+
input=new_module_input,
|
15
|
+
retries=0,
|
16
|
+
)
|
17
|
+
async def validate_create_my_app_name_module(ctx: AnyContext):
|
18
|
+
if ctx.input.module in get_existing_module_names():
|
19
|
+
raise ValueError(f"Module already exists: {ctx.input.module}")
|
20
|
+
|
21
|
+
|
22
|
+
scaffold_my_app_name_module = Scaffolder(
|
23
|
+
name="scaffold-my-app-name-module",
|
24
|
+
input=new_module_input,
|
25
|
+
source_path=os.path.join(os.path.dirname(__file__), "module_template"),
|
26
|
+
render_source_path=False,
|
27
|
+
destination_path=lambda ctx: os.path.join(
|
28
|
+
APP_DIR,
|
29
|
+
"module",
|
30
|
+
to_snake_case(ctx.input.module),
|
31
|
+
),
|
32
|
+
transform_content={
|
33
|
+
"module_template": "{to_snake_case(ctx.input.module)}",
|
34
|
+
"MY_MODULE_NAME": "{to_snake_case(ctx.input.module).upper()}",
|
35
|
+
},
|
36
|
+
retries=0,
|
37
|
+
upstream=validate_create_my_app_name_module,
|
38
|
+
)
|
39
|
+
|
40
|
+
|
41
|
+
@make_task(
|
42
|
+
name="register-my-app-name-module-config",
|
43
|
+
input=new_module_input,
|
44
|
+
upstream=validate_create_my_app_name_module,
|
45
|
+
retries=0,
|
46
|
+
)
|
47
|
+
async def register_my_app_name_module_config(ctx: AnyContext):
|
48
|
+
"""Registering module to config.py"""
|
49
|
+
existing_module_names = get_existing_module_names()
|
50
|
+
module_port = 3000 + len(
|
51
|
+
[
|
52
|
+
module_name
|
53
|
+
for module_name in existing_module_names
|
54
|
+
if module_name != to_snake_case(ctx.input.module)
|
55
|
+
]
|
56
|
+
)
|
57
|
+
module_base_url = f"http://localhost:{module_port}"
|
58
|
+
config_file_name = os.path.join(APP_DIR, "config.py")
|
59
|
+
upper_module_name = to_snake_case(ctx.input.module).upper()
|
60
|
+
config_name = f"APP_{upper_module_name}_BASE_URL"
|
61
|
+
env_name = f"MY_APP_NAME_{upper_module_name}_BASE_URL"
|
62
|
+
# TODO: check before write
|
63
|
+
with open(config_file_name, "a") as f:
|
64
|
+
f.write(f'{config_name} = os.getenv("{env_name}", "{module_base_url}")\n')
|
65
|
+
|
66
|
+
|
67
|
+
@make_task(
|
68
|
+
name="register-my-app-name-module",
|
69
|
+
input=new_module_input,
|
70
|
+
upstream=validate_create_my_app_name_module,
|
71
|
+
retries=0,
|
72
|
+
)
|
73
|
+
async def register_my_app_name_module(ctx: AnyContext):
|
74
|
+
"""Registering module to application's main.py"""
|
75
|
+
app_main_file_name = os.path.join(APP_DIR, "main.py")
|
76
|
+
module_name = to_snake_case(ctx.input.module)
|
77
|
+
import_code = f"from fastapp_template.module.{module_name} import route as {module_name}_route" # noqa
|
78
|
+
assert_code = f"assert {module_name}_route"
|
79
|
+
with open(app_main_file_name, "r") as f:
|
80
|
+
code = f.read()
|
81
|
+
new_code = "\n".join([import_code, code.strip(), assert_code, ""])
|
82
|
+
# TODO: check before write
|
83
|
+
with open(app_main_file_name, "w") as f:
|
84
|
+
f.write(new_code)
|
85
|
+
|
86
|
+
|
87
|
+
@make_task(
|
88
|
+
name="register-my-app-name-module-runner",
|
89
|
+
input=new_module_input,
|
90
|
+
upstream=validate_create_my_app_name_module,
|
91
|
+
retries=0,
|
92
|
+
)
|
93
|
+
async def register_my_app_name_module_runner(ctx: AnyContext):
|
94
|
+
"""Registering module to _zrb's main.py"""
|
95
|
+
task_main_file_name = os.path.join(APP_DIR, "_zrb", "main.py")
|
96
|
+
existing_module_names = get_existing_module_names()
|
97
|
+
module_port = 3001 + len(
|
98
|
+
[
|
99
|
+
module_name
|
100
|
+
for module_name in existing_module_names
|
101
|
+
if module_name != to_snake_case(ctx.input.module)
|
102
|
+
]
|
103
|
+
)
|
104
|
+
module_snake_name = to_snake_case(ctx.input.module)
|
105
|
+
module_kebab_name = to_kebab_case(ctx.input.module)
|
106
|
+
module_pascal_name = to_pascal_case(ctx.input.module)
|
107
|
+
with open(os.path.join(os.path.dirname(__file__), "run_module.template.py")) as f:
|
108
|
+
module_runner_code = (
|
109
|
+
f.read()
|
110
|
+
.replace("my_module", module_snake_name)
|
111
|
+
.replace("my-module", module_kebab_name)
|
112
|
+
.replace("My Module", module_pascal_name)
|
113
|
+
.replace("3000", f"{module_port}")
|
114
|
+
)
|
115
|
+
with open(task_main_file_name, "r") as f:
|
116
|
+
code = f.read()
|
117
|
+
new_code = "\n".join([code.strip(), "", module_runner_code, ""])
|
118
|
+
# TODO: check before write
|
119
|
+
with open(task_main_file_name, "w") as f:
|
120
|
+
f.write(new_code)
|
121
|
+
|
122
|
+
|
123
|
+
create_my_app_name_module = app_create_group.add_task(
|
124
|
+
Task(
|
125
|
+
name="create-my-app-name-module",
|
126
|
+
description="🧩 Create new module on My App Name",
|
127
|
+
retries=0,
|
128
|
+
),
|
129
|
+
alias="module",
|
130
|
+
)
|
131
|
+
create_my_app_name_module << [
|
132
|
+
scaffold_my_app_name_module,
|
133
|
+
register_my_app_name_module,
|
134
|
+
register_my_app_name_module_config,
|
135
|
+
register_my_app_name_module_runner,
|
136
|
+
]
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# A generic, single database configuration.
|
2
|
+
|
3
|
+
[alembic]
|
4
|
+
# path to migration scripts
|
5
|
+
# Use forward slashes (/) also on windows to provide an os agnostic path
|
6
|
+
script_location = migration
|
7
|
+
|
8
|
+
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
9
|
+
# Uncomment the line below if you want the files to be prepended with date and time
|
10
|
+
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
|
11
|
+
# for all available tokens
|
12
|
+
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
|
13
|
+
|
14
|
+
# sys.path path, will be prepended to sys.path if present.
|
15
|
+
# defaults to the current working directory.
|
16
|
+
prepend_sys_path = ../..
|
17
|
+
|
18
|
+
# timezone to use when rendering the date within the migration file
|
19
|
+
# as well as the filename.
|
20
|
+
# If specified, requires the python>=3.9 or backports.zoneinfo library.
|
21
|
+
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
|
22
|
+
# string value is passed to ZoneInfo()
|
23
|
+
# leave blank for localtime
|
24
|
+
# timezone =
|
25
|
+
|
26
|
+
# max length of characters to apply to the "slug" field
|
27
|
+
# truncate_slug_length = 40
|
28
|
+
|
29
|
+
# set to 'true' to run the environment during
|
30
|
+
# the 'revision' command, regardless of autogenerate
|
31
|
+
# revision_environment = false
|
32
|
+
|
33
|
+
# set to 'true' to allow .pyc and .pyo files without
|
34
|
+
# a source .py file to be detected as revisions in the
|
35
|
+
# versions/ directory
|
36
|
+
# sourceless = false
|
37
|
+
|
38
|
+
# version location specification; This defaults
|
39
|
+
# to migration/versions. When using multiple version
|
40
|
+
# directories, initial revisions must be specified with --version-path.
|
41
|
+
# The path separator used here should be the separator specified by "version_path_separator" below.
|
42
|
+
# version_locations = %(here)s/bar:%(here)s/bat:migration/versions
|
43
|
+
|
44
|
+
# version path separator; As mentioned above, this is the character used to split
|
45
|
+
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
|
46
|
+
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
|
47
|
+
# Valid values for version_path_separator are:
|
48
|
+
#
|
49
|
+
# version_path_separator = :
|
50
|
+
# version_path_separator = ;
|
51
|
+
# version_path_separator = space
|
52
|
+
# version_path_separator = newline
|
53
|
+
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.
|
54
|
+
|
55
|
+
# set to 'true' to search source files recursively
|
56
|
+
# in each "version_locations" directory
|
57
|
+
# new in Alembic version 1.10
|
58
|
+
# recursive_version_locations = false
|
59
|
+
|
60
|
+
# the output encoding used when revision files
|
61
|
+
# are written from script.py.mako
|
62
|
+
# output_encoding = utf-8
|
63
|
+
|
64
|
+
sqlalchemy.url = driver://user:pass@localhost/dbname
|
65
|
+
|
66
|
+
|
67
|
+
[post_write_hooks]
|
68
|
+
# post_write_hooks defines scripts or Python functions that are run
|
69
|
+
# on newly generated revision scripts. See the documentation for further
|
70
|
+
# detail and examples
|
71
|
+
|
72
|
+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
|
73
|
+
# hooks = black
|
74
|
+
# black.type = console_scripts
|
75
|
+
# black.entrypoint = black
|
76
|
+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
|
77
|
+
|
78
|
+
# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
|
79
|
+
# hooks = ruff
|
80
|
+
# ruff.type = exec
|
81
|
+
# ruff.executable = %(here)s/.venv/bin/ruff
|
82
|
+
# ruff.options = --fix REVISION_SCRIPT_FILENAME
|
83
|
+
|
84
|
+
# Logging configuration
|
85
|
+
[loggers]
|
86
|
+
keys = root,sqlalchemy,alembic
|
87
|
+
|
88
|
+
[handlers]
|
89
|
+
keys = console
|
90
|
+
|
91
|
+
[formatters]
|
92
|
+
keys = generic
|
93
|
+
|
94
|
+
[logger_root]
|
95
|
+
level = WARNING
|
96
|
+
handlers = console
|
97
|
+
qualname =
|
98
|
+
|
99
|
+
[logger_sqlalchemy]
|
100
|
+
level = WARNING
|
101
|
+
handlers =
|
102
|
+
qualname = sqlalchemy.engine
|
103
|
+
|
104
|
+
[logger_alembic]
|
105
|
+
level = INFO
|
106
|
+
handlers =
|
107
|
+
qualname = alembic
|
108
|
+
|
109
|
+
[handler_console]
|
110
|
+
class = StreamHandler
|
111
|
+
args = (sys.stderr,)
|
112
|
+
level = NOTSET
|
113
|
+
formatter = generic
|
114
|
+
|
115
|
+
[formatter_generic]
|
116
|
+
format = %(levelname)-5.5s [%(name)s] %(message)s
|
117
|
+
datefmt = %H:%M:%S
|
@@ -0,0 +1,9 @@
|
|
1
|
+
from fastapp_template.config import APP_COMMUNICATION
|
2
|
+
from fastapp_template.module.module_template.client.any_client import BaseClient
|
3
|
+
from fastapp_template.module.module_template.client.api_client import APIClient
|
4
|
+
from fastapp_template.module.module_template.client.direct_client import DirectClient
|
5
|
+
|
6
|
+
if APP_COMMUNICATION == "direct":
|
7
|
+
client: BaseClient = DirectClient()
|
8
|
+
elif APP_COMMUNICATION == "api":
|
9
|
+
client: BaseClient = APIClient()
|
@@ -0,0 +1 @@
|
|
1
|
+
Generic single-database configuration.
|
@@ -0,0 +1,108 @@
|
|
1
|
+
from logging.config import fileConfig
|
2
|
+
|
3
|
+
from alembic import context
|
4
|
+
from fastapp_template.config import APP_DB_URL
|
5
|
+
from fastapp_template.module.my_module.migration_metadata import metadata
|
6
|
+
from sqlalchemy import engine_from_config, pool
|
7
|
+
|
8
|
+
# this is the Alembic Config object, which provides
|
9
|
+
# access to the values within the .ini file in use.
|
10
|
+
config = context.config
|
11
|
+
|
12
|
+
# 🔥 FastApp Modification
|
13
|
+
MIGRATION_TABLE = "_migration_my_module"
|
14
|
+
# 🔥 FastApp Modification
|
15
|
+
config.set_section_option(config.config_ini_section, "sqlalchemy.url", APP_DB_URL)
|
16
|
+
|
17
|
+
# Interpret the config file for Python logging.
|
18
|
+
# This line sets up loggers basically.
|
19
|
+
if config.config_file_name is not None:
|
20
|
+
fileConfig(config.config_file_name)
|
21
|
+
|
22
|
+
# add your model's MetaData object here
|
23
|
+
# for 'autogenerate' support
|
24
|
+
# from myapp import mymodel
|
25
|
+
# target_metadata = mymodel.Base.metadata
|
26
|
+
target_metadata = metadata
|
27
|
+
|
28
|
+
# other values from the config, defined by the needs of env.py,
|
29
|
+
# can be acquired:
|
30
|
+
# my_important_option = config.get_main_option("my_important_option")
|
31
|
+
# ... etc.
|
32
|
+
|
33
|
+
|
34
|
+
# 🔥 FastApp Modification
|
35
|
+
def include_object(object, name, type_, reflected, compare_to):
|
36
|
+
"""
|
37
|
+
Filter which objects Alembic should include in migrations.
|
38
|
+
Args:
|
39
|
+
object: The SQLAlchemy object (table, column, etc.)
|
40
|
+
name: The name of the object
|
41
|
+
type_: The type of the object ("table", "column", etc.)
|
42
|
+
reflected: True if the object is reflected from the database
|
43
|
+
compare_to: The object being compared against
|
44
|
+
Returns:
|
45
|
+
bool: True to include, False to exclude
|
46
|
+
"""
|
47
|
+
# Exclude tables not in metadata
|
48
|
+
if type_ == "table" and name not in target_metadata.tables:
|
49
|
+
return False # Skip this table
|
50
|
+
return True
|
51
|
+
|
52
|
+
|
53
|
+
def run_migrations_offline() -> None:
|
54
|
+
"""Run migrations in 'offline' mode.
|
55
|
+
|
56
|
+
This configures the context with just a URL
|
57
|
+
and not an Engine, though an Engine is acceptable
|
58
|
+
here as well. By skipping the Engine creation
|
59
|
+
we don't even need a DBAPI to be available.
|
60
|
+
|
61
|
+
Calls to context.execute() here emit the given string to the
|
62
|
+
script output.
|
63
|
+
|
64
|
+
"""
|
65
|
+
url = config.get_main_option("sqlalchemy.url")
|
66
|
+
context.configure(
|
67
|
+
url=url,
|
68
|
+
target_metadata=target_metadata,
|
69
|
+
literal_binds=True,
|
70
|
+
dialect_opts={"paramstyle": "named"},
|
71
|
+
imports=["import sqlmodel"], # 🔥 FastApp Modification
|
72
|
+
version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
|
73
|
+
include_object=include_object, # 🔥 FastApp Modification
|
74
|
+
)
|
75
|
+
|
76
|
+
with context.begin_transaction():
|
77
|
+
context.run_migrations()
|
78
|
+
|
79
|
+
|
80
|
+
def run_migrations_online() -> None:
|
81
|
+
"""Run migrations in 'online' mode.
|
82
|
+
|
83
|
+
In this scenario we need to create an Engine
|
84
|
+
and associate a connection with the context.
|
85
|
+
|
86
|
+
"""
|
87
|
+
connectable = engine_from_config(
|
88
|
+
config.get_section(config.config_ini_section, {}),
|
89
|
+
prefix="sqlalchemy.",
|
90
|
+
poolclass=pool.NullPool,
|
91
|
+
)
|
92
|
+
|
93
|
+
with connectable.connect() as connection:
|
94
|
+
context.configure(
|
95
|
+
connection=connection,
|
96
|
+
target_metadata=target_metadata,
|
97
|
+
imports=["import sqlmodel"], # 🔥 FastApp Modification
|
98
|
+
version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
|
99
|
+
include_object=include_object, # 🔥 FastApp Modification
|
100
|
+
)
|
101
|
+
with context.begin_transaction():
|
102
|
+
context.run_migrations()
|
103
|
+
|
104
|
+
|
105
|
+
if context.is_offline_mode():
|
106
|
+
run_migrations_offline()
|
107
|
+
else:
|
108
|
+
run_migrations_online()
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"""${message}
|
2
|
+
|
3
|
+
Revision ID: ${up_revision}
|
4
|
+
Revises: ${down_revision | comma,n}
|
5
|
+
Create Date: ${create_date}
|
6
|
+
|
7
|
+
"""
|
8
|
+
from typing import Sequence, Union
|
9
|
+
|
10
|
+
from alembic import op
|
11
|
+
import sqlalchemy as sa
|
12
|
+
${imports if imports else ""}
|
13
|
+
|
14
|
+
# revision identifiers, used by Alembic.
|
15
|
+
revision: str = ${repr(up_revision)}
|
16
|
+
down_revision: Union[str, None] = ${repr(down_revision)}
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
18
|
+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
19
|
+
|
20
|
+
|
21
|
+
def upgrade() -> None:
|
22
|
+
${upgrades if upgrades else "pass"}
|
23
|
+
|
24
|
+
|
25
|
+
def downgrade() -> None:
|
26
|
+
${downgrades if downgrades else "pass"}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
"""Add user table
|
2
|
+
|
3
|
+
Revision ID: 3093c7336477
|
4
|
+
Revises:
|
5
|
+
Create Date: 2024-11-20 05:57:01.684118
|
6
|
+
|
7
|
+
"""
|
8
|
+
|
9
|
+
from typing import Sequence, Union
|
10
|
+
|
11
|
+
import sqlalchemy as sa
|
12
|
+
import sqlmodel
|
13
|
+
from alembic import op
|
14
|
+
|
15
|
+
# revision identifiers, used by Alembic.
|
16
|
+
revision: str = "3093c7336477"
|
17
|
+
down_revision: Union[str, None] = None
|
18
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
19
|
+
depends_on: Union[str, Sequence[str], None] = None
|
20
|
+
|
21
|
+
|
22
|
+
def upgrade() -> None:
|
23
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
24
|
+
op.create_table(
|
25
|
+
"user",
|
26
|
+
sa.Column("id", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
27
|
+
sa.Column("username", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
28
|
+
sa.Column("password", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
29
|
+
sa.PrimaryKeyConstraint("id"),
|
30
|
+
)
|
31
|
+
# ### end Alembic commands ###
|
32
|
+
|
33
|
+
|
34
|
+
def downgrade() -> None:
|
35
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
36
|
+
op.drop_table("user")
|
37
|
+
# ### end Alembic commands ###
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from fastapp_template.common.app import app
|
2
|
+
from fastapp_template.common.schema import BasicResponse
|
3
|
+
from fastapp_template.config import APP_MODE, APP_MODULES
|
4
|
+
|
5
|
+
if APP_MODE == "microservices" and "auth" in APP_MODULES:
|
6
|
+
|
7
|
+
if APP_MODE == "microservices" and (
|
8
|
+
len(APP_MODULES) > 0 and APP_MODULES[0] == "auth"
|
9
|
+
):
|
10
|
+
|
11
|
+
@app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
|
12
|
+
async def health():
|
13
|
+
return BasicResponse(message="ok")
|
14
|
+
|
15
|
+
@app.api_route(
|
16
|
+
"/readiness", methods=["GET", "HEAD"], response_model=BasicResponse
|
17
|
+
)
|
18
|
+
async def readiness():
|
19
|
+
return BasicResponse(message="ok")
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# 🔐 Run/Migrate My Module ==========================================================
|
2
|
+
|
3
|
+
run_my_module = app_run_group.add_task(
|
4
|
+
run_microservice("my-module", 3000, "my_module"), alias="microservices-my_module"
|
5
|
+
)
|
6
|
+
prepare_venv >> run_my_module >> run_microservices
|
7
|
+
|
8
|
+
create_my_module_migration = app_create_migration_group.add_task(
|
9
|
+
create_migration("my-module", "my_module"), alias="my_module"
|
10
|
+
)
|
11
|
+
prepare_venv >> create_my_module_migration >> create_all_migration
|
12
|
+
|
13
|
+
migrate_monolith_my_module = migrate_module(
|
14
|
+
"my_module", "my_module", as_microservices=False
|
15
|
+
)
|
16
|
+
prepare_venv >> migrate_monolith_my_module >> [migrate_monolith, run_monolith]
|
17
|
+
|
18
|
+
migrate_microservices_my_module = app_migrate_group.add_task(
|
19
|
+
migrate_module("my-module", "my_module", as_microservices=True),
|
20
|
+
alias="microservices-my-module",
|
21
|
+
)
|
22
|
+
(
|
23
|
+
prepare_venv
|
24
|
+
>> migrate_microservices_my_module
|
25
|
+
>> [migrate_microservices, run_my_module]
|
26
|
+
)
|