-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
3 changed files
with
85 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Create Price table | ||
Revision ID: 43571a31006d | ||
Revises: 01907c7134ee | ||
Create Date: 2023-11-12 18:27:49.656734 | ||
""" | ||
from typing import Sequence | ||
from typing import Union | ||
|
||
import sqlalchemy as sa | ||
|
||
from alembic import op | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '43571a31006d' | ||
down_revision: Union[str, None] = '01907c7134ee' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
'prices', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('product_code', sa.String(), nullable=True), | ||
sa.Column('price', sa.Numeric(precision=10, scale=2), nullable=True), | ||
sa.Column('currency', sa.String(length=3), nullable=True), | ||
sa.Column('location_osm_id', sa.BigInteger(), nullable=True), | ||
sa.Column('location_osm_type', sa.String(length=255), nullable=True), | ||
sa.Column('date', sa.Date(), nullable=True), | ||
sa.Column('created', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), | ||
sa.PrimaryKeyConstraint('id'), | ||
) | ||
op.create_index(op.f('ix_prices_id'), 'prices', ['id'], unique=False) | ||
op.create_index(op.f('ix_prices_location_osm_id'), 'prices', ['location_osm_id'], unique=False) | ||
op.create_index(op.f('ix_prices_product_code'), 'prices', ['product_code'], unique=False) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index(op.f('ix_prices_product_code'), table_name='prices') | ||
op.drop_index(op.f('ix_prices_location_osm_id'), table_name='prices') | ||
op.drop_index(op.f('ix_prices_id'), table_name='prices') | ||
op.drop_table('prices') | ||
# ### end Alembic commands ### |
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,7 @@ | ||
from enum import Enum | ||
|
||
|
||
class PriceLocationOSMType(Enum): | ||
NODE = "NODE" | ||
WAY = "WAY" | ||
RELATION = "RELATION" |
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,15 +1,44 @@ | ||
from sqlalchemy import BigInteger | ||
from sqlalchemy import Column | ||
from sqlalchemy import Date | ||
from sqlalchemy import DateTime | ||
from sqlalchemy import Integer | ||
from sqlalchemy import Numeric | ||
from sqlalchemy import String | ||
from sqlalchemy.sql import func | ||
from sqlalchemy_utils import force_auto_coercion | ||
from sqlalchemy_utils.types.choice import ChoiceType | ||
from sqlalchemy_utils.types.currency import CurrencyType | ||
|
||
from app.db import Base | ||
from app.enums import PriceLocationOSMType | ||
|
||
force_auto_coercion() | ||
|
||
|
||
class User(Base): | ||
user_id = Column(String, primary_key=True, index=True) | ||
token = Column(String, unique=True, index=True) | ||
|
||
last_used = Column(DateTime(timezone=True)) | ||
|
||
created = Column(DateTime(timezone=True), server_default=func.now()) | ||
|
||
__tablename__ = "users" | ||
|
||
|
||
class Price(Base): | ||
id = Column(Integer, primary_key=True, index=True) | ||
product_code = Column(String, index=True) | ||
|
||
price = Column(Numeric(precision=10, scale=2)) | ||
currency = Column(CurrencyType) | ||
|
||
location_osm_id = Column(BigInteger, index=True) | ||
location_osm_type = Column(ChoiceType(PriceLocationOSMType)) | ||
|
||
date = Column(Date) | ||
|
||
created = Column(DateTime(timezone=True), server_default=func.now()) | ||
|
||
__tablename__ = "prices" |