···11+# A generic, single database configuration.
22+33+[alembic]
44+# path to migration scripts
55+script_location = kefi/migrations
66+77+# template used to generate migration files
88+# file_template = %%(rev)s_%%(slug)s
99+1010+# sys.path path, will be prepended to sys.path if present.
1111+# defaults to the current working directory.
1212+prepend_sys_path = .
1313+1414+# timezone to use when rendering the date within the migration file
1515+# as well as the filename.
1616+# If specified, requires the python-dateutil library that can be
1717+# installed by adding `alembic[tz]` to the pip requirements
1818+# string value is passed to dateutil.tz.gettz()
1919+# leave blank for localtime
2020+# timezone =
2121+2222+# max length of characters to apply to the
2323+# "slug" field
2424+# truncate_slug_length = 40
2525+2626+# set to 'true' to run the environment during
2727+# the 'revision' command, regardless of autogenerate
2828+# revision_environment = false
2929+3030+# set to 'true' to allow .pyc and .pyo files without
3131+# a source .py file to be detected as revisions in the
3232+# versions/ directory
3333+# sourceless = false
3434+3535+# version location specification; This defaults
3636+# to alembic/versions. When using multiple version
3737+# directories, initial revisions must be specified with --version-path.
3838+# The path separator used here should be the separator specified by "version_path_separator"
3939+# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions
4040+4141+# version path separator; As mentioned above, this is the character used to split
4242+# version_locations. Valid values are:
4343+#
4444+# version_path_separator = :
4545+# version_path_separator = ;
4646+# version_path_separator = space
4747+version_path_separator = os # default: use os.pathsep
4848+4949+# the output encoding used when revision files
5050+# are written from script.py.mako
5151+# output_encoding = utf-8
5252+5353+sqlalchemy.url = driver://user:pass@localhost/dbname
5454+5555+5656+[post_write_hooks]
5757+# post_write_hooks defines scripts or Python functions that are run
5858+# on newly generated revision scripts. See the documentation for further
5959+# detail and examples
6060+6161+# format using "black" - use the console_scripts runner, against the "black" entrypoint
6262+# hooks = black
6363+# black.type = console_scripts
6464+# black.entrypoint = black
6565+# black.options = -l 79 REVISION_SCRIPT_FILENAME
6666+6767+# Logging configuration
6868+[loggers]
6969+keys = root,sqlalchemy,alembic
7070+7171+[handlers]
7272+keys = console
7373+7474+[formatters]
7575+keys = generic
7676+7777+[logger_root]
7878+level = WARN
7979+handlers = console
8080+qualname =
8181+8282+[logger_sqlalchemy]
8383+level = WARN
8484+handlers =
8585+qualname = sqlalchemy.engine
8686+8787+[logger_alembic]
8888+level = INFO
8989+handlers =
9090+qualname = alembic
9191+9292+[handler_console]
9393+class = StreamHandler
9494+args = (sys.stderr,)
9595+level = NOTSET
9696+formatter = generic
9797+9898+[formatter_generic]
9999+format = %(levelname)-5.5s [%(name)s] %(message)s
100100+datefmt = %H:%M:%S
+24
docker-compose.yml
···11+# Docker-compose file to launch in the local machine all the services that
22+# the project needs to run.
33+version: '3'
44+55+volumes:
66+ postgres_data: {}
77+ postgres_data_backups: {}
88+99+services:
1010+1111+ postgres:
1212+ image: registry.dekaside.com/library/postgres:12
1313+ volumes:
1414+ - postgres_data:/var/lib/postgresql/data
1515+ - postgres_data_backups:/backups
1616+ env_file:
1717+ - ./.env
1818+ ports:
1919+ - "5432:5432"
2020+2121+ redis:
2222+ image: redis:latest
2323+ ports:
2424+ - "6379:6379"
···11+from logging.config import fileConfig
22+33+from alembic import context
44+from sqlalchemy import engine_from_config, pool
55+66+# this is the Alembic Config object, which provides
77+# access to the values within the .ini file in use.
88+config = context.config
99+1010+# Interpret the config file for Python logging.
1111+# This line sets up loggers basically.
1212+fileConfig(config.config_file_name)
1313+1414+1515+# add your model's MetaData object here
1616+from sqlmodel import SQLModel
1717+1818+from kefi.config import settings
1919+from kefi.models.users import User
2020+2121+if settings.IS_TEST:
2222+ config.set_main_option(
2323+ "sqlalchemy.url", f"{settings.DATABASE_URL}{settings.DATABASE_TEST_SUFFIX}"
2424+ )
2525+else:
2626+ config.set_main_option("sqlalchemy.url", f"{settings.DATABASE_URL}")
2727+target_metadata = SQLModel.metadata
2828+2929+# other values from the config, defined by the needs of env.py,
3030+# can be acquired:
3131+# my_important_option = config.get_main_option("my_important_option")
3232+# ... etc.
3333+3434+3535+def run_migrations_offline():
3636+ """Run migrations in 'offline' mode.
3737+3838+ This configures the context with just a URL
3939+ and not an Engine, though an Engine is acceptable
4040+ here as well. By skipping the Engine creation
4141+ we don't even need a DBAPI to be available.
4242+4343+ Calls to context.execute() here emit the given string to the
4444+ script output.
4545+4646+ """
4747+ url = config.get_main_option("sqlalchemy.url")
4848+ context.configure(
4949+ url=url,
5050+ target_metadata=target_metadata,
5151+ literal_binds=True,
5252+ dialect_opts={"paramstyle": "named"},
5353+ )
5454+5555+ with context.begin_transaction():
5656+ context.run_migrations()
5757+5858+5959+def run_migrations_online():
6060+ """Run migrations in 'online' mode.
6161+6262+ In this scenario we need to create an Engine
6363+ and associate a connection with the context.
6464+6565+ """
6666+ connectable = engine_from_config(
6767+ config.get_section(config.config_ini_section),
6868+ prefix="sqlalchemy.",
6969+ poolclass=pool.NullPool,
7070+ )
7171+7272+ with connectable.connect() as connection:
7373+ context.configure(connection=connection, target_metadata=target_metadata)
7474+7575+ with context.begin_transaction():
7676+ context.run_migrations()
7777+7878+7979+if context.is_offline_mode():
8080+ run_migrations_offline()
8181+else:
8282+ run_migrations_online()
+25
kefi/migrations/script.py.mako
···11+"""${message}
22+33+Revision ID: ${up_revision}
44+Revises: ${down_revision | comma,n}
55+Create Date: ${create_date}
66+77+"""
88+from alembic import op
99+import sqlalchemy as sa
1010+import sqlmodel
1111+${imports if imports else ""}
1212+1313+# revision identifiers, used by Alembic.
1414+revision = ${repr(up_revision)}
1515+down_revision = ${repr(down_revision)}
1616+branch_labels = ${repr(branch_labels)}
1717+depends_on = ${repr(depends_on)}
1818+1919+2020+def upgrade():
2121+ ${upgrades if upgrades else "pass"}
2222+2323+2424+def downgrade():
2525+ ${downgrades if downgrades else "pass"}