Spaces:
Running
on
Zero
Running
on
Zero
Delete alembic_db
Browse files- alembic_db/README.md +0 -4
- alembic_db/env.py +0 -64
- alembic_db/script.py.mako +0 -28
alembic_db/README.md
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
## Generate new revision
|
2 |
-
|
3 |
-
1. Update models in `/app/database/models.py`
|
4 |
-
2. Run `alembic revision --autogenerate -m "{your message}"`
|
|
|
|
|
|
|
|
|
|
alembic_db/env.py
DELETED
@@ -1,64 +0,0 @@
|
|
1 |
-
from sqlalchemy import engine_from_config
|
2 |
-
from sqlalchemy import pool
|
3 |
-
|
4 |
-
from alembic import context
|
5 |
-
|
6 |
-
# this is the Alembic Config object, which provides
|
7 |
-
# access to the values within the .ini file in use.
|
8 |
-
config = context.config
|
9 |
-
|
10 |
-
|
11 |
-
from app.database.models import Base
|
12 |
-
target_metadata = Base.metadata
|
13 |
-
|
14 |
-
# other values from the config, defined by the needs of env.py,
|
15 |
-
# can be acquired:
|
16 |
-
# my_important_option = config.get_main_option("my_important_option")
|
17 |
-
# ... etc.
|
18 |
-
|
19 |
-
|
20 |
-
def run_migrations_offline() -> None:
|
21 |
-
"""Run migrations in 'offline' mode.
|
22 |
-
This configures the context with just a URL
|
23 |
-
and not an Engine, though an Engine is acceptable
|
24 |
-
here as well. By skipping the Engine creation
|
25 |
-
we don't even need a DBAPI to be available.
|
26 |
-
Calls to context.execute() here emit the given string to the
|
27 |
-
script output.
|
28 |
-
"""
|
29 |
-
url = config.get_main_option("sqlalchemy.url")
|
30 |
-
context.configure(
|
31 |
-
url=url,
|
32 |
-
target_metadata=target_metadata,
|
33 |
-
literal_binds=True,
|
34 |
-
dialect_opts={"paramstyle": "named"},
|
35 |
-
)
|
36 |
-
|
37 |
-
with context.begin_transaction():
|
38 |
-
context.run_migrations()
|
39 |
-
|
40 |
-
|
41 |
-
def run_migrations_online() -> None:
|
42 |
-
"""Run migrations in 'online' mode.
|
43 |
-
In this scenario we need to create an Engine
|
44 |
-
and associate a connection with the context.
|
45 |
-
"""
|
46 |
-
connectable = engine_from_config(
|
47 |
-
config.get_section(config.config_ini_section, {}),
|
48 |
-
prefix="sqlalchemy.",
|
49 |
-
poolclass=pool.NullPool,
|
50 |
-
)
|
51 |
-
|
52 |
-
with connectable.connect() as connection:
|
53 |
-
context.configure(
|
54 |
-
connection=connection, target_metadata=target_metadata
|
55 |
-
)
|
56 |
-
|
57 |
-
with context.begin_transaction():
|
58 |
-
context.run_migrations()
|
59 |
-
|
60 |
-
|
61 |
-
if context.is_offline_mode():
|
62 |
-
run_migrations_offline()
|
63 |
-
else:
|
64 |
-
run_migrations_online()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alembic_db/script.py.mako
DELETED
@@ -1,28 +0,0 @@
|
|
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 |
-
"""Upgrade schema."""
|
23 |
-
${upgrades if upgrades else "pass"}
|
24 |
-
|
25 |
-
|
26 |
-
def downgrade() -> None:
|
27 |
-
"""Downgrade schema."""
|
28 |
-
${downgrades if downgrades else "pass"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|