diff --git a/README.md b/README.md index 681d13c867..7c9a5f4a84 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,12 @@ After using this generator, your new project (the directory created) will contai * Update development scripts. +* Read Alembic configs from env vars. PR #9 by @ebreton. + +* Create DB Item objects from all Pydantic model's fields. + +* Update Jupyter Lab installation and util script/environment variable for local development. + ### 0.3.0 * PR #14: @@ -163,7 +169,7 @@ After using this generator, your new project (the directory created) will contai * Update migrations to include new Items. * Update project README.md with tips about how to start with backend. -* Upgrade Python to 3.7 as Celery is now compatible too. PR #10 by @ebreton. +* Upgrade Python to 3.7 as Celery is now compatible too. PR #10 by @ebreton. ### 0.2.2 diff --git a/{{cookiecutter.project_slug}}/backend/app/alembic.ini b/{{cookiecutter.project_slug}}/backend/app/alembic.ini index 61bc2fdcbf..921aaf17b8 100755 --- a/{{cookiecutter.project_slug}}/backend/app/alembic.ini +++ b/{{cookiecutter.project_slug}}/backend/app/alembic.ini @@ -35,9 +35,6 @@ script_location = alembic # are written from script.py.mako # output_encoding = utf-8 -sqlalchemy.url = postgresql://postgres:{{cookiecutter.postgres_password}}@db/app - - # Logging configuration [loggers] keys = root,sqlalchemy,alembic diff --git a/{{cookiecutter.project_slug}}/backend/app/alembic/env.py b/{{cookiecutter.project_slug}}/backend/app/alembic/env.py index ae47ee586c..df37198286 100755 --- a/{{cookiecutter.project_slug}}/backend/app/alembic/env.py +++ b/{{cookiecutter.project_slug}}/backend/app/alembic/env.py @@ -1,4 +1,7 @@ from __future__ import with_statement + +import os + from alembic import context from sqlalchemy import engine_from_config, pool from logging.config import fileConfig @@ -27,6 +30,14 @@ # ... etc. +def get_url(): + user = os.getenv("POSTGRES_USER", "postgres") + password = os.getenv("POSTGRES_PASSWORD", "") + server = os.getenv("POSTGRES_SERVER", "db") + db = os.getenv("POSTGRES_DB", "app") + return f"postgresql://{user}:{password}@{server}/{db}" + + def run_migrations_offline(): """Run migrations in 'offline' mode. @@ -39,7 +50,7 @@ def run_migrations_offline(): script output. """ - url = config.get_main_option("sqlalchemy.url") + url = get_url() context.configure( url=url, target_metadata=target_metadata, literal_binds=True, compare_type=True ) @@ -55,8 +66,10 @@ def run_migrations_online(): and associate a connection with the context. """ + configuration = config.get_section(config.config_ini_section) + configuration['sqlalchemy.url'] = get_url() connectable = engine_from_config( - config.get_section(config.config_ini_section), + configuration, prefix="sqlalchemy.", poolclass=pool.NullPool, ) diff --git a/{{cookiecutter.project_slug}}/backend/app/app/crud/item.py b/{{cookiecutter.project_slug}}/backend/app/app/crud/item.py index 4d92b041ca..9cec459f54 100644 --- a/{{cookiecutter.project_slug}}/backend/app/app/crud/item.py +++ b/{{cookiecutter.project_slug}}/backend/app/app/crud/item.py @@ -28,7 +28,8 @@ def get_multi_by_owner( def create(db_session: Session, *, item_in: ItemCreate, owner_id: int) -> Item: - item = Item(title=item_in.title, description=item_in.description, owner_id=owner_id) + item_in_data = jsonable_encoder(item_in) + item = Item(**item_in_data, owner_id=owner_id) db_session.add(item) db_session.commit() db_session.refresh(item) diff --git a/{{cookiecutter.project_slug}}/backend/backend.dockerfile b/{{cookiecutter.project_slug}}/backend/backend.dockerfile index 60fd3b3018..d30f17d58e 100644 --- a/{{cookiecutter.project_slug}}/backend/backend.dockerfile +++ b/{{cookiecutter.project_slug}}/backend/backend.dockerfile @@ -4,9 +4,9 @@ RUN pip install celery~=4.3 passlib[bcrypt] tenacity requests emails "fastapi>=0 # For development, Jupyter remote kernel, Hydrogen # Using inside the container: -# jupyter notebook --ip=0.0.0.0 --allow-root +# jupyter lab --ip=0.0.0.0 --allow-root --NotebookApp.custom_display_url=http://127.0.0.1:8888 ARG env=prod -RUN bash -c "if [ $env == 'dev' ] ; then pip install jupyter ; fi" +RUN bash -c "if [ $env == 'dev' ] ; then pip install jupyterlab ; fi" EXPOSE 8888 COPY ./app /app diff --git a/{{cookiecutter.project_slug}}/backend/celeryworker.dockerfile b/{{cookiecutter.project_slug}}/backend/celeryworker.dockerfile index b0d5497c10..e2ac4a8881 100644 --- a/{{cookiecutter.project_slug}}/backend/celeryworker.dockerfile +++ b/{{cookiecutter.project_slug}}/backend/celeryworker.dockerfile @@ -4,9 +4,9 @@ RUN pip install raven celery~=4.3 passlib[bcrypt] tenacity requests "fastapi>=0. # For development, Jupyter remote kernel, Hydrogen # Using inside the container: -# jupyter notebook --ip=0.0.0.0 --allow-root +# jupyter lab --ip=0.0.0.0 --allow-root --NotebookApp.custom_display_url=http://127.0.0.1:8888 ARG env=prod -RUN bash -c "if [ $env == 'dev' ] ; then pip install jupyter ; fi" +RUN bash -c "if [ $env == 'dev' ] ; then pip install jupyterlab ; fi" EXPOSE 8888 ENV C_FORCE_ROOT=1 diff --git a/{{cookiecutter.project_slug}}/backend/tests.dockerfile b/{{cookiecutter.project_slug}}/backend/tests.dockerfile index 55d7036481..838dfcc7a9 100644 --- a/{{cookiecutter.project_slug}}/backend/tests.dockerfile +++ b/{{cookiecutter.project_slug}}/backend/tests.dockerfile @@ -4,9 +4,9 @@ RUN pip install requests pytest tenacity passlib[bcrypt] "fastapi>=0.16.0" psyco # For development, Jupyter remote kernel, Hydrogen # Using inside the container: -# jupyter notebook --ip=0.0.0.0 --allow-root +# jupyter lab --ip=0.0.0.0 --allow-root --NotebookApp.custom_display_url=http://127.0.0.1:8888 ARG env=prod -RUN bash -c "if [ $env == 'dev' ] ; then pip install jupyter ; fi" +RUN bash -c "if [ $env == 'dev' ] ; then pip install jupyterlab ; fi" EXPOSE 8888 COPY ./app /app diff --git a/{{cookiecutter.project_slug}}/docker-compose.dev.env.yml b/{{cookiecutter.project_slug}}/docker-compose.dev.env.yml index 9118b25ab7..39b024849d 100644 --- a/{{cookiecutter.project_slug}}/docker-compose.dev.env.yml +++ b/{{cookiecutter.project_slug}}/docker-compose.dev.env.yml @@ -2,13 +2,13 @@ version: '3.3' services: backend: environment: - - 'JUPYTER=jupyter notebook --ip=0.0.0.0 --allow-root' + - JUPYTER=jupyter lab --ip=0.0.0.0 --allow-root --NotebookApp.custom_display_url=http://127.0.0.1:8888 - SERVER_HOST=http://${DOMAIN} celeryworker: environment: - RUN=celery worker -A app.worker -l info -Q main-queue -c 1 - - JUPYTER=jupyter notebook --ip=0.0.0.0 --allow-root + - JUPYTER=jupyter lab --ip=0.0.0.0 --allow-root --NotebookApp.custom_display_url=http://127.0.0.1:8888 - SERVER_HOST=http://${DOMAIN} backend-tests: environment: - - JUPYTER=jupyter notebook --ip=0.0.0.0 --allow-root + - JUPYTER=jupyter lab --ip=0.0.0.0 --allow-root --NotebookApp.custom_display_url=http://127.0.0.1:8888