From 65a5cd6c9dc41be6689f76fb665bbfae10c39519 Mon Sep 17 00:00:00 2001 From: Gweneth Johnson Date: Tue, 25 Apr 2023 13:14:10 -0700 Subject: [PATCH 01/12] finished wave 1 --- app/__init__.py | 4 +++- app/routes.py | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 70b4cabfe..57f895006 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,7 +1,9 @@ from flask import Flask - def create_app(test_config=None): app = Flask(__name__) + from .routes import planet_bp + app.register_blueprint(planet_bp) + return app diff --git a/app/routes.py b/app/routes.py index 8e9dfe684..8d0a139ec 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,2 +1,37 @@ -from flask import Blueprint +from flask import Blueprint, jsonify + +class Planet: + def __init__(self, id, name, description, distance): + self.id = id + self.name = name + self.description = description + self.distance = distance +planets = [ + Planet(1, 'Mercury', 'Rocky', '38 million'), + Planet(2, 'Venus', 'Cloudy', '66 million'), + Planet(3, 'Earth', 'Home', '92 million'), + Planet(4, 'Mars', 'Red', '141 million'), + Planet(5, 'Jupiter','Spotty', '483 million'), + Planet(6, 'Saturn', 'Rings', '890 million'), + Planet(7, 'Uranus', 'Ice Giant', '1.7 billion'), + Planet(8, 'Neptune', 'Dense Ice', '2.7 billion'), + Planet(9, 'Pluto', 'Dwarf Planet', '3.7 billion') + +] + +planet_bp = Blueprint("planet_bp", __name__, url_prefix="/planets") + +@planet_bp.route("", methods=["GET"]) +def get_planets(): + planet_list = [] + for planet in planets: + planet_list.append( + { + "id" : planet.id, + "name" : planet.name, + "description" : planet.description, + "distance" : planet.distance + } + ) + return jsonify(planet_list) \ No newline at end of file From 2f83376f6a45b9bf5dd3caf6024a933975b76b12 Mon Sep 17 00:00:00 2001 From: Gweneth Johnson Date: Tue, 25 Apr 2023 13:51:28 -0700 Subject: [PATCH 02/12] finished wave 2 --- app/routes.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/routes.py b/app/routes.py index 8d0a139ec..6830e97c3 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,4 +1,4 @@ -from flask import Blueprint, jsonify +from flask import Blueprint, jsonify, make_response, abort class Planet: def __init__(self, id, name, description, distance): @@ -6,6 +6,7 @@ def __init__(self, id, name, description, distance): self.name = name self.description = description self.distance = distance + self.dictionary = {"id" : id, "name" : name, "description": description, "distance": distance} planets = [ Planet(1, 'Mercury', 'Rocky', '38 million'), @@ -34,4 +35,17 @@ def get_planets(): "distance" : planet.distance } ) - return jsonify(planet_list) \ No newline at end of file + return jsonify(planet_list) + +@planet_bp.route("/", methods=["GET"]) +def get_planet(planet_id): + try: + planet_id = int(planet_id) + except: + abort(make_response({"message" : f"book {planet_id} invalid"}, 400)) + + for planet in planets: + if planet.id == planet_id: + return planet.dictionary + + abort(make_response({"message":f"planet {planet_id} not found"}, 404)) \ No newline at end of file From 00165fc80bc4c42d65267a9dcee16aba3dbc8bd3 Mon Sep 17 00:00:00 2001 From: Virginia Ramos Date: Fri, 28 Apr 2023 13:32:35 -0500 Subject: [PATCH 03/12] Migration confirmed --- app/__init__.py | 15 ++- app/models/__init__.py | 0 app/models/planet.py | 7 ++ migrations/README | 1 + migrations/alembic.ini | 45 +++++++++ migrations/env.py | 96 +++++++++++++++++++ migrations/script.py.mako | 24 +++++ .../afee522f3200_adds_planet_model.py | 34 +++++++ 8 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 app/models/__init__.py create mode 100644 app/models/planet.py create mode 100644 migrations/README create mode 100644 migrations/alembic.ini create mode 100644 migrations/env.py create mode 100644 migrations/script.py.mako create mode 100644 migrations/versions/afee522f3200_adds_planet_model.py diff --git a/app/__init__.py b/app/__init__.py index 57f895006..b10391993 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,9 +1,22 @@ -from flask import Flask +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +from flask_migrate import Migrate + +db = SQLAlchemy() +migrate = Migrate() def create_app(test_config=None): app = Flask(__name__) + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False + app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres:postgres@localhost:5432/solar_system_development' + + db.init_app(app) + migrate.init_app(app, db) + from app.models.planet import Planet + from .routes import planet_bp + # app.register_blueprint(planet_bp) app.register_blueprint(planet_bp) return app diff --git a/app/models/__init__.py b/app/models/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/app/models/planet.py b/app/models/planet.py new file mode 100644 index 000000000..dfd00209b --- /dev/null +++ b/app/models/planet.py @@ -0,0 +1,7 @@ +from app import db + +class Planet(db.Model): + id = db.Column(db.Integer, primary_key=True, autoincrement=True) + name = db.Column(db.String(255), nullable=False) + description = db.Column(db.Text, nullable=False) + distance = db.Column(db.String(255), nullable=False) \ No newline at end of file diff --git a/migrations/README b/migrations/README new file mode 100644 index 000000000..98e4f9c44 --- /dev/null +++ b/migrations/README @@ -0,0 +1 @@ +Generic single-database configuration. \ No newline at end of file diff --git a/migrations/alembic.ini b/migrations/alembic.ini new file mode 100644 index 000000000..f8ed4801f --- /dev/null +++ b/migrations/alembic.ini @@ -0,0 +1,45 @@ +# A generic, single database configuration. + +[alembic] +# template used to generate migration files +# file_template = %%(rev)s_%%(slug)s + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/migrations/env.py b/migrations/env.py new file mode 100644 index 000000000..8b3fb3353 --- /dev/null +++ b/migrations/env.py @@ -0,0 +1,96 @@ +from __future__ import with_statement + +import logging +from logging.config import fileConfig + +from sqlalchemy import engine_from_config +from sqlalchemy import pool +from flask import current_app + +from alembic import context + +# 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. +fileConfig(config.config_file_name) +logger = logging.getLogger('alembic.env') + +# add your model's MetaData object here +# for 'autogenerate' support +# from myapp import mymodel +# target_metadata = mymodel.Base.metadata +config.set_main_option( + 'sqlalchemy.url', + str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%')) +target_metadata = current_app.extensions['migrate'].db.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(): + """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 + ) + + with context.begin_transaction(): + context.run_migrations() + + +def run_migrations_online(): + """Run migrations in 'online' mode. + + In this scenario we need to create an Engine + and associate a connection with the context. + + """ + + # this callback is used to prevent an auto-migration from being generated + # when there are no changes to the schema + # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html + def process_revision_directives(context, revision, directives): + if getattr(config.cmd_opts, 'autogenerate', False): + script = directives[0] + if script.upgrade_ops.is_empty(): + directives[:] = [] + logger.info('No changes in schema detected.') + + 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, + process_revision_directives=process_revision_directives, + **current_app.extensions['migrate'].configure_args + ) + + with context.begin_transaction(): + context.run_migrations() + + +if context.is_offline_mode(): + run_migrations_offline() +else: + run_migrations_online() diff --git a/migrations/script.py.mako b/migrations/script.py.mako new file mode 100644 index 000000000..2c0156303 --- /dev/null +++ b/migrations/script.py.mako @@ -0,0 +1,24 @@ +"""${message} + +Revision ID: ${up_revision} +Revises: ${down_revision | comma,n} +Create Date: ${create_date} + +""" +from alembic import op +import sqlalchemy as sa +${imports if imports else ""} + +# revision identifiers, used by Alembic. +revision = ${repr(up_revision)} +down_revision = ${repr(down_revision)} +branch_labels = ${repr(branch_labels)} +depends_on = ${repr(depends_on)} + + +def upgrade(): + ${upgrades if upgrades else "pass"} + + +def downgrade(): + ${downgrades if downgrades else "pass"} diff --git a/migrations/versions/afee522f3200_adds_planet_model.py b/migrations/versions/afee522f3200_adds_planet_model.py new file mode 100644 index 000000000..b8af39c5e --- /dev/null +++ b/migrations/versions/afee522f3200_adds_planet_model.py @@ -0,0 +1,34 @@ +"""Adds Planet model + +Revision ID: afee522f3200 +Revises: +Create Date: 2023-04-28 13:14:20.124726 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'afee522f3200' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('planet', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('description', sa.Text(), nullable=False), + sa.Column('distance', sa.String(length=255), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('planet') + # ### end Alembic commands ### From 0bead4c1251e7f9ba6e93b79a3900122d8c26bae Mon Sep 17 00:00:00 2001 From: Virginia Ramos Date: Fri, 28 Apr 2023 14:32:00 -0500 Subject: [PATCH 04/12] Wave 3 complete --- app/__init__.py | 4 +- app/routes.py | 130 ++++++++++++++++++++++++++++++------------------ 2 files changed, 83 insertions(+), 51 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index b10391993..9802d76f5 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -15,8 +15,8 @@ def create_app(test_config=None): migrate.init_app(app, db) from app.models.planet import Planet - from .routes import planet_bp + from .routes import planets_bp # app.register_blueprint(planet_bp) - app.register_blueprint(planet_bp) + app.register_blueprint(planets_bp) return app diff --git a/app/routes.py b/app/routes.py index 6830e97c3..f64371947 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,51 +1,83 @@ -from flask import Blueprint, jsonify, make_response, abort - -class Planet: - def __init__(self, id, name, description, distance): - self.id = id - self.name = name - self.description = description - self.distance = distance - self.dictionary = {"id" : id, "name" : name, "description": description, "distance": distance} - -planets = [ - Planet(1, 'Mercury', 'Rocky', '38 million'), - Planet(2, 'Venus', 'Cloudy', '66 million'), - Planet(3, 'Earth', 'Home', '92 million'), - Planet(4, 'Mars', 'Red', '141 million'), - Planet(5, 'Jupiter','Spotty', '483 million'), - Planet(6, 'Saturn', 'Rings', '890 million'), - Planet(7, 'Uranus', 'Ice Giant', '1.7 billion'), - Planet(8, 'Neptune', 'Dense Ice', '2.7 billion'), - Planet(9, 'Pluto', 'Dwarf Planet', '3.7 billion') - -] - -planet_bp = Blueprint("planet_bp", __name__, url_prefix="/planets") - -@planet_bp.route("", methods=["GET"]) -def get_planets(): - planet_list = [] - for planet in planets: - planet_list.append( - { - "id" : planet.id, - "name" : planet.name, - "description" : planet.description, - "distance" : planet.distance - } +from app import db +from app.models.planet import Planet +from flask import Blueprint, jsonify, abort, make_response, request + +planets_bp = Blueprint("planets", __name__, url_prefix="/planets") + +@planets_bp.route("", methods=["POST"]) +def create_planet(): + request_body = request.get_json() + new_planet = Planet ( + name=request_body["name"], + description=request_body["description"], + distance=request_body["distance"] ) - return jsonify(planet_list) - -@planet_bp.route("/", methods=["GET"]) -def get_planet(planet_id): - try: - planet_id = int(planet_id) - except: - abort(make_response({"message" : f"book {planet_id} invalid"}, 400)) - - for planet in planets: - if planet.id == planet_id: - return planet.dictionary + db.session.add(new_planet) + db.session.commit() + + return make_response(f"Planet {new_planet.name} successfully created", 201) + +@planets_bp.route("", methods=["GET"]) +def read_all_planets(): + planets = Planet.query.all() + planets_response = [] + for planet in planets: + planets_response.append({ + "id": planet.id, + "name": planet.name, + "description": planet.description, + "distance": planet.distance + }) + return jsonify(planets_response) + + + +# class Planet: +# def __init__(self, id, name, description, distance): +# self.id = id +# self.name = name +# self.description = description +# self.distance = distance +# self.dictionary = {"id" : id, "name" : name, "description": description, "distance": distance} + +# planets = [ +# Planet(1, 'Mercury', 'Rocky', '38 million'), +# Planet(2, 'Venus', 'Cloudy', '66 million'), +# Planet(3, 'Earth', 'Home', '92 million'), +# Planet(4, 'Mars', 'Red', '141 million'), +# Planet(5, 'Jupiter','Spotty', '483 million'), +# Planet(6, 'Saturn', 'Rings', '890 million'), +# Planet(7, 'Uranus', 'Ice Giant', '1.7 billion'), +# Planet(8, 'Neptune', 'Dense Ice', '2.7 billion'), +# Planet(9, 'Pluto', 'Dwarf Planet', '3.7 billion') + +# ] + +# planet_bp = Blueprint("planet_bp", __name__, url_prefix="/planets") + +# @planet_bp.route("", methods=["GET"]) +# def get_planets(): +# planet_list = [] +# for planet in planets: +# planet_list.append( +# { +# "id" : planet.id, +# "name" : planet.name, +# "description" : planet.description, +# "distance" : planet.distance +# } +# ) +# return jsonify(planet_list) + +# @planet_bp.route("/", methods=["GET"]) +# def get_planet(planet_id): +# try: +# planet_id = int(planet_id) +# except: +# abort(make_response({"message" : f"book {planet_id} invalid"}, 400)) + +# for planet in planets: +# if planet.id == planet_id: +# return planet.dictionary - abort(make_response({"message":f"planet {planet_id} not found"}, 404)) \ No newline at end of file +# abort(make_response({"message":f"planet {planet_id} not found"}, 404)) \ No newline at end of file From c8c0a16b16988a4f9c47df614657d3733dcd6e7b Mon Sep 17 00:00:00 2001 From: Virginia Ramos Date: Tue, 2 May 2023 12:50:34 -0500 Subject: [PATCH 05/12] Wave 4 complete --- app/routes.py | 60 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/app/routes.py b/app/routes.py index f64371947..b541ab869 100644 --- a/app/routes.py +++ b/app/routes.py @@ -4,6 +4,21 @@ planets_bp = Blueprint("planets", __name__, url_prefix="/planets") +#helper functions +def validate_planet(planet_id): + try: + planet_id = int(planet_id) + except: + abort(make_response({"message" : f"planet {planet_id} invalid"}, 400)) + + planet = Planet.query.get(planet_id) + + if not planet: + abort(make_response({"message":f"planet {planet_id} not found"}, 404)) + + return planet + +#route functions @planets_bp.route("", methods=["POST"]) def create_planet(): request_body = request.get_json() @@ -30,6 +45,39 @@ def read_all_planets(): }) return jsonify(planets_response) +@planets_bp.route("/", methods=["GET"]) +def read_one_planet(planet_id): + planet = validate_planet(planet_id) + return { + "id": planet.id, + "name": planet.name, + "description": planet.description, + "distance":planet.distance + } + +@planets_bp.route("/", methods=["PUT"]) +def update_planet(planet_id): + planet = validate_planet(planet_id) + + request_body = request.get_json() + + planet.name = request_body["name"] + planet.description = request_body["description"] + planet.distance = request_body["distance"] + + db.session.commit() + + return make_response(f"Planet #{planet_id} succesfully updated") + +@planets_bp.route("/", methods=["DELETE"]) +def delete_planet(planet_id): + planet = validate_planet(planet_id) + + db.session.delete(planet) + db.session.commit() + + return make_response(f"Planet #{planet_id} succesfully deleted") + # class Planet: @@ -69,15 +117,3 @@ def read_all_planets(): # ) # return jsonify(planet_list) -# @planet_bp.route("/", methods=["GET"]) -# def get_planet(planet_id): -# try: -# planet_id = int(planet_id) -# except: -# abort(make_response({"message" : f"book {planet_id} invalid"}, 400)) - -# for planet in planets: -# if planet.id == planet_id: -# return planet.dictionary - -# abort(make_response({"message":f"planet {planet_id} not found"}, 404)) \ No newline at end of file From 3a0b711f407af4460cef7757f6f975a141d2ceba Mon Sep 17 00:00:00 2001 From: Virginia Ramos Date: Tue, 2 May 2023 13:17:27 -0500 Subject: [PATCH 06/12] Wave 4 with if for create_planet --- app/routes.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/routes.py b/app/routes.py index b541ab869..0d0cfce46 100644 --- a/app/routes.py +++ b/app/routes.py @@ -23,10 +23,25 @@ def validate_planet(planet_id): def create_planet(): request_body = request.get_json() new_planet = Planet ( - name=request_body["name"], - description=request_body["description"], - distance=request_body["distance"] - ) + name=request_body["name"], + description=request_body["description"], + distance=request_body["distance"] + ) + + # if request_body.get("id"): + # new_planet = Planet ( + # id = request_body["id"], + # name=request_body["name"], + # description=request_body["description"], + # distance=request_body["distance"] + # ) + # else: + # new_planet = Planet ( + # name=request_body["name"], + # description=request_body["description"], + # distance=request_body["distance"] + # ) + db.session.add(new_planet) db.session.commit() From 79be922dfb97b03b1c6e8c362f99fb87a1ba0da3 Mon Sep 17 00:00:00 2001 From: Gweneth Johnson Date: Wed, 3 May 2023 11:14:22 -0700 Subject: [PATCH 07/12] made helper function to dict --- app/routes.py | 23 +++++----- migrations/README | 2 +- migrations/alembic.ini | 7 ++- migrations/env.py | 44 ++++++++++++------- ..._adds_planet_model.py => 2774090a3bfd_.py} | 8 ++-- 5 files changed, 51 insertions(+), 33 deletions(-) rename migrations/versions/{afee522f3200_adds_planet_model.py => 2774090a3bfd_.py} (87%) diff --git a/app/routes.py b/app/routes.py index 0d0cfce46..2589c74ca 100644 --- a/app/routes.py +++ b/app/routes.py @@ -5,6 +5,13 @@ planets_bp = Blueprint("planets", __name__, url_prefix="/planets") #helper functions +def to_dict(planet): + return ({"id": planet.id, + "name": planet.name, + "description": planet.description, + "distance": planet.distance}) + + def validate_planet(planet_id): try: planet_id = int(planet_id) @@ -52,23 +59,15 @@ def read_all_planets(): planets = Planet.query.all() planets_response = [] for planet in planets: - planets_response.append({ - "id": planet.id, - "name": planet.name, - "description": planet.description, - "distance": planet.distance - }) + planets_response.append( + to_dict(planet) + ) return jsonify(planets_response) @planets_bp.route("/", methods=["GET"]) def read_one_planet(planet_id): planet = validate_planet(planet_id) - return { - "id": planet.id, - "name": planet.name, - "description": planet.description, - "distance":planet.distance - } + return to_dict(planet) @planets_bp.route("/", methods=["PUT"]) def update_planet(planet_id): diff --git a/migrations/README b/migrations/README index 98e4f9c44..0e0484415 100644 --- a/migrations/README +++ b/migrations/README @@ -1 +1 @@ -Generic single-database configuration. \ No newline at end of file +Single-database configuration for Flask. diff --git a/migrations/alembic.ini b/migrations/alembic.ini index f8ed4801f..ec9d45c26 100644 --- a/migrations/alembic.ini +++ b/migrations/alembic.ini @@ -11,7 +11,7 @@ # Logging configuration [loggers] -keys = root,sqlalchemy,alembic +keys = root,sqlalchemy,alembic,flask_migrate [handlers] keys = console @@ -34,6 +34,11 @@ level = INFO handlers = qualname = alembic +[logger_flask_migrate] +level = INFO +handlers = +qualname = flask_migrate + [handler_console] class = StreamHandler args = (sys.stderr,) diff --git a/migrations/env.py b/migrations/env.py index 8b3fb3353..89f80b211 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -1,10 +1,6 @@ -from __future__ import with_statement - import logging from logging.config import fileConfig -from sqlalchemy import engine_from_config -from sqlalchemy import pool from flask import current_app from alembic import context @@ -18,14 +14,30 @@ fileConfig(config.config_file_name) logger = logging.getLogger('alembic.env') + +def get_engine(): + try: + # this works with Flask-SQLAlchemy<3 and Alchemical + return current_app.extensions['migrate'].db.get_engine() + except TypeError: + # this works with Flask-SQLAlchemy>=3 + return current_app.extensions['migrate'].db.engine + + +def get_engine_url(): + try: + return get_engine().url.render_as_string(hide_password=False).replace( + '%', '%%') + except AttributeError: + return str(get_engine().url).replace('%', '%%') + + # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata -config.set_main_option( - 'sqlalchemy.url', - str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%')) -target_metadata = current_app.extensions['migrate'].db.metadata +config.set_main_option('sqlalchemy.url', get_engine_url()) +target_db = current_app.extensions['migrate'].db # other values from the config, defined by the needs of env.py, # can be acquired: @@ -33,6 +45,12 @@ # ... etc. +def get_metadata(): + if hasattr(target_db, 'metadatas'): + return target_db.metadatas[None] + return target_db.metadata + + def run_migrations_offline(): """Run migrations in 'offline' mode. @@ -47,7 +65,7 @@ def run_migrations_offline(): """ url = config.get_main_option("sqlalchemy.url") context.configure( - url=url, target_metadata=target_metadata, literal_binds=True + url=url, target_metadata=get_metadata(), literal_binds=True ) with context.begin_transaction(): @@ -72,16 +90,12 @@ def process_revision_directives(context, revision, directives): directives[:] = [] logger.info('No changes in schema detected.') - connectable = engine_from_config( - config.get_section(config.config_ini_section), - prefix='sqlalchemy.', - poolclass=pool.NullPool, - ) + connectable = get_engine() with connectable.connect() as connection: context.configure( connection=connection, - target_metadata=target_metadata, + target_metadata=get_metadata(), process_revision_directives=process_revision_directives, **current_app.extensions['migrate'].configure_args ) diff --git a/migrations/versions/afee522f3200_adds_planet_model.py b/migrations/versions/2774090a3bfd_.py similarity index 87% rename from migrations/versions/afee522f3200_adds_planet_model.py rename to migrations/versions/2774090a3bfd_.py index b8af39c5e..5632884c2 100644 --- a/migrations/versions/afee522f3200_adds_planet_model.py +++ b/migrations/versions/2774090a3bfd_.py @@ -1,8 +1,8 @@ -"""Adds Planet model +"""empty message -Revision ID: afee522f3200 +Revision ID: 2774090a3bfd Revises: -Create Date: 2023-04-28 13:14:20.124726 +Create Date: 2023-05-01 16:54:01.740082 """ from alembic import op @@ -10,7 +10,7 @@ # revision identifiers, used by Alembic. -revision = 'afee522f3200' +revision = '2774090a3bfd' down_revision = None branch_labels = None depends_on = None From e6412ecb535cda78726ae514d47f7d27262e9887 Mon Sep 17 00:00:00 2001 From: Gweneth Johnson Date: Wed, 3 May 2023 12:31:45 -0700 Subject: [PATCH 08/12] created tests still an error --- app/__init__.py | 20 ++++++++++++++++++-- tests/__init__.py | 0 tests/conftest.py | 36 +++++++++++++++++++++++++++++++++++ tests/test_routes.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ touch | 0 5 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py create mode 100644 tests/test_routes.py create mode 100644 touch diff --git a/app/__init__.py b/app/__init__.py index 9802d76f5..4819984e0 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,18 +1,34 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate +from dotenv import load_dotenv +import os + db = SQLAlchemy() migrate = Migrate() +load_dotenv() def create_app(test_config=None): app = Flask(__name__) - app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False - app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres:postgres@localhost:5432/solar_system_development' + if not test_config: + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False + app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get("SQLALCHEMY_DATABASE_URI") + + else: + app.config["TESTING"] = True + app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False + app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( + "SQLALCHEMY_TEST_DATABASE_URI") + + + # app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False + # app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres:postgres@localhost:5432/solar_system_development' db.init_app(app) migrate.init_app(app, db) + from app.models.planet import Planet from .routes import planets_bp diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 000000000..47eb63388 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,36 @@ +import pytest +from app import create_app +from app import db +from flask.signals import request_finished +from app.models.planet import Planet + +@pytest.fixture +def app(): + app = create_app({"TESTING": True}) + + @request_finished.connect_via(app) + def expire_session(sender, response, **extra): + db.session.remove() + + with app.app_context(): + db.create_all() + yield app + + with app.app_context(): + db.drop_all() + + +@pytest.fixture +def client(app): + return app.test_client() + +@pytest.fixture +def one_saved_planets(app): + # Arrange + dolphini_planet = Planet(name="Dolphini", description="Exoplanet", distance= "100 billion miles") + + + db.session.add(dolphini_planet) + db.session.commit() + + return dolphini_planet \ No newline at end of file diff --git a/tests/test_routes.py b/tests/test_routes.py new file mode 100644 index 000000000..b38e79650 --- /dev/null +++ b/tests/test_routes.py @@ -0,0 +1,45 @@ +from app.models.planet import Planet + +def test_get_planets_returns_empty_list_when_db_is_empty(client): + response = client.get("/planets") + response_body = response.get_json() + + assert response.status_code == 200 + assert response_body == [] + +def test_get_one_planet(client, one_planet): + + response = client.get(f"/planets/{one_planet.id}") + response_body = response.get_json() + + assert response.status_code == 200 + assert response_body["id"] == one_planet.id + assert response_body["name"] == one_planet.name + assert response_body["description"] == one_planet.description + assert response_body["distance"] == one_planet.distance + + +def test_get_one_empty_planet(client): + + response = client.get("/planets/1") + response_body = response.get_json() + + assert response.status_code == 404 + assert response_body == {"message":f"planet 1 not found"}, 404 + +def test_create_planet_creates_planet(client): + EXPECTED_PLANET = { + "name" : "Draconis", + "description" : "Arion", + "distance" : "150 billion miles" + } + + response = client.post("/planets", json=EXPECTED_PLANET) + response_body = response.get_data(as_text=True) + + actual_planet = Planet.query.get(1) + assert response.status_code == 201 + assert response_body == f"Planet {EXPECTED_PLANET['name']} successfully created" + assert actual_planet.name == EXPECTED_PLANET["name"] + assert actual_planet.description == EXPECTED_PLANET["description"] + assert actual_planet.distance == EXPECTED_PLANET["distance"] \ No newline at end of file diff --git a/touch b/touch new file mode 100644 index 000000000..e69de29bb From d36566ec3669a2bc52882b82302547c5d0cedd50 Mon Sep 17 00:00:00 2001 From: Gweneth Johnson Date: Wed, 3 May 2023 13:03:48 -0700 Subject: [PATCH 09/12] finished 4 tests and changed conftest get saved planets to one planet --- tests/conftest.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 47eb63388..e317f106d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,5 @@ import pytest -from app import create_app -from app import db +from app import create_app, db from flask.signals import request_finished from app.models.planet import Planet @@ -25,7 +24,7 @@ def client(app): return app.test_client() @pytest.fixture -def one_saved_planets(app): +def one_planet(app): # Arrange dolphini_planet = Planet(name="Dolphini", description="Exoplanet", distance= "100 billion miles") From 9ee2e7db34d3626df34822f78de273f256d9a132 Mon Sep 17 00:00:00 2001 From: Gweneth Johnson Date: Thu, 4 May 2023 12:18:18 -0700 Subject: [PATCH 10/12] wrote 2 more tests and refactored several functions --- app/models/planet.py | 16 +++++- app/routes.py | 131 ++++++++++++++----------------------------- tests/conftest.py | 1 - tests/test_routes.py | 20 ++++++- 4 files changed, 75 insertions(+), 93 deletions(-) diff --git a/app/models/planet.py b/app/models/planet.py index dfd00209b..459e324c3 100644 --- a/app/models/planet.py +++ b/app/models/planet.py @@ -4,4 +4,18 @@ class Planet(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), nullable=False) description = db.Column(db.Text, nullable=False) - distance = db.Column(db.String(255), nullable=False) \ No newline at end of file + distance = db.Column(db.String(255), nullable=False) + + def to_dict(self): + return ({"id": self.id, + "name": self.name, + "description": self.description, + "distance": self.distance}) + + @classmethod + def from_dict(cls, data_dict): + return cls( + name = data_dict["name"], + description = data_dict["description"], + distance = data_dict["distance"] + ) \ No newline at end of file diff --git a/app/routes.py b/app/routes.py index 2589c74ca..0a4cd93b4 100644 --- a/app/routes.py +++ b/app/routes.py @@ -4,50 +4,36 @@ planets_bp = Blueprint("planets", __name__, url_prefix="/planets") -#helper functions -def to_dict(planet): - return ({"id": planet.id, - "name": planet.name, - "description": planet.description, - "distance": planet.distance}) - -def validate_planet(planet_id): +def validate_model(cls, model_id): try: - planet_id = int(planet_id) + model_id = int(model_id) except: - abort(make_response({"message" : f"planet {planet_id} invalid"}, 400)) + message = f"{cls.__name__} {model_id} is invalid" + abort(make_response({"message" : message}, 400)) - planet = Planet.query.get(planet_id) + model = cls.query.get(model_id) - if not planet: - abort(make_response({"message":f"planet {planet_id} not found"}, 404)) + if not model: + message = f"{cls.__name__} {model_id} not found" + abort(make_response({"message": message}, 404)) - return planet + return model #route functions @planets_bp.route("", methods=["POST"]) def create_planet(): - request_body = request.get_json() - new_planet = Planet ( - name=request_body["name"], - description=request_body["description"], - distance=request_body["distance"] - ) + request_body = request.get_json() + try: + new_planet = Planet.from_dict(request_body) + db.session.add(new_planet) + db.session.commit() + + message = f"Planet {new_planet.name} successfully created" + return make_response(message, 201) - # if request_body.get("id"): - # new_planet = Planet ( - # id = request_body["id"], - # name=request_body["name"], - # description=request_body["description"], - # distance=request_body["distance"] - # ) - # else: - # new_planet = Planet ( - # name=request_body["name"], - # description=request_body["description"], - # distance=request_body["distance"] - # ) + except KeyError as e: + abort(make_response({"message": f"missing required value: {e}"}, 400)) db.session.add(new_planet) db.session.commit() @@ -55,37 +41,42 @@ def create_planet(): return make_response(f"Planet {new_planet.name} successfully created", 201) @planets_bp.route("", methods=["GET"]) -def read_all_planets(): +def get_all_planets(): + name_query = request.args.get("name") + description_query = request.args.get("description") + if name_query: + planets = Planet.query.filter_by(name = name_query) + elif description_query: + planets = Planet.query.filter_by(description = description_query) + else: planets = Planet.query.all() - planets_response = [] - for planet in planets: - planets_response.append( - to_dict(planet) - ) - return jsonify(planets_response) + + results = [planet.to_dict() for planet in planets] + return jsonify(results) + + @planets_bp.route("/", methods=["GET"]) -def read_one_planet(planet_id): - planet = validate_planet(planet_id) - return to_dict(planet) +def get_one_planet(planet_id): + planet = validate_model(Planet, planet_id) + return planet.to_dict() @planets_bp.route("/", methods=["PUT"]) def update_planet(planet_id): - planet = validate_planet(planet_id) + planet_data = request.get_json() + planet_to_update = validate_model(Planet, planet_id) - request_body = request.get_json() - - planet.name = request_body["name"] - planet.description = request_body["description"] - planet.distance = request_body["distance"] + planet_to_update.name = planet_data["name"] + planet_to_update.description = planet_data["description"] + planet_to_update.distance = planet_data["distance"] db.session.commit() - return make_response(f"Planet #{planet_id} succesfully updated") + return make_response(f"Planet {planet_to_update.name} succesfully updated", 200) @planets_bp.route("/", methods=["DELETE"]) def delete_planet(planet_id): - planet = validate_planet(planet_id) + planet = validate_model(Planet, planet_id) db.session.delete(planet) db.session.commit() @@ -93,41 +84,3 @@ def delete_planet(planet_id): return make_response(f"Planet #{planet_id} succesfully deleted") - -# class Planet: -# def __init__(self, id, name, description, distance): -# self.id = id -# self.name = name -# self.description = description -# self.distance = distance -# self.dictionary = {"id" : id, "name" : name, "description": description, "distance": distance} - -# planets = [ -# Planet(1, 'Mercury', 'Rocky', '38 million'), -# Planet(2, 'Venus', 'Cloudy', '66 million'), -# Planet(3, 'Earth', 'Home', '92 million'), -# Planet(4, 'Mars', 'Red', '141 million'), -# Planet(5, 'Jupiter','Spotty', '483 million'), -# Planet(6, 'Saturn', 'Rings', '890 million'), -# Planet(7, 'Uranus', 'Ice Giant', '1.7 billion'), -# Planet(8, 'Neptune', 'Dense Ice', '2.7 billion'), -# Planet(9, 'Pluto', 'Dwarf Planet', '3.7 billion') - -# ] - -# planet_bp = Blueprint("planet_bp", __name__, url_prefix="/planets") - -# @planet_bp.route("", methods=["GET"]) -# def get_planets(): -# planet_list = [] -# for planet in planets: -# planet_list.append( -# { -# "id" : planet.id, -# "name" : planet.name, -# "description" : planet.description, -# "distance" : planet.distance -# } -# ) -# return jsonify(planet_list) - diff --git a/tests/conftest.py b/tests/conftest.py index e317f106d..a82262c6b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -25,7 +25,6 @@ def client(app): @pytest.fixture def one_planet(app): - # Arrange dolphini_planet = Planet(name="Dolphini", description="Exoplanet", distance= "100 billion miles") diff --git a/tests/test_routes.py b/tests/test_routes.py index b38e79650..c3f9baafc 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -1,4 +1,8 @@ from app.models.planet import Planet +from app.routes import validate_model +from werkzeug.exceptions import HTTPException +import pytest + def test_get_planets_returns_empty_list_when_db_is_empty(client): response = client.get("/planets") @@ -25,7 +29,7 @@ def test_get_one_empty_planet(client): response_body = response.get_json() assert response.status_code == 404 - assert response_body == {"message":f"planet 1 not found"}, 404 + assert response_body == {"message":f"Planet 1 not found"}, 404 def test_create_planet_creates_planet(client): EXPECTED_PLANET = { @@ -42,4 +46,16 @@ def test_create_planet_creates_planet(client): assert response_body == f"Planet {EXPECTED_PLANET['name']} successfully created" assert actual_planet.name == EXPECTED_PLANET["name"] assert actual_planet.description == EXPECTED_PLANET["description"] - assert actual_planet.distance == EXPECTED_PLANET["distance"] \ No newline at end of file + assert actual_planet.distance == EXPECTED_PLANET["distance"] + +def test_validate_model_returns_invalid_with_invalid_id(client): + with pytest.raises(HTTPException): + result_planet = validate_model(Planet, "planet") + +def test_delete_planet_missing_record(client, one_planet): + response = client.delete("/planets/35") + response_body = response.get_json() + + assert response.status_code == 404 + assert response_body == {"message" : "Planet 35 not found"} + \ No newline at end of file From eb55d0981e31eea214df60db3ce35768e46c2663 Mon Sep 17 00:00:00 2001 From: Gweneth Johnson Date: Mon, 8 May 2023 14:54:13 -0700 Subject: [PATCH 11/12] added moons model and two routes one get and post --- app/models/moon.py | 24 +++++++++++++++++++ app/models/planet.py | 11 ++++++++- app/routes.py | 25 +++++++++++++++++++ migrations/versions/adeafd0d3146_.py | 36 ++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 app/models/moon.py create mode 100644 migrations/versions/adeafd0d3146_.py diff --git a/app/models/moon.py b/app/models/moon.py new file mode 100644 index 000000000..3d1f4ccbe --- /dev/null +++ b/app/models/moon.py @@ -0,0 +1,24 @@ +from app import db + +class Moon(db.Model): + id = db.Column(db.Integer, primary_key=True, autoincrement=True) + name = db.Column(db.String(255), nullable=False) + description = db.Column(db.Text, nullable=False) + size = db.Column(db.String(255), nullable=False) + planet_id = db.Column(db.Integer, db.ForeignKey("planet.id")) + planet = db.relationship("Planet", back_populates="moons") + + + def to_dict(self): + return ({"id": self.id, + "name": self.name, + "description": self.description, + "size": self.size}) + + @classmethod + def from_dict(cls, data_dict): + return cls( + name = data_dict["name"], + description = data_dict["description"], + size = data_dict["size"] + ) \ No newline at end of file diff --git a/app/models/planet.py b/app/models/planet.py index 459e324c3..013cd6409 100644 --- a/app/models/planet.py +++ b/app/models/planet.py @@ -5,12 +5,21 @@ class Planet(db.Model): name = db.Column(db.String(255), nullable=False) description = db.Column(db.Text, nullable=False) distance = db.Column(db.String(255), nullable=False) + moons = db.relationship("Moon", back_populates="planet") def to_dict(self): + moon_data = [] + if self.moons: + for moon in self.moons: + moon_data.append(moon.to_dict()) + + + return ({"id": self.id, "name": self.name, "description": self.description, - "distance": self.distance}) + "distance": self.distance, + "moons" : moon_data}) @classmethod def from_dict(cls, data_dict): diff --git a/app/routes.py b/app/routes.py index 0a4cd93b4..4f0ffcdae 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,5 +1,6 @@ from app import db from app.models.planet import Planet +from app.models.moon import Moon from flask import Blueprint, jsonify, abort, make_response, request planets_bp = Blueprint("planets", __name__, url_prefix="/planets") @@ -54,6 +55,16 @@ def get_all_planets(): results = [planet.to_dict() for planet in planets] return jsonify(results) +@planets_bp.route("/moons", methods=["GET"]) +def read_moons(planet_id): + planet = validate_model(Planet, planet_id) + + planet_response = [] + for moon in planet.moons: + planet_response.append(moon.to_dict()) + + return(jsonify(planet_response)) + @planets_bp.route("/", methods=["GET"]) @@ -84,3 +95,17 @@ def delete_planet(planet_id): return make_response(f"Planet #{planet_id} succesfully deleted") +@planets_bp.route("/moons", methods=["POST"]) +def create_moon(planet_id): + planet = validate_model(Planet, planet_id) + request_body = request.get_json() + try: + new_moon = Moon.from_dict(request_body) + new_moon.planet = planet + + db.session.add(new_moon) + db.session.commit() + + return make_response(jsonify(f"Moon {new_moon.name} cared by {planet.name} successfully created"), 201) + except KeyError as e: + abort(make_response({"message": f"missing required value: {e}"}, 400)) \ No newline at end of file diff --git a/migrations/versions/adeafd0d3146_.py b/migrations/versions/adeafd0d3146_.py new file mode 100644 index 000000000..d0e63f302 --- /dev/null +++ b/migrations/versions/adeafd0d3146_.py @@ -0,0 +1,36 @@ +"""empty message + +Revision ID: adeafd0d3146 +Revises: 2774090a3bfd +Create Date: 2023-05-08 14:34:48.161540 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'adeafd0d3146' +down_revision = '2774090a3bfd' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('moon', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('description', sa.Text(), nullable=False), + sa.Column('size', sa.String(length=255), nullable=False), + sa.Column('planet_id', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['planet_id'], ['planet.id'], ), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('moon') + # ### end Alembic commands ### From d4b8b3d78bc89d951365116402bed3a73b35d54f Mon Sep 17 00:00:00 2001 From: Virginia Ramos Date: Tue, 9 May 2023 13:17:02 -0500 Subject: [PATCH 12/12] Deployment --- migrations/README | 2 +- migrations/alembic.ini | 7 +---- migrations/env.py | 44 ++++++++++------------------ migrations/versions/2774090a3bfd_.py | 34 --------------------- migrations/versions/adeafd0d3146_.py | 36 ----------------------- requirements.txt | 7 +++++ 6 files changed, 24 insertions(+), 106 deletions(-) delete mode 100644 migrations/versions/2774090a3bfd_.py delete mode 100644 migrations/versions/adeafd0d3146_.py diff --git a/migrations/README b/migrations/README index 0e0484415..98e4f9c44 100644 --- a/migrations/README +++ b/migrations/README @@ -1 +1 @@ -Single-database configuration for Flask. +Generic single-database configuration. \ No newline at end of file diff --git a/migrations/alembic.ini b/migrations/alembic.ini index ec9d45c26..f8ed4801f 100644 --- a/migrations/alembic.ini +++ b/migrations/alembic.ini @@ -11,7 +11,7 @@ # Logging configuration [loggers] -keys = root,sqlalchemy,alembic,flask_migrate +keys = root,sqlalchemy,alembic [handlers] keys = console @@ -34,11 +34,6 @@ level = INFO handlers = qualname = alembic -[logger_flask_migrate] -level = INFO -handlers = -qualname = flask_migrate - [handler_console] class = StreamHandler args = (sys.stderr,) diff --git a/migrations/env.py b/migrations/env.py index 89f80b211..8b3fb3353 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -1,6 +1,10 @@ +from __future__ import with_statement + import logging from logging.config import fileConfig +from sqlalchemy import engine_from_config +from sqlalchemy import pool from flask import current_app from alembic import context @@ -14,30 +18,14 @@ fileConfig(config.config_file_name) logger = logging.getLogger('alembic.env') - -def get_engine(): - try: - # this works with Flask-SQLAlchemy<3 and Alchemical - return current_app.extensions['migrate'].db.get_engine() - except TypeError: - # this works with Flask-SQLAlchemy>=3 - return current_app.extensions['migrate'].db.engine - - -def get_engine_url(): - try: - return get_engine().url.render_as_string(hide_password=False).replace( - '%', '%%') - except AttributeError: - return str(get_engine().url).replace('%', '%%') - - # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata -config.set_main_option('sqlalchemy.url', get_engine_url()) -target_db = current_app.extensions['migrate'].db +config.set_main_option( + 'sqlalchemy.url', + str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%')) +target_metadata = current_app.extensions['migrate'].db.metadata # other values from the config, defined by the needs of env.py, # can be acquired: @@ -45,12 +33,6 @@ def get_engine_url(): # ... etc. -def get_metadata(): - if hasattr(target_db, 'metadatas'): - return target_db.metadatas[None] - return target_db.metadata - - def run_migrations_offline(): """Run migrations in 'offline' mode. @@ -65,7 +47,7 @@ def run_migrations_offline(): """ url = config.get_main_option("sqlalchemy.url") context.configure( - url=url, target_metadata=get_metadata(), literal_binds=True + url=url, target_metadata=target_metadata, literal_binds=True ) with context.begin_transaction(): @@ -90,12 +72,16 @@ def process_revision_directives(context, revision, directives): directives[:] = [] logger.info('No changes in schema detected.') - connectable = get_engine() + 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=get_metadata(), + target_metadata=target_metadata, process_revision_directives=process_revision_directives, **current_app.extensions['migrate'].configure_args ) diff --git a/migrations/versions/2774090a3bfd_.py b/migrations/versions/2774090a3bfd_.py deleted file mode 100644 index 5632884c2..000000000 --- a/migrations/versions/2774090a3bfd_.py +++ /dev/null @@ -1,34 +0,0 @@ -"""empty message - -Revision ID: 2774090a3bfd -Revises: -Create Date: 2023-05-01 16:54:01.740082 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '2774090a3bfd' -down_revision = None -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table('planet', - sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', sa.Text(), nullable=False), - sa.Column('distance', sa.String(length=255), nullable=False), - sa.PrimaryKeyConstraint('id') - ) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_table('planet') - # ### end Alembic commands ### diff --git a/migrations/versions/adeafd0d3146_.py b/migrations/versions/adeafd0d3146_.py deleted file mode 100644 index d0e63f302..000000000 --- a/migrations/versions/adeafd0d3146_.py +++ /dev/null @@ -1,36 +0,0 @@ -"""empty message - -Revision ID: adeafd0d3146 -Revises: 2774090a3bfd -Create Date: 2023-05-08 14:34:48.161540 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'adeafd0d3146' -down_revision = '2774090a3bfd' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table('moon', - sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', sa.Text(), nullable=False), - sa.Column('size', sa.String(length=255), nullable=False), - sa.Column('planet_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['planet_id'], ['planet.id'], ), - sa.PrimaryKeyConstraint('id') - ) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_table('moon') - # ### end Alembic commands ### diff --git a/requirements.txt b/requirements.txt index ae59e7b55..f4ff77124 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,14 +4,20 @@ blinker==1.4 certifi==2020.12.5 chardet==4.0.0 click==7.1.2 +coverage==7.2.3 +exceptiongroup==1.1.1 Flask==1.1.2 Flask-Migrate==2.6.0 Flask-SQLAlchemy==2.4.4 +gunicorn==20.1.0 idna==2.10 +iniconfig==2.0.0 itsdangerous==1.1.0 Jinja2==2.11.3 Mako==1.1.4 MarkupSafe==1.1.1 +packaging==23.1 +pluggy==1.0.0 psycopg2-binary==2.9.5 pycodestyle==2.6.0 pytest==7.3.1 @@ -23,5 +29,6 @@ requests==2.25.1 six==1.15.0 SQLAlchemy==1.3.23 toml==0.10.2 +tomli==2.0.1 urllib3==1.26.4 Werkzeug==1.0.1