diff --git a/backend/README.md b/backend/README.md index a017a4d..286c544 100644 --- a/backend/README.md +++ b/backend/README.md @@ -21,7 +21,6 @@ fastapi dev src/main.py ### Migration This repository use `alembic` for migrations -On first installation copy the `alembic.ini.example` to `alembic.ini` #### Create migration ```console alembic revision --autogenerate -m "message" diff --git a/backend/alembic/env.py b/backend/alembic/env.py index 567f10a..7c92e0d 100644 --- a/backend/alembic/env.py +++ b/backend/alembic/env.py @@ -7,7 +7,7 @@ from alembic import context from sqlmodel import SQLModel from src.settings import settings - +from src.models import * # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config diff --git a/backend/alembic/versions/370137544ee6_initial_repository.py b/backend/alembic/versions/370137544ee6_initial_repository.py deleted file mode 100644 index 089e8f4..0000000 --- a/backend/alembic/versions/370137544ee6_initial_repository.py +++ /dev/null @@ -1,155 +0,0 @@ -"""Initial repository - -Revision ID: 370137544ee6 -Revises: -Create Date: 2026-02-19 22:55:19.804879 - -""" -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql -import sqlmodel.sql.sqltypes - -# revision identifiers, used by Alembic. -revision: str = '370137544ee6' -down_revision: Union[str, Sequence[str], None] = None -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - """Upgrade schema.""" - # ### commands auto generated by Alembic - please adjust! ### - op.drop_table('template') - op.drop_table('user') - op.drop_table('form') - op.drop_table('usercontracttypelink') - op.drop_table('shipment') - op.drop_table('cheque') - op.drop_table('productor') - op.drop_table('paymentmethod') - op.drop_table('contract') - op.drop_table('contractproduct') - op.drop_table('contracttype') - op.drop_table('product') - op.drop_table('shipmentproductlink') - # ### end Alembic commands ### - - -def downgrade() -> None: - """Downgrade schema.""" - # ### commands auto generated by Alembic - please adjust! ### - op.create_table('shipmentproductlink', - sa.Column('shipment_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('product_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.ForeignKeyConstraint(['product_id'], ['product.id'], name=op.f('shipmentproductlink_product_id_fkey')), - sa.ForeignKeyConstraint(['shipment_id'], ['shipment.id'], name=op.f('shipmentproductlink_shipment_id_fkey')), - sa.PrimaryKeyConstraint('shipment_id', 'product_id', name=op.f('shipmentproductlink_pkey')) - ) - op.create_table('product', - sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('unit', postgresql.ENUM('GRAMS', 'KILO', 'PIECE', name='unit'), autoincrement=False, nullable=False), - sa.Column('price', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True), - sa.Column('price_kg', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True), - sa.Column('quantity', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True), - sa.Column('quantity_unit', sa.VARCHAR(), autoincrement=False, nullable=True), - sa.Column('type', postgresql.ENUM('OCCASIONAL', 'RECCURENT', name='producttype'), autoincrement=False, nullable=False), - sa.Column('productor_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.ForeignKeyConstraint(['productor_id'], ['productor.id'], name=op.f('product_productor_id_fkey')), - sa.PrimaryKeyConstraint('id', name=op.f('product_pkey')) - ) - op.create_table('contracttype', - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.PrimaryKeyConstraint('id', name=op.f('contracttype_pkey')) - ) - op.create_table('contractproduct', - sa.Column('product_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('shipment_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('quantity', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=False), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('contract_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.ForeignKeyConstraint(['contract_id'], ['contract.id'], name=op.f('contractproduct_contract_id_fkey'), ondelete='CASCADE'), - sa.ForeignKeyConstraint(['product_id'], ['product.id'], name=op.f('contractproduct_product_id_fkey'), ondelete='CASCADE'), - sa.ForeignKeyConstraint(['shipment_id'], ['shipment.id'], name=op.f('contractproduct_shipment_id_fkey'), ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id', name=op.f('contractproduct_pkey')) - ) - op.create_table('contract', - sa.Column('firstname', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('lastname', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('email', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('phone', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('payment_method', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('cheque_quantity', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('form_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('file', postgresql.BYTEA(), autoincrement=False, nullable=True), - sa.Column('total_price', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['form_id'], ['form.id'], name=op.f('contract_form_id_fkey'), ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id', name=op.f('contract_pkey')) - ) - op.create_table('paymentmethod', - sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('details', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('productor_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.ForeignKeyConstraint(['productor_id'], ['productor.id'], name=op.f('paymentmethod_productor_id_fkey'), ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id', name=op.f('paymentmethod_pkey')) - ) - op.create_table('productor', - sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('address', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('type', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.PrimaryKeyConstraint('id', name=op.f('productor_pkey')) - ) - op.create_table('cheque', - sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('value', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('contract_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.ForeignKeyConstraint(['contract_id'], ['contract.id'], name=op.f('cheque_contract_id_fkey'), ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id', name=op.f('cheque_pkey')) - ) - op.create_table('shipment', - sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('date', sa.DATE(), autoincrement=False, nullable=False), - sa.Column('form_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.ForeignKeyConstraint(['form_id'], ['form.id'], name=op.f('shipment_form_id_fkey'), ondelete='CASCADE'), - sa.PrimaryKeyConstraint('id', name=op.f('shipment_pkey')) - ) - op.create_table('usercontracttypelink', - sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('contract_type_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.ForeignKeyConstraint(['contract_type_id'], ['contracttype.id'], name=op.f('usercontracttypelink_contract_type_id_fkey')), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('usercontracttypelink_user_id_fkey')), - sa.PrimaryKeyConstraint('user_id', 'contract_type_id', name=op.f('usercontracttypelink_pkey')) - ) - op.create_table('form', - sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('productor_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('referer_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('season', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('start', sa.DATE(), autoincrement=False, nullable=False), - sa.Column('end', sa.DATE(), autoincrement=False, nullable=False), - sa.Column('minimum_shipment_value', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.ForeignKeyConstraint(['productor_id'], ['productor.id'], name=op.f('form_productor_id_fkey')), - sa.ForeignKeyConstraint(['referer_id'], ['user.id'], name=op.f('form_referer_id_fkey')), - sa.PrimaryKeyConstraint('id', name=op.f('form_pkey')) - ) - op.create_table('user', - sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('email', sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.PrimaryKeyConstraint('id', name=op.f('user_pkey')) - ) - op.create_table('template', - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.PrimaryKeyConstraint('id', name=op.f('template_pkey')) - ) - # ### end Alembic commands ### diff --git a/backend/alembic/versions/c0b1073a8394_initial_repository.py b/backend/alembic/versions/c0b1073a8394_initial_repository.py new file mode 100644 index 0000000..0d280fb --- /dev/null +++ b/backend/alembic/versions/c0b1073a8394_initial_repository.py @@ -0,0 +1,155 @@ +"""Initial repository + +Revision ID: c0b1073a8394 +Revises: +Create Date: 2026-02-20 00:09:35.920486 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + +import sqlmodel.sql.sqltypes + +# revision identifiers, used by Alembic. +revision: str = 'c0b1073a8394' +down_revision: Union[str, Sequence[str], None] = None +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + """Upgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('contracttype', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('productor', + sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('address', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('type', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('template', + sa.Column('id', sa.Integer(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('user', + sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('email', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('form', + sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('productor_id', sa.Integer(), nullable=True), + sa.Column('referer_id', sa.Integer(), nullable=True), + sa.Column('season', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('start', sa.Date(), nullable=False), + sa.Column('end', sa.Date(), nullable=False), + sa.Column('minimum_shipment_value', sa.Float(), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['productor_id'], ['productor.id'], ), + sa.ForeignKeyConstraint(['referer_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('paymentmethod', + sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('details', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('productor_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['productor_id'], ['productor.id'], ondelete='CASCADE'), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('product', + sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('unit', sa.Enum('GRAMS', 'KILO', 'PIECE', name='unit'), nullable=False), + sa.Column('price', sa.Float(), nullable=True), + sa.Column('price_kg', sa.Float(), nullable=True), + sa.Column('quantity', sa.Float(), nullable=True), + sa.Column('quantity_unit', sqlmodel.sql.sqltypes.AutoString(), nullable=True), + sa.Column('type', sa.Enum('OCCASIONAL', 'RECCURENT', name='producttype'), nullable=False), + sa.Column('productor_id', sa.Integer(), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['productor_id'], ['productor.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('usercontracttypelink', + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('contract_type_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['contract_type_id'], ['contracttype.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('user_id', 'contract_type_id') + ) + op.create_table('contract', + sa.Column('firstname', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('lastname', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('email', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('phone', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('payment_method', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('cheque_quantity', sa.Integer(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('form_id', sa.Integer(), nullable=False), + sa.Column('file', sa.LargeBinary(), nullable=True), + sa.Column('total_price', sa.Float(), nullable=True), + sa.ForeignKeyConstraint(['form_id'], ['form.id'], ondelete='CASCADE'), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('shipment', + sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('date', sa.Date(), nullable=False), + sa.Column('form_id', sa.Integer(), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['form_id'], ['form.id'], ondelete='CASCADE'), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('cheque', + sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('value', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('contract_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['contract_id'], ['contract.id'], ondelete='CASCADE'), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('contractproduct', + sa.Column('product_id', sa.Integer(), nullable=False), + sa.Column('shipment_id', sa.Integer(), nullable=True), + sa.Column('quantity', sa.Float(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('contract_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['contract_id'], ['contract.id'], ondelete='CASCADE'), + sa.ForeignKeyConstraint(['product_id'], ['product.id'], ondelete='CASCADE'), + sa.ForeignKeyConstraint(['shipment_id'], ['shipment.id'], ondelete='CASCADE'), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('shipmentproductlink', + sa.Column('shipment_id', sa.Integer(), nullable=False), + sa.Column('product_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['product_id'], ['product.id'], ), + sa.ForeignKeyConstraint(['shipment_id'], ['shipment.id'], ), + sa.PrimaryKeyConstraint('shipment_id', 'product_id') + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + """Downgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('shipmentproductlink') + op.drop_table('contractproduct') + op.drop_table('cheque') + op.drop_table('shipment') + op.drop_table('contract') + op.drop_table('usercontracttypelink') + op.drop_table('product') + op.drop_table('paymentmethod') + op.drop_table('form') + op.drop_table('user') + op.drop_table('template') + op.drop_table('productor') + op.drop_table('contracttype') + # ### end Alembic commands ### diff --git a/backend/src/main.py b/backend/src/main.py index 5b1e638..9de6475 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -35,7 +35,4 @@ app.include_router(productors_router, prefix="/api") app.include_router(products_router, prefix="/api") app.include_router(users_router, prefix="/api") app.include_router(auth_router, prefix="/api") -app.include_router(shipment_router, prefix="/api") - -if settings.debug == True: - create_all_tables() \ No newline at end of file +app.include_router(shipment_router, prefix="/api") \ No newline at end of file diff --git a/backend/src/settings.py b/backend/src/settings.py index e646bbd..22e703d 100644 --- a/backend/src/settings.py +++ b/backend/src/settings.py @@ -12,6 +12,7 @@ class Settings(BaseSettings): keycloak_client_id: str keycloak_client_secret: str keycloak_redirect_uri: str + vite_api_url: str max_age: int debug: bool diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 5ff3599..c07e388 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -17,9 +17,9 @@ services: context: . dockerfile: backend/Dockerfile volumes: - - ./backend:/code/app + - ./backend:/code command: > - sh -c "fastapi run app/src/main.py --reload --port 8000" + sh -c "fastapi run src/main.py --reload --port 8000" environment: ORIGINS: ${ORIGINS} DB_HOST: database @@ -27,6 +27,7 @@ services: DB_PASS: ${DB_PASS} DB_NAME: ${DB_NAME} SECRET_KEY: ${SECRET_KEY} + VITE_API_URL: ${VITE_API_URL} KEYCLOAK_SERVER: ${KEYCLOAK_SERVER} KEYCLOAK_REALM: ${KEYCLOAK_REALM} KEYCLOAK_CLIENT_ID: ${KEYCLOAK_CLIENT_ID} diff --git a/docker-compose.yaml b/docker-compose.yaml index e75faba..ad4f6de 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -22,6 +22,7 @@ services: DB_PASS: ${DB_PASS} DB_NAME: ${DB_NAME} SECRET_KEY: ${SECRET_KEY} + VITE_API_URL: ${VITE_API_URL} KEYCLOAK_SERVER: ${KEYCLOAK_SERVER} KEYCLOAK_REALM: ${KEYCLOAK_REALM} KEYCLOAK_CLIENT_ID: ${KEYCLOAK_CLIENT_ID} @@ -41,7 +42,7 @@ services: POSTGRES_USER: ${DB_USER} POSTGRES_PASSWORD: ${DB_PASS} POSTGRES_DB: ${DB_NAME} - ports: + ports: - 5432:5432 volumes: db: \ No newline at end of file