-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b6e3b4
commit 8c46d73
Showing
16 changed files
with
500 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ lib/ | |
|
||
# Hatch version | ||
_version.py | ||
*.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# A generic, single database configuration. | ||
|
||
[alembic] | ||
script_location = {alembic_dir} | ||
sqlalchemy.url = {db_url} | ||
|
||
# template used to generate migration files | ||
# file_template = %%(rev)s_%%(slug)s | ||
|
||
# max length of characters to apply to the | ||
# "slug" field | ||
#truncate_slug_length = 40 | ||
|
||
# set to 'true' to run the environment during | ||
# the 'revision' command, regardless of autogenerate | ||
# revision_environment = false | ||
|
||
# set to 'true' to allow .pyc and .pyo files without | ||
# a source .py file to be detected as revisions in the | ||
# versions/ directory | ||
# sourceless = false | ||
|
||
# version location specification; this defaults | ||
# to jupyterhub/alembic/versions. When using multiple version | ||
# directories, initial revisions must be specified with --version-path | ||
# version_locations = %(here)s/bar %(here)s/bat jupyterhub/alembic/versions | ||
|
||
# the output encoding used when revision files | ||
# are written from script.py.mako | ||
# output_encoding = utf-8 | ||
|
||
|
||
# Logging configuration | ||
[loggers] | ||
keys = root,sqlalchemy,alembic | ||
|
||
[handlers] | ||
keys = console | ||
|
||
[formatters] | ||
keys = generic | ||
|
||
[logger_root] | ||
level = WARN | ||
handlers = console | ||
qualname = | ||
|
||
[logger_sqlalchemy] | ||
level = WARN | ||
handlers = | ||
qualname = sqlalchemy.engine | ||
|
||
[logger_alembic] | ||
level = INFO | ||
handlers = | ||
qualname = alembic | ||
|
||
[handler_console] | ||
class = StreamHandler | ||
args = (sys.stderr,) | ||
level = NOTSET | ||
formatter = generic | ||
|
||
[formatter_generic] | ||
format = %(levelname)-5.5s [%(name)s] %(message)s | ||
datefmt = %H:%M:%S |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import asyncio | ||
import logging | ||
from logging.config import fileConfig | ||
|
||
import alembic | ||
from sqlalchemy import engine_from_config, pool | ||
from sqlalchemy.ext.asyncio import AsyncEngine | ||
|
||
# Alembic Config object, which provides access to values within the .ini file | ||
config = alembic.context.config | ||
|
||
# Interpret the config file for logging | ||
fileConfig(config.config_file_name) | ||
logger = logging.getLogger("alembic.env") | ||
|
||
|
||
def run_migrations_online() -> None: | ||
""" | ||
Run migrations in 'online' mode | ||
""" | ||
connectable = config.attributes.get("connection", None) | ||
|
||
if connectable is None: | ||
connectable = AsyncEngine( | ||
engine_from_config( | ||
config.get_section(config.config_ini_section), | ||
prefix="sqlalchemy.", | ||
poolclass=pool.NullPool, | ||
) | ||
) | ||
|
||
if isinstance(connectable, AsyncEngine): | ||
asyncio.run(run_async_migrations(connectable)) | ||
else: | ||
do_run_migrations(connectable) | ||
|
||
|
||
def do_run_migrations(connection): | ||
alembic.context.configure(connection=connection, target_metadata=None) | ||
with alembic.context.begin_transaction(): | ||
alembic.context.run_migrations() | ||
|
||
|
||
async def run_async_migrations(connectable): | ||
async with connectable.connect() as connection: | ||
await connection.run_sync(do_run_migrations) | ||
await connectable.dispose() | ||
|
||
|
||
def run_migrations_offline() -> None: | ||
""" | ||
Run migrations in 'offline' mode. | ||
""" | ||
alembic.context.configure(url=config.get_main_option("sqlalchemy.url")) | ||
|
||
with alembic.context.begin_transaction(): | ||
alembic.context.run_migrations() | ||
|
||
|
||
if alembic.context.is_offline_mode(): | ||
logger.info("Running migrations offline") | ||
run_migrations_offline() | ||
else: | ||
logger.info("Running migrations online") | ||
run_migrations_online() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""${message} | ||
|
||
Revision ID: ${up_revision} | ||
Revises: ${down_revision | comma,n} | ||
Create Date: ${create_date} | ||
|
||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = ${repr(up_revision)} | ||
down_revision = ${repr(down_revision)} | ||
branch_labels = ${repr(branch_labels)} | ||
depends_on = ${repr(depends_on)} | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
${imports if imports else ""} | ||
|
||
def upgrade(): | ||
${upgrades if upgrades else "pass"} | ||
|
||
|
||
def downgrade(): | ||
${downgrades if downgrades else "pass"} |
30 changes: 30 additions & 0 deletions
30
tljh_repo2docker/alembic/versions/ac1b4e7e52f3_first_migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""First migration | ||
Revision ID: ac1b4e7e52f3 | ||
Revises: | ||
Create Date: 2024-04-05 16:25:18.246631 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "ac1b4e7e52f3" | ||
down_revision = None | ||
branch_labels = None | ||
depends_on = None | ||
|
||
import sqlalchemy as sa # noqa | ||
from alembic import op # noqa | ||
from jupyterhub.orm import JSONDict # noqa | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
"images", | ||
sa.Column("uid", sa.Unicode(36)), | ||
sa.Column("name", sa.Unicode(4096)), | ||
sa.Column("metadata", JSONDict, nullable=True), | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table("images") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.