mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 15:12:08 +01:00
feat(models): add basic database structure
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
"""add categories
|
||||
|
||||
Revision ID: a60134ef6c4c
|
||||
Revises: c5e9d6c59812
|
||||
Create Date: 2025-10-09 14:29:31.170347
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import fastapi_users_db_sqlalchemy
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'a60134ef6c4c'
|
||||
down_revision: Union[str, Sequence[str], None] = 'c5e9d6c59812'
|
||||
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('categories',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('name', sa.String(length=100), nullable=False),
|
||||
sa.Column('description', sa.String(length=255), nullable=True),
|
||||
sa.Column('user_id', fastapi_users_db_sqlalchemy.generics.GUID(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('name')
|
||||
)
|
||||
op.create_table('category_transaction',
|
||||
sa.Column('id_category', sa.Integer(), nullable=True),
|
||||
sa.Column('id_transaction', sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['id_category'], ['categories.id'], ),
|
||||
sa.ForeignKeyConstraint(['id_transaction'], ['transaction.id'], )
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('category_transaction')
|
||||
op.drop_table('categories')
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,41 @@
|
||||
"""User transaction relationship
|
||||
|
||||
Revision ID: c5e9d6c59812
|
||||
Revises: 81f275275556
|
||||
Create Date: 2025-10-09 14:17:19.983889
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import fastapi_users_db_sqlalchemy
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'c5e9d6c59812'
|
||||
down_revision: Union[str, Sequence[str], None] = '81f275275556'
|
||||
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.alter_column('transaction', 'user_id',
|
||||
existing_type=sa.UUID(),
|
||||
type_=fastapi_users_db_sqlalchemy.generics.GUID(),
|
||||
existing_nullable=False)
|
||||
op.create_foreign_key(None, 'transaction', 'user', ['user_id'], ['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'transaction', type_='foreignkey')
|
||||
op.alter_column('transaction', 'user_id',
|
||||
existing_type=fastapi_users_db_sqlalchemy.generics.GUID(),
|
||||
type_=sa.UUID(),
|
||||
existing_nullable=False)
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user