Initial commit with authentication and routes for registering/login already set up
This commit is contained in:
1
alembic/README
Normal file
1
alembic/README
Normal file
@ -0,0 +1 @@
|
||||
Generic single-database configuration.
|
||||
84
alembic/env.py
Normal file
84
alembic/env.py
Normal file
@ -0,0 +1,84 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
from logging.config import fileConfig
|
||||
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import pool
|
||||
|
||||
from alembic import context
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'app'))
|
||||
|
||||
from models import Base
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
target_metadata = Base.metadata
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
# my_important_option = config.get_main_option("my_important_option")
|
||||
# ... etc.
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
"""Run migrations in 'offline' mode.
|
||||
|
||||
This configures the context with just a URL
|
||||
and not an Engine, though an Engine is acceptable
|
||||
here as well. By skipping the Engine creation
|
||||
we don't even need a DBAPI to be available.
|
||||
|
||||
Calls to context.execute() here emit the given string to the
|
||||
script output.
|
||||
|
||||
"""
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(
|
||||
url=url,
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
"""Run migrations in 'online' mode.
|
||||
|
||||
In this scenario we need to create an Engine
|
||||
and associate a connection with the context.
|
||||
|
||||
"""
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=pool.NullPool,
|
||||
)
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(
|
||||
connection=connection, target_metadata=target_metadata
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
26
alembic/script.py.mako
Normal file
26
alembic/script.py.mako
Normal file
@ -0,0 +1,26 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = ${repr(up_revision)}
|
||||
down_revision: Union[str, None] = ${repr(down_revision)}
|
||||
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
||||
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
${downgrades if downgrades else "pass"}
|
||||
@ -0,0 +1,56 @@
|
||||
"""Add relation between bid and user through userId and added nullable false to all foreign keys
|
||||
|
||||
Revision ID: 21ac26bca176
|
||||
Revises: 22e9331f3fbd
|
||||
Create Date: 2024-10-13 20:21:05.124526
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '21ac26bca176'
|
||||
down_revision: Union[str, None] = '22e9331f3fbd'
|
||||
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.alter_column('accounts', 'userId',
|
||||
existing_type=sa.INTEGER(),
|
||||
nullable=False)
|
||||
op.alter_column('auctions', 'vehicleId',
|
||||
existing_type=sa.INTEGER(),
|
||||
nullable=False)
|
||||
op.alter_column('auctions', 'userId',
|
||||
existing_type=sa.INTEGER(),
|
||||
nullable=False)
|
||||
op.add_column('bids', sa.Column('userId', sa.Integer(), nullable=False))
|
||||
op.alter_column('bids', 'auctionId',
|
||||
existing_type=sa.INTEGER(),
|
||||
nullable=False)
|
||||
op.create_foreign_key(None, 'bids', 'users', ['userId'], ['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'bids', type_='foreignkey')
|
||||
op.alter_column('bids', 'auctionId',
|
||||
existing_type=sa.INTEGER(),
|
||||
nullable=True)
|
||||
op.drop_column('bids', 'userId')
|
||||
op.alter_column('auctions', 'userId',
|
||||
existing_type=sa.INTEGER(),
|
||||
nullable=True)
|
||||
op.alter_column('auctions', 'vehicleId',
|
||||
existing_type=sa.INTEGER(),
|
||||
nullable=True)
|
||||
op.alter_column('accounts', 'userId',
|
||||
existing_type=sa.INTEGER(),
|
||||
nullable=True)
|
||||
# ### end Alembic commands ###
|
||||
@ -0,0 +1,30 @@
|
||||
"""Add relation between Bid and User
|
||||
|
||||
Revision ID: 22e9331f3fbd
|
||||
Revises: 3ab355a9d3b1
|
||||
Create Date: 2024-10-13 19:49:18.378918
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '22e9331f3fbd'
|
||||
down_revision: Union[str, None] = '3ab355a9d3b1'
|
||||
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! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
32
alembic/versions/2ea50aba1814_added_postcode_and_city.py
Normal file
32
alembic/versions/2ea50aba1814_added_postcode_and_city.py
Normal file
@ -0,0 +1,32 @@
|
||||
"""Added postcode and city
|
||||
|
||||
Revision ID: 2ea50aba1814
|
||||
Revises: f0915dd7eb8b
|
||||
Create Date: 2024-10-14 04:23:57.393072
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '2ea50aba1814'
|
||||
down_revision: Union[str, None] = 'f0915dd7eb8b'
|
||||
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.add_column('users', sa.Column('postcode', sa.Integer(), nullable=False))
|
||||
op.add_column('users', sa.Column('city', sa.String(), nullable=False))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('users', 'city')
|
||||
op.drop_column('users', 'postcode')
|
||||
# ### end Alembic commands ###
|
||||
@ -0,0 +1,30 @@
|
||||
"""Add relation between Bid and User
|
||||
|
||||
Revision ID: 3ab355a9d3b1
|
||||
Revises: 88d9df7768b2
|
||||
Create Date: 2024-10-13 19:44:39.230332
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '3ab355a9d3b1'
|
||||
down_revision: Union[str, None] = '88d9df7768b2'
|
||||
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! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
138
alembic/versions/88d9df7768b2_initial_migration.py
Normal file
138
alembic/versions/88d9df7768b2_initial_migration.py
Normal file
@ -0,0 +1,138 @@
|
||||
"""Initial migration
|
||||
|
||||
Revision ID: 88d9df7768b2
|
||||
Revises:
|
||||
Create Date: 2024-10-12 15:40:52.735580
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '88d9df7768b2'
|
||||
down_revision: Union[str, None] = None
|
||||
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('equipment',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('name', sa.String(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('users',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('name', sa.String(), nullable=False),
|
||||
sa.Column('company', sa.String(), nullable=True),
|
||||
sa.Column('address', sa.String(), nullable=False),
|
||||
sa.Column('latitude', sa.String(), nullable=True),
|
||||
sa.Column('longitude', sa.String(), nullable=True),
|
||||
sa.Column('phone', sa.String(), nullable=False),
|
||||
sa.Column('privatePhone', sa.String(), nullable=True),
|
||||
sa.Column('email', sa.String(), nullable=False),
|
||||
sa.Column('cvr', sa.String(), nullable=True),
|
||||
sa.Column('password', sa.String(), nullable=False),
|
||||
sa.Column('username', sa.String(), nullable=False),
|
||||
sa.Column('role', sa.Enum('PRIVATE', 'BUSINESS', name='userrole'), nullable=True),
|
||||
sa.Column('updatedAt', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||
sa.Column('createdAt', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('email'),
|
||||
sa.UniqueConstraint('username')
|
||||
)
|
||||
op.create_table('vehicles',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('brand', sa.String(), nullable=False),
|
||||
sa.Column('model', sa.String(), nullable=False),
|
||||
sa.Column('variant', sa.String(), nullable=True),
|
||||
sa.Column('year', sa.Integer(), nullable=False),
|
||||
sa.Column('kilometers', sa.Integer(), nullable=False),
|
||||
sa.Column('condition', sa.String(), nullable=False),
|
||||
sa.Column('location', sa.String(), nullable=False),
|
||||
sa.Column('latitude', sa.String(), nullable=False),
|
||||
sa.Column('longitude', sa.String(), nullable=False),
|
||||
sa.Column('gasType', sa.String(), nullable=False),
|
||||
sa.Column('images', sa.Text(), nullable=False),
|
||||
sa.Column('description', sa.String(), nullable=False),
|
||||
sa.Column('service', sa.String(), nullable=False),
|
||||
sa.Column('inspectedAt', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('updatedAt', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||
sa.Column('createdAt', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('verification_tokens',
|
||||
sa.Column('identifier', sa.String(), nullable=False),
|
||||
sa.Column('token', sa.String(), nullable=False),
|
||||
sa.Column('expires', sa.DateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('identifier'),
|
||||
sa.UniqueConstraint('token')
|
||||
)
|
||||
op.create_table('accounts',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('userId', sa.Integer(), nullable=True),
|
||||
sa.Column('type', sa.String(), nullable=False),
|
||||
sa.Column('provider', sa.String(), nullable=False),
|
||||
sa.Column('providerAccountId', sa.String(), nullable=False),
|
||||
sa.Column('refresh_token', sa.String(), nullable=True),
|
||||
sa.Column('access_token', sa.String(), nullable=True),
|
||||
sa.Column('expires_at', sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['userId'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('auctions',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('vehicleId', sa.Integer(), nullable=True),
|
||||
sa.Column('userId', sa.Integer(), nullable=True),
|
||||
sa.Column('askingPrice', sa.Float(), nullable=False),
|
||||
sa.Column('description', sa.String(), nullable=True),
|
||||
sa.Column('updatedAt', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||
sa.Column('createdAt', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||
sa.ForeignKeyConstraint(['userId'], ['users.id'], ),
|
||||
sa.ForeignKeyConstraint(['vehicleId'], ['vehicles.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('sessions',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('sessionToken', sa.String(), nullable=False),
|
||||
sa.Column('userId', sa.Integer(), nullable=True),
|
||||
sa.Column('expires', sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['userId'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('sessionToken')
|
||||
)
|
||||
op.create_table('vehicle_equipment',
|
||||
sa.Column('vehicle_id', sa.Integer(), nullable=False),
|
||||
sa.Column('equipment_id', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['equipment_id'], ['equipment.id'], ),
|
||||
sa.ForeignKeyConstraint(['vehicle_id'], ['vehicles.id'], ),
|
||||
sa.PrimaryKeyConstraint('vehicle_id', 'equipment_id')
|
||||
)
|
||||
op.create_table('bids',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('auctionId', sa.Integer(), nullable=True),
|
||||
sa.Column('bid', sa.Float(), nullable=False),
|
||||
sa.Column('updatedAt', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||
sa.Column('createdAt', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||
sa.ForeignKeyConstraint(['auctionId'], ['auctions.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('bids')
|
||||
op.drop_table('vehicle_equipment')
|
||||
op.drop_table('sessions')
|
||||
op.drop_table('auctions')
|
||||
op.drop_table('accounts')
|
||||
op.drop_table('verification_tokens')
|
||||
op.drop_table('vehicles')
|
||||
op.drop_table('users')
|
||||
op.drop_table('equipment')
|
||||
# ### end Alembic commands ###
|
||||
32
alembic/versions/bc6a303851bc_removed_username.py
Normal file
32
alembic/versions/bc6a303851bc_removed_username.py
Normal file
@ -0,0 +1,32 @@
|
||||
"""Removed username
|
||||
|
||||
Revision ID: bc6a303851bc
|
||||
Revises: 21ac26bca176
|
||||
Create Date: 2024-10-14 03:48:16.528692
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'bc6a303851bc'
|
||||
down_revision: Union[str, None] = '21ac26bca176'
|
||||
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.drop_constraint('users_username_key', 'users', type_='unique')
|
||||
op.drop_column('users', 'username')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('users', sa.Column('username', sa.VARCHAR(), autoincrement=False, nullable=False))
|
||||
op.create_unique_constraint('users_username_key', 'users', ['username'])
|
||||
# ### end Alembic commands ###
|
||||
@ -0,0 +1,30 @@
|
||||
"""changed user_input to email in UserLogin BaseModel
|
||||
|
||||
Revision ID: f0915dd7eb8b
|
||||
Revises: bc6a303851bc
|
||||
Create Date: 2024-10-14 03:52:56.985970
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'f0915dd7eb8b'
|
||||
down_revision: Union[str, None] = 'bc6a303851bc'
|
||||
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! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user