Skip to content

Commit fae0d2e

Browse files
committed
app_less_69_new 3x
1 parent 2980b91 commit fae0d2e

File tree

9 files changed

+80
-9
lines changed

9 files changed

+80
-9
lines changed

Diff for: app_less_69_new/alembic.ini renamed to alembic.ini

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[alembic]
44
# path to migration scripts
55
# Use forward slashes (/) also on windows to provide an os agnostic path
6-
script_location = alembic
6+
script_location = app_less_69_new/migrations
77

88
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
99
# Uncomment the line below if you want the files to be prepended with date and time
@@ -36,10 +36,10 @@ prepend_sys_path = .
3636
# sourceless = false
3737

3838
# version location specification; This defaults
39-
# to alembic/versions. When using multiple version
39+
# to app_less_69_new/migrations/versions. When using multiple version
4040
# directories, initial revisions must be specified with --version-path.
4141
# The path separator used here should be the separator specified by "version_path_separator" below.
42-
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions
42+
# version_locations = %(here)s/bar:%(here)s/bat:app_less_69_new/migrations/versions
4343

4444
# version path separator; As mentioned above, this is the character used to split
4545
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.

Diff for: app_less_68_new/backends/bd_dependes.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from .db import SessionLocal
2+
3+
async def get_db():
4+
db = SessionLocal()
5+
try:
6+
yield db
7+
finally:
8+
db.close()

Diff for: app_less_69_new/main.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from fastapi import FastAPI
22
from sqlalchemy import create_engine
33
from sqlalchemy.schema import CreateTable
4-
from .models import User, Task
5-
from .backends.bd import Base
6-
from .routers import task, user
4+
from models import User, Task
5+
from backends.bd import Base
6+
from routers import task, user
77

88

99
#$env:PYTHONPATH="C:\VisualDevelop\Python_Lesson"
10+
#alembic init app/migrations
11+
#alembic revision --autogenerate -m "Initial migration"
1012
#alembic upgrade head
1113
#uvicorn main:app --reload
1214

File renamed without changes.

Diff for: app_less_69_new/alembic/env.py renamed to app_less_69_new/migrations/env.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
from sqlalchemy import engine_from_config
44
from sqlalchemy import pool
5-
from ..backends.bd import Base
6-
from ..models import User, Task
5+
76
from alembic import context
87

98
# this is the Alembic Config object, which provides
@@ -15,6 +14,7 @@
1514
if config.config_file_name is not None:
1615
fileConfig(config.config_file_name)
1716

17+
from app_less_69_new.backends.bd import Base
1818
# add your model's MetaData object here
1919
# for 'autogenerate' support
2020
# from myapp import mymodel
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""Initial migration
2+
3+
Revision ID: 04f2d5baf5fc
4+
Revises:
5+
Create Date: 2024-11-04 09:50:54.426527
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = '04f2d5baf5fc'
16+
down_revision: Union[str, None] = None
17+
branch_labels: Union[str, Sequence[str], None] = None
18+
depends_on: Union[str, Sequence[str], None] = None
19+
20+
21+
def upgrade() -> None:
22+
# ### commands auto generated by Alembic - please adjust! ###
23+
op.drop_index('ix_users_id', table_name='users')
24+
op.drop_index('ix_users_slug', table_name='users')
25+
op.drop_table('users')
26+
op.drop_index('ix_tasks_id', table_name='tasks')
27+
op.drop_index('ix_tasks_slug', table_name='tasks')
28+
op.drop_index('ix_tasks_user_id', table_name='tasks')
29+
op.drop_table('tasks')
30+
# ### end Alembic commands ###
31+
32+
33+
def downgrade() -> None:
34+
# ### commands auto generated by Alembic - please adjust! ###
35+
op.create_table('tasks',
36+
sa.Column('id', sa.INTEGER(), nullable=False),
37+
sa.Column('title', sa.VARCHAR(), nullable=True),
38+
sa.Column('content', sa.VARCHAR(), nullable=True),
39+
sa.Column('priority', sa.INTEGER(), nullable=True),
40+
sa.Column('completed', sa.BOOLEAN(), nullable=True),
41+
sa.Column('user_id', sa.INTEGER(), nullable=False),
42+
sa.Column('slug', sa.VARCHAR(), nullable=True),
43+
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
44+
sa.PrimaryKeyConstraint('id')
45+
)
46+
op.create_index('ix_tasks_user_id', 'tasks', ['user_id'], unique=False)
47+
op.create_index('ix_tasks_slug', 'tasks', ['slug'], unique=1)
48+
op.create_index('ix_tasks_id', 'tasks', ['id'], unique=False)
49+
op.create_table('users',
50+
sa.Column('id', sa.INTEGER(), nullable=False),
51+
sa.Column('username', sa.VARCHAR(), nullable=True),
52+
sa.Column('firstname', sa.VARCHAR(), nullable=True),
53+
sa.Column('lastname', sa.VARCHAR(), nullable=True),
54+
sa.Column('age', sa.INTEGER(), nullable=True),
55+
sa.Column('slug', sa.VARCHAR(), nullable=True),
56+
sa.PrimaryKeyConstraint('id')
57+
)
58+
op.create_index('ix_users_slug', 'users', ['slug'], unique=1)
59+
op.create_index('ix_users_id', 'users', ['id'], unique=False)
60+
# ### end Alembic commands ###

Diff for: requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ psycopg2-binary==2.9.9
1818
fastapi==0.115.0
1919
uvicorn==0.30.6
2020
asyncpg
21-
alembic==1.13.3
21+
alembic==1.13.3
22+
python-slugify==8.0.4
40 KB
Binary file not shown.

0 commit comments

Comments
 (0)