Skip to content

Ft001 base de datos #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions migrations/versions/a08fba8a0180_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""empty message

Revision ID: a08fba8a0180
Revises:
Create Date: 2025-03-05 14:44:28.016416

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'a08fba8a0180'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('accessories',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('brand', sa.String(length=100), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('animal_type', sa.String(length=50), nullable=False),
sa.Column('pathologies', sa.Text(), nullable=True),
sa.Column('price', sa.Float(), nullable=False),
sa.Column('url', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('foods',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('brand', sa.String(length=100), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('ingredients', sa.Text(), nullable=False),
sa.Column('weight', sa.Float(), nullable=False),
sa.Column('price', sa.Float(), nullable=False),
sa.Column('age', sa.String(), nullable=False),
sa.Column('animal_type', sa.String(length=50), nullable=False),
sa.Column('size', sa.String(length=30), nullable=True),
sa.Column('pathologies', sa.Text(), nullable=True),
sa.Column('url', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=80), nullable=False),
sa.Column('email', sa.String(length=120), nullable=False),
sa.Column('password', sa.String(length=80), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
op.create_table('pet',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('size', sa.String(length=100), nullable=True),
sa.Column('breed', sa.String(length=100), nullable=True),
sa.Column('age', sa.String(), nullable=False),
sa.Column('animal_type', sa.String(), nullable=False),
sa.Column('pathologies', sa.Text(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('url', sa.String(length=255), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('pet')
op.drop_table('user')
op.drop_table('foods')
op.drop_table('accessories')
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ sqlalchemy==1.3.23
urllib3==1.26.3; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'
werkzeug==1.0.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
wtforms==2.3.3

26 changes: 26 additions & 0 deletions requirements.txt.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-i https://pypi.org/simple
alembic==1.5.4; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
certifi==2020.12.5
click==7.1.2; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
cloudinary==1.24.0
flask==1.1.2
flask-admin==1.5.7
flask-cors==3.0.10
flask-migrate==2.6.0
flask-sqlalchemy==2.4.4
flask-swagger==0.2.14
gunicorn==20.0.4
itsdangerous==1.1.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
jinja2==2.11.3; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
mako==1.1.4; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
markupsafe==1.1.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
psycopg2-binary==2.8.6
python-dateutil==2.8.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
python-dotenv==0.15.0
python-editor==1.0.4
pyyaml==5.4.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
six==1.15.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
sqlalchemy==1.3.23
urllib3==1.26.3; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'
werkzeug==1.0.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
wtforms==2.
6 changes: 4 additions & 2 deletions src/api/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import os
from flask_admin import Admin
from .models import db, User
from .models import db, User, Food, Accessories, Pet
from flask_admin.contrib.sqla import ModelView

def setup_admin(app):
Expand All @@ -12,6 +12,8 @@ def setup_admin(app):

# Add your models here, for example this is how we add a the User model to the admin
admin.add_view(ModelView(User, db.session))

admin.add_view(ModelView(Food, db.session))
admin.add_view(ModelView(Accessories, db.session))
admin.add_view(ModelView(Pet, db.session))
# You can duplicate that line to add mew models
# admin.add_view(ModelView(YourModelName, db.session))
138 changes: 134 additions & 4 deletions src/api/commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import click
from api.models import db, User
from api.models import db, User, Food, Accessories, Pet

"""
In this file, you can add as many commands as you want using the @app.cli.command decorator
Expand All @@ -20,15 +20,145 @@ def insert_test_users(count):
print("Creating test users")
for x in range(1, int(count) + 1):
user = User()
user.name = "name"+ str(x)
user.email = "test_user" + str(x) + "@test.com"
user.password = "123456"
user.address = "asd"
user.phone = 12324
user.is_active = True
db.session.add(user)
db.session.commit()
print("User: ", user.email, " created.")

print("All test users created")

@app.cli.command("insert-test-data")
def insert_test_data():
pass
@app.cli.command("insert_data_catfood")
def insert_data_catfood():
catfood = Food()
catfood.name = "KA AYURVEDA Only Fish Gatos Sin Gluten"
catfood.brand="Feral"
catfood.description = "asd"
catfood.ingredients = "ads"
catfood.weight = 1.
catfood.price = 1.
catfood.animal_type = "asd"
catfood.age = "sd"
catfood.pathologies = "asd"
db.session.add(catfood)
db.session.commit()




@app.cli.command("insert_data_dogfood")
def insert_data_food():
dogfood = Food()
dogfood.name = "Special Care hepatic/renal"
dogfood.brand="nfnatcane"
dogfood.description = "asd"
dogfood.ingredients = "ads"
dogfood.price = 1.
dogfood.pathologies = "renal"
dogfood.animal_type = "perro"
dogfood.age = "senior"
dogfood.size = "medium"
dogfood.weight = 1.
db.session.add(dogfood)
db.session.commit()

dogfood = Food()
dogfood.name = "CARE DIGESTIVE (DOG)"
dogfood.brand="ownat"
dogfood.description = "asd"
dogfood.ingredients = "ads"
dogfood.price = 1.
dogfood.pathologies = "renal"
dogfood.animal_type = "perro"
dogfood.age = "senior"
dogfood.size = "medium"
dogfood.weight = 1.
db.session.add(dogfood)
db.session.commit()



@app.cli.command("insert_data_exoticfood")
def insert_data_exoticfood():
exoticfood = Food()
exoticfood.name = "critical care"
exoticfood.brand="oxbow"
exoticfood.description = "asd"
exoticfood.ingredients = "ads"
exoticfood.price = 1.
exoticfood.pathologies = "asd"
exoticfood.animal_type = "asd"
exoticfood.age = "asd"
exoticfood.weight = 1.
db.session.add(exoticfood)
db.session.commit()



@app.cli.command("insert_data_accessories")
def insert_data_accessories():
accessories= Accessories()
accessories.name = "critical care"
accessories.brand="oxbow"
accessories.description = "asd"
accessories.price = 1.
accessories.animal_type = ""
accessories.pathologies = ""
accessories.url = ""
db.session.add(accessories)
db.session.commit()


@app.cli.command("insert_data_pet")
def insert_data_pet():
pet= Pet()
pet.name = "asd"
pet.size=""
pet.breed= "asd"
pet.age= "cachorro"
pet.animal_type = "gato"
pet.pathologies="obesidad, diabetes"
pet.user_id = 1
db.session.add(pet)
db.session.commit()

pet= Pet()
pet.name = "recoleto"
pet.size="medium"
pet.breed= "asd"
pet.age="senior"
pet.animal_type = "perro"
pet.pathologies="renal"
pet.user_id = 1
db.session.add(pet)
db.session.commit()

pet= Pet()
pet.name = "asd"
pet.size="oxbow"
pet.breed= "asd"
pet.age= "2"
pet.animal_type = "cobaya"
pet.pathologies="escorbuto"
db.session.add(pet)
db.session.commit()

pet= Pet()
pet.name = "asd"
pet.size="oxbow"
pet.breed= "asd"
pet.age= "60"
pet.animal_type = "loro"
pet.pathologies=""
db.session.add(pet)
db.session.commit()






Loading