-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/FRAAND-T-29_tags' into FRAAND-T-29_tags Slightly updated (docstrings) Mako template for migrations... Solved the double dynamic models import by moving the functionality from models/__init__.py to models/util.py and execution to /alembic/env.py... Fixed a typo for ItemsTags Removed meta in db.md Added dynamic models importing for Alembic... Moved get_user_db() to users/dependencies.py... Made ERD code clearer... Updated ERD with Tags, ItemsTags and fields... Moved all models to Mapped-version; added Items-Tags association table; added tags migration... Changed declarative_base to DeclarativeBase in Base model... Added Tag model frame... Added Tag model frame... Fixed a typo in entrypoint.sh... Changed all `uid`s to `id`s in models and schemas; added tables names for User model; made Alembic's autogenerate() pick-up the changes... Added schema and data upgrade/downgrade for migrations template... Added Items and Images migrations... Updated Alembic-migrations with SQLAlchemy 2.0 version, added schema and data sections for them... Merge branch 'master' of https://git.jetbrains.space/uno/fraand/FRAAND Co-authored-by: Ernest Umerov <[email protected]> Merge-request: FRAAND-MR-7 Merged-by: Willhelm Hawk <[email protected]>
- Loading branch information
Showing
17 changed files
with
443 additions
and
50 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
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
88 changes: 88 additions & 0 deletions
88
alembic/versions/2023-05-16__added_items_and_images_frame_models.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,88 @@ | ||
"""Added Items and Images (frame) models... | ||
Revision ID: 720d958185d7 | ||
Revises: 8fc39660ddf4 | ||
Create Date: 2023-05-16 00:38:55.652063 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '720d958185d7' | ||
down_revision = '8fc39660ddf4' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
'items', | ||
sa.Column('id', sa.UUID(), nullable=False), | ||
sa.Column('name', sa.String(), nullable=False), | ||
sa.Column('description', sa.String(), nullable=True), | ||
sa.Column('is_published', sa.Boolean(), nullable=True), | ||
sa.Column('city', sa.String(), nullable=True), | ||
sa.PrimaryKeyConstraint('id', name=op.f('items_pkey')), | ||
) | ||
|
||
op.create_table( | ||
'images', | ||
sa.Column('id', sa.UUID(), nullable=False), | ||
sa.Column('image', sa.LargeBinary(), nullable=False), | ||
sa.Column('item_id', sa.UUID(), nullable=False), | ||
sa.ForeignKeyConstraint(['item_id'], ['items.id'], name=op.f('images_item_id_fkey')), | ||
sa.PrimaryKeyConstraint('id', name=op.f('images_pkey')), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('images') | ||
op.drop_table('items') | ||
# ### end Alembic commands ### | ||
|
||
|
||
def schema_upgrades(): | ||
"""schema upgrade migrations go here.""" | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
'items', | ||
sa.Column('id', sa.UUID(), nullable=False), | ||
sa.Column('name', sa.String(), nullable=False), | ||
sa.Column('description', sa.String(), nullable=True), | ||
sa.Column('is_published', sa.Boolean(), nullable=True), | ||
sa.Column('city', sa.String(), nullable=True), | ||
sa.PrimaryKeyConstraint('id', name=op.f('items_pkey')), | ||
) | ||
|
||
op.create_table( | ||
'images', | ||
sa.Column('id', sa.UUID(), nullable=False), | ||
sa.Column('image', sa.LargeBinary(), nullable=False), | ||
sa.Column('item_id', sa.UUID(), nullable=False), | ||
sa.ForeignKeyConstraint(['item_id'], ['items.id'], name=op.f('images_item_id_fkey')), | ||
sa.PrimaryKeyConstraint('id', name=op.f('images_pkey')), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def schema_downgrades(): | ||
"""schema downgrade migrations go here.""" | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('images') | ||
op.drop_table('items') | ||
# ### end Alembic commands ### | ||
|
||
|
||
def data_upgrades(): | ||
"""Add any optional data upgrade migrations here!""" | ||
pass | ||
|
||
|
||
def data_downgrades(): | ||
"""Add any optional data downgrade migrations here!""" | ||
pass |
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,80 @@ | ||
"""Added Tag, ItemTag models... | ||
Revision ID: 062796a52532 | ||
Revises: 720d958185d7 | ||
Create Date: 2023-05-16 02:29:59.569509 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '062796a52532' | ||
down_revision = '720d958185d7' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
'tags', | ||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column('name', sa.String(), nullable=False), | ||
sa.PrimaryKeyConstraint('id', name=op.f('tags_pkey')), | ||
) | ||
op.create_table( | ||
'items_tags_at', | ||
sa.Column('tag_id', sa.Integer(), nullable=False), | ||
sa.Column('item_id', sa.UUID(), nullable=False), | ||
sa.ForeignKeyConstraint(['item_id'], ['items.id'], name=op.f('items_tags_at_item_id_fkey')), | ||
sa.ForeignKeyConstraint(['tag_id'], ['tags.id'], name=op.f('items_tags_at_tag_id_fkey')), | ||
sa.PrimaryKeyConstraint('tag_id', 'item_id', name=op.f('items_tags_at_pkey')), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('items_tags_at') | ||
op.drop_table('tags') | ||
# ### end Alembic commands ### | ||
|
||
|
||
def schema_upgrades(): | ||
"""Schema upgrade migrations go here...""" | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
'tags', | ||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column('name', sa.String(), nullable=False), | ||
sa.PrimaryKeyConstraint('id', name=op.f('tags_pkey')), | ||
) | ||
op.create_table( | ||
'items_tags_at', | ||
sa.Column('tag_id', sa.Integer(), nullable=False), | ||
sa.Column('item_id', sa.UUID(), nullable=False), | ||
sa.ForeignKeyConstraint(['item_id'], ['items.id'], name=op.f('items_tags_at_item_id_fkey')), | ||
sa.ForeignKeyConstraint(['tag_id'], ['tags.id'], name=op.f('items_tags_at_tag_id_fkey')), | ||
sa.PrimaryKeyConstraint('tag_id', 'item_id', name=op.f('items_tags_at_pkey')), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def schema_downgrades(): | ||
"""schema downgrade migrations go here...""" | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('items_tags_at') | ||
op.drop_table('tags') | ||
# ### end Alembic commands ### | ||
|
||
|
||
def data_upgrades(): | ||
"""Add any optional data upgrade migrations here!""" | ||
pass | ||
|
||
|
||
def data_downgrades(): | ||
"""Add any optional data downgrade migrations here!""" | ||
pass |
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 |
---|---|---|
@@ -1,7 +1,49 @@ | ||
# Entity-Relationship Diagram (ERD) | ||
|
||
```mermaid | ||
erDiagram | ||
USER ||--o{ ITEM : has | ||
ITEM ||--o{ ITEM_IMAGE: has | ||
ITEM }|--|| CITY : is_published_in | ||
USERS { | ||
UUID id PK | ||
string email | ||
string hashed_password | ||
bool is_active | ||
bool is_verified | ||
bool is_superuser | ||
} | ||
ITEMS { | ||
UUID id PK | ||
string name | ||
string description | ||
bool is_published | ||
} | ||
ITEMS_TAGS { | ||
UUID item_id PK, FK | ||
int tag_id PK, FK | ||
} | ||
TAGS { | ||
int id PK | ||
string name | ||
} | ||
IMAGES { | ||
UUID id PK | ||
binary image | ||
UUID item_id FK | ||
} | ||
CITIES { | ||
UUID id PK | ||
string name "Will be some geo-based service/DB" | ||
} | ||
USERS || -- o{ ITEMS : has | ||
ITEMS || -- o{ IMAGES: has | ||
ITEMS }| -- || CITIES : is_published_in | ||
ITEMS || -- |{ ITEMS_TAGS : has | ||
ITEMS_TAGS }| -- || TAGS : has | ||
``` |
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
Oops, something went wrong.