From bcd2e1ec5de9ab273b1a5bff41deff1c04644e74 Mon Sep 17 00:00:00 2001 From: Brittany Clemons Date: Tue, 4 May 2021 21:18:45 -0700 Subject: [PATCH 1/9] created task endpoint --- app/__init__.py | 7 +- app/models/task.py | 5 +- app/routes.py | 35 +++++++++- migrations/README | 1 + migrations/alembic.ini | 45 +++++++++++++ migrations/env.py | 96 ++++++++++++++++++++++++++++ migrations/script.py.mako | 24 +++++++ migrations/versions/f92a2eea5f0d_.py | 38 +++++++++++ requirements.txt | 8 +-- 9 files changed, 250 insertions(+), 9 deletions(-) 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/f92a2eea5f0d_.py diff --git a/app/__init__.py b/app/__init__.py index 2764c4cc8..ccd441d58 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -22,13 +22,16 @@ def create_app(test_config=None): app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( "SQLALCHEMY_TEST_DATABASE_URI") + db.init_app(app) + migrate.init_app(app, db) + # Import models here for Alembic setup from app.models.task import Task from app.models.goal import Goal - db.init_app(app) - migrate.init_app(app, db) + from .routes import task_bp # Register Blueprints here + app.register_blueprint(task_bp) return app diff --git a/app/models/task.py b/app/models/task.py index 39c89cd16..b26fb4065 100644 --- a/app/models/task.py +++ b/app/models/task.py @@ -3,4 +3,7 @@ class Task(db.Model): - task_id = db.Column(db.Integer, primary_key=True) + id = db.Column(db.Integer, primary_key=True, autoincrement=True) + title = db.Column(db.String) + description = db.Column(db.String) + completed_at = db.DateTime(db.String) \ No newline at end of file diff --git a/app/routes.py b/app/routes.py index 8e9dfe684..7f76e6ca2 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,2 +1,35 @@ -from flask import Blueprint +from app import db +from app.models.task import Task +from flask import request +from flask import request, Blueprint, task_response +from flask import jsonify +task_bp = Blueprint("task", __name__, url_prefix="/task") + +@task_bp.route("", methods=["POST", "GET"], strict_slashes=False) +def task(): + if request.method == "GET": + task = Task.query.all() + task_response = [] + for task in task: + task_response.append({ + "id": task.id, + "title": task.title, + "description": task.description, + "completed_at": task.completed_at + }) + return jsonify(task_response), 200 + + elif request.method == "POST": + request_body = request.get_json() + new_task = Task(title=request_body["title"], + description=request_body["description"], + completed_at=request_body["null"]) + + db.session.add(new_task) + db.session.commit() + + return { + "success" : True, + "message" : f"Task {new_task.name} has been created! wohoo!", + }, 201 \ 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/f92a2eea5f0d_.py b/migrations/versions/f92a2eea5f0d_.py new file mode 100644 index 000000000..a90e74951 --- /dev/null +++ b/migrations/versions/f92a2eea5f0d_.py @@ -0,0 +1,38 @@ +"""empty message + +Revision ID: f92a2eea5f0d +Revises: +Create Date: 2021-05-04 19:17:30.656774 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'f92a2eea5f0d' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('goal', + sa.Column('goal_id', sa.Integer(), nullable=False), + sa.PrimaryKeyConstraint('goal_id') + ) + op.create_table('task', + sa.Column('task_id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('title', sa.String(), nullable=True), + sa.Column('description', sa.String(), nullable=True), + sa.PrimaryKeyConstraint('task_id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('task') + op.drop_table('goal') + # ### end Alembic commands ### diff --git a/requirements.txt b/requirements.txt index cfdf74050..d0b4f7658 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,17 +16,15 @@ Mako==1.1.4 MarkupSafe==1.1.1 packaging==20.9 pluggy==0.13.1 -psycopg2-binary==2.8.6 py==1.10.0 pycodestyle==2.6.0 pyparsing==2.4.7 -pytest==6.2.3 +pytest==6.2.4 python-dateutil==2.8.1 -python-dotenv==0.15.0 +python-dotenv==0.17.1 python-editor==1.0.4 -requests==2.25.1 +rope==0.19.0 six==1.15.0 SQLAlchemy==1.3.23 toml==0.10.2 -urllib3==1.26.4 Werkzeug==1.0.1 From 039ac21a5eea42cce0114e5dd44ca88dbff45a75 Mon Sep 17 00:00:00 2001 From: Brittany Clemons Date: Tue, 4 May 2021 22:44:05 -0700 Subject: [PATCH 2/9] fix psycopg2 --- requirements.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index d0b4f7658..ffcfcb2eb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,15 +16,17 @@ Mako==1.1.4 MarkupSafe==1.1.1 packaging==20.9 pluggy==0.13.1 +psycopg2-binary==2.8.6 py==1.10.0 pycodestyle==2.6.0 pyparsing==2.4.7 -pytest==6.2.4 +pytest==6.2.3 python-dateutil==2.8.1 -python-dotenv==0.17.1 +python-dotenv==0.15.0 python-editor==1.0.4 -rope==0.19.0 +requests==2.25.1 six==1.15.0 SQLAlchemy==1.3.23 toml==0.10.2 -Werkzeug==1.0.1 +urllib3==1.26.4 +Werkzeug==1.0.1 \ No newline at end of file From 9c53996e671bd9c9efbd425d448a456b4f6e9ecd Mon Sep 17 00:00:00 2001 From: Brittany Clemons Date: Thu, 6 May 2021 00:12:05 -0700 Subject: [PATCH 3/9] wave one pass --- app/__init__.py | 3 + app/models/task.py | 20 ++++- app/routes.py | 110 +++++++++++++++++++++++---- migrations/versions/0b0197f93cdf_.py | 28 +++++++ migrations/versions/1cfb6e9ac5ef_.py | 28 +++++++ migrations/versions/1d08448e6c2b_.py | 34 +++++++++ migrations/versions/b30dac682d4f_.py | 28 +++++++ migrations/versions/b5e27277c35f_.py | 28 +++++++ tests/test_wave_01.py | 2 +- 9 files changed, 264 insertions(+), 17 deletions(-) create mode 100644 migrations/versions/0b0197f93cdf_.py create mode 100644 migrations/versions/1cfb6e9ac5ef_.py create mode 100644 migrations/versions/1d08448e6c2b_.py create mode 100644 migrations/versions/b30dac682d4f_.py create mode 100644 migrations/versions/b5e27277c35f_.py diff --git a/app/__init__.py b/app/__init__.py index ccd441d58..63a3bdc84 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,8 +1,10 @@ +import pytest from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate import os from dotenv import load_dotenv +import datetime db = SQLAlchemy() @@ -12,6 +14,7 @@ def create_app(test_config=None): app = Flask(__name__) + app.config['JSON_SORT_KEYS'] = False app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False if test_config is None: diff --git a/app/models/task.py b/app/models/task.py index b26fb4065..2479b6f7d 100644 --- a/app/models/task.py +++ b/app/models/task.py @@ -1,9 +1,27 @@ from flask import current_app from app import db +import datetime +# this is telling flask about my database task table class Task(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String) description = db.Column(db.String) - completed_at = db.DateTime(db.String) \ No newline at end of file + completed_at = db.Column(db.DateTime) + + def completed_at_helper(self): + if self.completed_at == None: + complete = False + else: + complete = True + return complete + + def json_object(self): + return { + "id": self.id, + "title": self.title, + "description": self.description, + "is_complete": self.completed_at_helper() + } + # Use this helper function any time the return is expected to be complete diff --git a/app/routes.py b/app/routes.py index 7f76e6ca2..6e3dbb140 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,35 +1,115 @@ from app import db from app.models.task import Task from flask import request -from flask import request, Blueprint, task_response +from flask import request, Blueprint, make_response from flask import jsonify +import datetime -task_bp = Blueprint("task", __name__, url_prefix="/task") +task_bp = Blueprint("tasks", __name__, url_prefix="/tasks") + + +@task_bp.route("/", methods=["GET", "PUT", "DELETE"], strict_slashes=False) +def get_single_task(task_id): + + task = Task.query.get(task_id) + + if task is None: + return jsonify(None), 404 + + complete = task.completed_at_helper() # Helper function to return boolean -@task_bp.route("", methods=["POST", "GET"], strict_slashes=False) -def task(): if request.method == "GET": - task = Task.query.all() - task_response = [] - for task in task: - task_response.append({ + return jsonify({ + "task": { "id": task.id, "title": task.title, "description": task.description, - "completed_at": task.completed_at - }) + "is_complete": complete + }, + }), 200 + elif request.method == "PUT": + form_data = request.get_json() + + task.title = form_data["title"] + task.description = form_data["description"] + task.is_complete = form_data["completed_at"] # TODO: fix this + + db.session.commit() + return jsonify({ + "task": { + "id": task.id, + "title": task.title, + "description": task.description, + "is_complete": task.completed_at_helper() + } + }), 200 + + elif request.method == "DELETE": + db.session.delete(task) + db.session.commit() + return jsonify({"details": f'Task {task.id} "{task.title}" successfully deleted'}), 200 + + +@task_bp.route("", methods=["GET", "POST"]) +def handle_tasks(): + if request.method == "GET": + tasks = Task.query.all() + task_response = [] + + for task in tasks: + # using jsonobject helper to create a dictionary with id, title, description, isComplete + task_response.append(task.json_object()) return jsonify(task_response), 200 elif request.method == "POST": request_body = request.get_json() + + if "completed_at" not in request_body or "description" not in request_body or "title" not in request_body: + return jsonify({ + "details": "Invalid data" + }), 400 + new_task = Task(title=request_body["title"], description=request_body["description"], - completed_at=request_body["null"]) + completed_at=request_body["completed_at"]) + + db.session.add(new_task) + db.session.commit() + # created a new task and changed my task objet into JSON + # called my new_task.completed_at_helper. + # using jsonobject helper to create a dictionary with id, title, description, isComplete + return jsonify({"task": new_task.json_object()}), 201 db.session.add(new_task) db.session.commit() - return { - "success" : True, - "message" : f"Task {new_task.name} has been created! wohoo!", - }, 201 \ No newline at end of file + +# post man testing eviroment +# # api request using url request can i find route that matches + + +# @task_bp.route("", methods=["POST", "GET"], strict_slashes=False) +# def post_task(): +# if request.method == "POST": +# request_body = request.get_json() + +# if "completed_at" not in request_body or "description" not in request_body or "title" not in request_body: +# return jsonify({ +# "details": "Invalid data" +# }), 400 + +# # This is allowing POSTMAN to test the requesting URL infomation by creating a route +# task = Task(title=request_body["title"], +# description=request_body["description"], +# completed_at=request_body["completed_at"]) +# db.session.add(task) # Session +# db.session.commit() +# complete = task.completed_at_helper() +# return jsonify({ +# "task": { +# "id": 1, +# "title": task.title, +# "description": task.description, +# "is_complete": complete +# } +# }), 201 diff --git a/migrations/versions/0b0197f93cdf_.py b/migrations/versions/0b0197f93cdf_.py new file mode 100644 index 000000000..f7bccb000 --- /dev/null +++ b/migrations/versions/0b0197f93cdf_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: 0b0197f93cdf +Revises: b30dac682d4f +Create Date: 2021-05-05 12:35:41.039681 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '0b0197f93cdf' +down_revision = 'b30dac682d4f' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('task', sa.Column('brittany', sa.String(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('task', 'brittany') + # ### end Alembic commands ### diff --git a/migrations/versions/1cfb6e9ac5ef_.py b/migrations/versions/1cfb6e9ac5ef_.py new file mode 100644 index 000000000..d5ff11b21 --- /dev/null +++ b/migrations/versions/1cfb6e9ac5ef_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: 1cfb6e9ac5ef +Revises: 0b0197f93cdf +Create Date: 2021-05-05 12:37:55.551305 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '1cfb6e9ac5ef' +down_revision = '0b0197f93cdf' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('task', 'brittany') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('task', sa.Column('brittany', sa.VARCHAR(), autoincrement=False, nullable=True)) + # ### end Alembic commands ### diff --git a/migrations/versions/1d08448e6c2b_.py b/migrations/versions/1d08448e6c2b_.py new file mode 100644 index 000000000..f7c8eae63 --- /dev/null +++ b/migrations/versions/1d08448e6c2b_.py @@ -0,0 +1,34 @@ +"""empty message + +Revision ID: 1d08448e6c2b +Revises: f92a2eea5f0d +Create Date: 2021-05-04 22:45:56.813749 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '1d08448e6c2b' +down_revision = 'f92a2eea5f0d' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('task', 'title', + existing_type=sa.VARCHAR(length=200), + nullable=True) + op.drop_column('task', 'completed_at') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('task', sa.Column('completed_at', sa.BOOLEAN(), autoincrement=False, nullable=True)) + op.alter_column('task', 'title', + existing_type=sa.VARCHAR(length=200), + nullable=False) + # ### end Alembic commands ### diff --git a/migrations/versions/b30dac682d4f_.py b/migrations/versions/b30dac682d4f_.py new file mode 100644 index 000000000..b964cede8 --- /dev/null +++ b/migrations/versions/b30dac682d4f_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: b30dac682d4f +Revises: b5e27277c35f +Create Date: 2021-05-05 00:22:39.394816 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'b30dac682d4f' +down_revision = 'b5e27277c35f' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('task', sa.Column('completed_at', sa.DateTime(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('task', 'completed_at') + # ### end Alembic commands ### diff --git a/migrations/versions/b5e27277c35f_.py b/migrations/versions/b5e27277c35f_.py new file mode 100644 index 000000000..81e34e3c5 --- /dev/null +++ b/migrations/versions/b5e27277c35f_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: b5e27277c35f +Revises: 1d08448e6c2b +Create Date: 2021-05-05 00:17:41.643437 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = 'b5e27277c35f' +down_revision = '1d08448e6c2b' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('task', 'completed_at') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('task', sa.Column('completed_at', postgresql.ARRAY(postgresql.TIME()), autoincrement=False, nullable=True, comment='Time stamp when completed ')) + # ### end Alembic commands ### diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index fb943d9b3..b9b401238 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -69,7 +69,7 @@ def test_create_task_with_none_completed_at(client): # Assert assert response.status_code == 201 assert "task" in response_body - assert response_body == { + assert response_body == { "task": { "id": 1, "title": "A Brand New Task", From ef0daf0cabbb4779ff50724017076dd264ea1a2f Mon Sep 17 00:00:00 2001 From: Brittany Clemons Date: Sun, 9 May 2021 21:37:45 -0700 Subject: [PATCH 4/9] Wave 3/ mark_incomplete & mark_complet --- app/models/task.py | 5 ++-- app/routes.py | 74 ++++++++++++++++++---------------------------- 2 files changed, 32 insertions(+), 47 deletions(-) diff --git a/app/models/task.py b/app/models/task.py index 2479b6f7d..4dd75c946 100644 --- a/app/models/task.py +++ b/app/models/task.py @@ -1,6 +1,6 @@ from flask import current_app from app import db -import datetime +from datetime import datetime # this is telling flask about my database task table @@ -24,4 +24,5 @@ def json_object(self): "description": self.description, "is_complete": self.completed_at_helper() } - # Use this helper function any time the return is expected to be complete + # Use this helper function any time the return is expected to be complete ^^^ + \ No newline at end of file diff --git a/app/routes.py b/app/routes.py index 6e3dbb140..673051758 100644 --- a/app/routes.py +++ b/app/routes.py @@ -4,7 +4,7 @@ from flask import request, Blueprint, make_response from flask import jsonify import datetime - +from sqlalchemy import asc, desc task_bp = Blueprint("tasks", __name__, url_prefix="/tasks") @@ -19,30 +19,17 @@ def get_single_task(task_id): complete = task.completed_at_helper() # Helper function to return boolean if request.method == "GET": - return jsonify({ - "task": { - "id": task.id, - "title": task.title, - "description": task.description, - "is_complete": complete - }, - }), 200 + return jsonify({"task": task.json_object()}), 200 + elif request.method == "PUT": form_data = request.get_json() task.title = form_data["title"] task.description = form_data["description"] - task.is_complete = form_data["completed_at"] # TODO: fix this + task.is_complete = form_data["completed_at"] db.session.commit() - return jsonify({ - "task": { - "id": task.id, - "title": task.title, - "description": task.description, - "is_complete": task.completed_at_helper() - } - }), 200 + return jsonify({"task": task.json_object()}),200 elif request.method == "DELETE": db.session.delete(task) @@ -52,15 +39,36 @@ def get_single_task(task_id): @task_bp.route("", methods=["GET", "POST"]) def handle_tasks(): + + + if request.method == "GET": - tasks = Task.query.all() + + request_value = request.args.get("sort") + + if request_value == None: + tasks = Task.query.all() + + if request_value == "asc": # checking if there is a sort arg with the value of asc. + tasks = Task.query.order_by(Task.title.asc()) #Task is the the model and query is a class method + + + if request_value == "desc": + tasks = Task.query.order_by(Task.title.desc()) task_response = [] for task in tasks: # using jsonobject helper to create a dictionary with id, title, description, isComplete task_response.append(task.json_object()) + return jsonify(task_response), 200 + + + + + + elif request.method == "POST": request_body = request.get_json() @@ -75,8 +83,8 @@ def handle_tasks(): db.session.add(new_task) db.session.commit() - # created a new task and changed my task objet into JSON # called my new_task.completed_at_helper. + # created a new task and changed my task objet into JSON # using jsonobject helper to create a dictionary with id, title, description, isComplete return jsonify({"task": new_task.json_object()}), 201 @@ -88,28 +96,4 @@ def handle_tasks(): # # api request using url request can i find route that matches -# @task_bp.route("", methods=["POST", "GET"], strict_slashes=False) -# def post_task(): -# if request.method == "POST": -# request_body = request.get_json() - -# if "completed_at" not in request_body or "description" not in request_body or "title" not in request_body: -# return jsonify({ -# "details": "Invalid data" -# }), 400 - -# # This is allowing POSTMAN to test the requesting URL infomation by creating a route -# task = Task(title=request_body["title"], -# description=request_body["description"], -# completed_at=request_body["completed_at"]) -# db.session.add(task) # Session -# db.session.commit() -# complete = task.completed_at_helper() -# return jsonify({ -# "task": { -# "id": 1, -# "title": task.title, -# "description": task.description, -# "is_complete": complete -# } -# }), 201 + From e5f2ae4b24580a84894e3377c5f247c773b17b5d Mon Sep 17 00:00:00 2001 From: Brittany Clemons Date: Sun, 9 May 2021 21:48:07 -0700 Subject: [PATCH 5/9] wave 3 passed --- app/routes.py | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/app/routes.py b/app/routes.py index 673051758..4e479b096 100644 --- a/app/routes.py +++ b/app/routes.py @@ -3,11 +3,11 @@ from flask import request from flask import request, Blueprint, make_response from flask import jsonify -import datetime +from datetime import datetime from sqlalchemy import asc, desc task_bp = Blueprint("tasks", __name__, url_prefix="/tasks") - +#localhost:9000/tasks/2 @task_bp.route("/", methods=["GET", "PUT", "DELETE"], strict_slashes=False) def get_single_task(task_id): @@ -39,9 +39,6 @@ def get_single_task(task_id): @task_bp.route("", methods=["GET", "POST"]) def handle_tasks(): - - - if request.method == "GET": request_value = request.args.get("sort") @@ -63,12 +60,6 @@ def handle_tasks(): return jsonify(task_response), 200 - - - - - - elif request.method == "POST": request_body = request.get_json() @@ -90,10 +81,42 @@ def handle_tasks(): db.session.add(new_task) db.session.commit() - + +#PATCH localhost:9000/tasks/1/mark_complete +@task_bp.route("//mark_complete", methods=["PATCH"], strict_slashes=False) +def mark_complete(task_id): + # If POSTMAN (request)searches for a patch path + if request.method == "PATCH": + #query is seaching TASK (ID, TITLE, DESCRIPTION, AND COMPLEATED_AT) and "get" getting the task_id + task = Task.query.get(task_id) + # If the task is NONE return the not found 404 code + if task is None: + return jsonify(None), 404 + # If None is found than my code searches for what id is being mark_compleated and with my compleated_at_helper() marking complete turn/ + # into a true statement which then timestamps the date and time completed. + task.completed_at = datetime.now() + #jsonify my object and "task"(STR) json_object is the jsonifyed id, title, description, and compleated_at function + return jsonify({"task": task.json_object()}),200 # 200 ok code + +#PATCH localhost:9000/tasks/2/mark_incomplete(is saying this id should be marked as complete) +@task_bp.route("//mark_incomplete", methods=["PATCH"], strict_slashes=False) +def mark_incomplete(task_id): + + if request.method == "PATCH": + #query is seaching TASK (ID, TITLE, DESCRIPTION, AND COMPLEATED_AT) and "get" getting the task_id + task = Task.query.get(task_id) + # If the task is NONE return the not found 404 code + if task is None: + return jsonify(None), 404 + + task.completed_at = None + + return jsonify({"task": task.json_object()}),200 + # post man testing eviroment -# # api request using url request can i find route that matches +#API request using url request can i find route that matches + From d073f473656a85d53af6bc739ccd1a5273f3c5de Mon Sep 17 00:00:00 2001 From: Brittany Clemons Date: Wed, 12 May 2021 15:15:22 -0700 Subject: [PATCH 6/9] Added Slack Bot --- app/models/task.py | 2 +- app/routes.py | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/models/task.py b/app/models/task.py index 4dd75c946..4d3140b7b 100644 --- a/app/models/task.py +++ b/app/models/task.py @@ -25,4 +25,4 @@ def json_object(self): "is_complete": self.completed_at_helper() } # Use this helper function any time the return is expected to be complete ^^^ - \ No newline at end of file + diff --git a/app/routes.py b/app/routes.py index 4e479b096..7448cf449 100644 --- a/app/routes.py +++ b/app/routes.py @@ -5,6 +5,9 @@ from flask import jsonify from datetime import datetime from sqlalchemy import asc, desc +import requests +import json +import os task_bp = Blueprint("tasks", __name__, url_prefix="/tasks") #localhost:9000/tasks/2 @@ -81,7 +84,16 @@ def handle_tasks(): db.session.add(new_task) db.session.commit() - + +def slack_bot(task): + url = "https://slack.com/api/chat.postMessage?channel=task-notifications" + slack_token = os.environ.get("SLACK") + + payload = {"text": f"Someone just completed the task: '{task.title}'!"} + headers = {"Authorization": f"Bearer {slack_token}"} + + return requests.request("PATCH", url, headers=headers, data=payload) + #PATCH localhost:9000/tasks/1/mark_complete @task_bp.route("//mark_complete", methods=["PATCH"], strict_slashes=False) def mark_complete(task_id): @@ -95,6 +107,13 @@ def mark_complete(task_id): # If None is found than my code searches for what id is being mark_compleated and with my compleated_at_helper() marking complete turn/ # into a true statement which then timestamps the date and time completed. task.completed_at = datetime.now() + + # where I saved the change to db + db.session.commit() + + # call slackbot + slack_bot(task) + #jsonify my object and "task"(STR) json_object is the jsonifyed id, title, description, and compleated_at function return jsonify({"task": task.json_object()}),200 # 200 ok code @@ -111,12 +130,8 @@ def mark_incomplete(task_id): task.completed_at = None - return jsonify({"task": task.json_object()}),200 + return jsonify({"task":task.json_object()}),200 # post man testing eviroment #API request using url request can i find route that matches - - - - From 1096b55900b5ec74d97af19c35f5400a506d7c99 Mon Sep 17 00:00:00 2001 From: Brittany Clemons Date: Wed, 12 May 2021 16:58:10 -0700 Subject: [PATCH 7/9] remove comments --- app/models/goal.py | 7 +++++++ app/models/task.py | 2 +- app/routes.py | 52 ++++++++++++++++++++++++++-------------------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/app/models/goal.py b/app/models/goal.py index 8cad278f8..79ced2ff5 100644 --- a/app/models/goal.py +++ b/app/models/goal.py @@ -4,3 +4,10 @@ class Goal(db.Model): goal_id = db.Column(db.Integer, primary_key=True) + title = db.Column(db.String) + + def goal_json_object(self): + return { + "id": self.goal_id, + "title": self.title + } \ No newline at end of file diff --git a/app/models/task.py b/app/models/task.py index 4d3140b7b..4dd75c946 100644 --- a/app/models/task.py +++ b/app/models/task.py @@ -25,4 +25,4 @@ def json_object(self): "is_complete": self.completed_at_helper() } # Use this helper function any time the return is expected to be complete ^^^ - + \ No newline at end of file diff --git a/app/routes.py b/app/routes.py index 7448cf449..9f80236f6 100644 --- a/app/routes.py +++ b/app/routes.py @@ -8,10 +8,12 @@ import requests import json import os -task_bp = Blueprint("tasks", __name__, url_prefix="/tasks") +from app.models.goal import Goal + -#localhost:9000/tasks/2 +task_bp = Blueprint("tasks", __name__, url_prefix="/tasks") @task_bp.route("/", methods=["GET", "PUT", "DELETE"], strict_slashes=False) + def get_single_task(task_id): task = Task.query.get(task_id) @@ -49,8 +51,8 @@ def handle_tasks(): if request_value == None: tasks = Task.query.all() - if request_value == "asc": # checking if there is a sort arg with the value of asc. - tasks = Task.query.order_by(Task.title.asc()) #Task is the the model and query is a class method + if request_value == "asc": + tasks = Task.query.order_by(Task.title.asc()) if request_value == "desc": @@ -58,7 +60,7 @@ def handle_tasks(): task_response = [] for task in tasks: - # using jsonobject helper to create a dictionary with id, title, description, isComplete + task_response.append(task.json_object()) return jsonify(task_response), 200 @@ -77,9 +79,7 @@ def handle_tasks(): db.session.add(new_task) db.session.commit() - # called my new_task.completed_at_helper. - # created a new task and changed my task objet into JSON - # using jsonobject helper to create a dictionary with id, title, description, isComplete + return jsonify({"task": new_task.json_object()}), 201 db.session.add(new_task) @@ -94,37 +94,36 @@ def slack_bot(task): return requests.request("PATCH", url, headers=headers, data=payload) -#PATCH localhost:9000/tasks/1/mark_complete + @task_bp.route("//mark_complete", methods=["PATCH"], strict_slashes=False) def mark_complete(task_id): - # If POSTMAN (request)searches for a patch path + if request.method == "PATCH": - #query is seaching TASK (ID, TITLE, DESCRIPTION, AND COMPLEATED_AT) and "get" getting the task_id + task = Task.query.get(task_id) - # If the task is NONE return the not found 404 code + if task is None: return jsonify(None), 404 - # If None is found than my code searches for what id is being mark_compleated and with my compleated_at_helper() marking complete turn/ - # into a true statement which then timestamps the date and time completed. + task.completed_at = datetime.now() - # where I saved the change to db + db.session.commit() # call slackbot slack_bot(task) - #jsonify my object and "task"(STR) json_object is the jsonifyed id, title, description, and compleated_at function - return jsonify({"task": task.json_object()}),200 # 200 ok code + + return jsonify({"task": task.json_object()}),200 + -#PATCH localhost:9000/tasks/2/mark_incomplete(is saying this id should be marked as complete) @task_bp.route("//mark_incomplete", methods=["PATCH"], strict_slashes=False) def mark_incomplete(task_id): if request.method == "PATCH": - #query is seaching TASK (ID, TITLE, DESCRIPTION, AND COMPLEATED_AT) and "get" getting the task_id + task = Task.query.get(task_id) - # If the task is NONE return the not found 404 code + if task is None: return jsonify(None), 404 @@ -132,6 +131,15 @@ def mark_incomplete(task_id): return jsonify({"task":task.json_object()}),200 +goal_bp = Blueprint("goals", __name__, url_prefix="/goals") + +@goal_bp.route("", methods=["POST"]) +def one_goal(): + + if request.method == "POST": + goal = Goal.query.post() -# post man testing eviroment -#API request using url request can i find route that matches + request_body = request.goal_json_object() + db.session.commit() + + return jsonify({"goal":goal.goal_json_object()}),201 From dc826d1eac7f81fe8c35b6a990ef36cb3d2c5e93 Mon Sep 17 00:00:00 2001 From: Brittany Clemons Date: Wed, 12 May 2021 20:47:42 -0700 Subject: [PATCH 8/9] PASSED WAVE 5 --- app/__init__.py | 3 ++- app/models/goal.py | 8 +++++--- app/models/task.py | 1 - app/routes.py | 51 +++++++++++++++++++++++++++++++++++++++------- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 63a3bdc84..f0dc5e0e5 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -32,9 +32,10 @@ def create_app(test_config=None): from app.models.task import Task from app.models.goal import Goal - from .routes import task_bp + from .routes import task_bp, goal_bp # Register Blueprints here app.register_blueprint(task_bp) + app.register_blueprint(goal_bp) return app diff --git a/app/models/goal.py b/app/models/goal.py index 79ced2ff5..f11e59ee0 100644 --- a/app/models/goal.py +++ b/app/models/goal.py @@ -1,13 +1,15 @@ from flask import current_app from app import db - class Goal(db.Model): - goal_id = db.Column(db.Integer, primary_key=True) + goal_id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String) def goal_json_object(self): return { "id": self.goal_id, "title": self.title - } \ No newline at end of file + } + def bad_request(self): + if self.title == None: + return None \ No newline at end of file diff --git a/app/models/task.py b/app/models/task.py index 4dd75c946..71614a6b3 100644 --- a/app/models/task.py +++ b/app/models/task.py @@ -3,7 +3,6 @@ from datetime import datetime # this is telling flask about my database task table - class Task(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String) diff --git a/app/routes.py b/app/routes.py index 9f80236f6..b8ab93910 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,5 +1,6 @@ from app import db from app.models.task import Task +from app.models.goal import Goal from flask import request from flask import request, Blueprint, make_response from flask import jsonify @@ -8,12 +9,9 @@ import requests import json import os -from app.models.goal import Goal - task_bp = Blueprint("tasks", __name__, url_prefix="/tasks") @task_bp.route("/", methods=["GET", "PUT", "DELETE"], strict_slashes=False) - def get_single_task(task_id): task = Task.query.get(task_id) @@ -132,14 +130,53 @@ def mark_incomplete(task_id): return jsonify({"task":task.json_object()}),200 goal_bp = Blueprint("goals", __name__, url_prefix="/goals") +@goal_bp.route("/", methods=["GET", "PUT", "DELETE"], strict_slashes=False) +def get_goal(goal_id): + + goal = Goal.query.get(goal_id) + + if goal is None: + return jsonify(None), 404 -@goal_bp.route("", methods=["POST"]) + if request.method == "GET": + return jsonify({"goal": goal.goal_json_object()}), 200 + + elif request.method == "PUT": + form_data = request.get_json() + + goal.title = form_data["title"] + + db.session.commit() + return jsonify({"goal": goal.goal_json_object()}),200 + + elif request.method == "DELETE": + db.session.delete(goal) + db.session.commit() + + return jsonify({"details": f'Goal {goal.goal_id} "{goal.title}" successfully deleted'}), 200 + +@goal_bp.route("", methods=["POST", "GET"], strict_slashes=False) def one_goal(): + if request.method == "GET": + goals = Goal.query.all() + + goal_response = [] + + for goal in goals: + goal_response.append(goal.goal_json_object()) + + return jsonify(goal_response), 200 if request.method == "POST": - goal = Goal.query.post() + request_body = request.get_json() + + if request_body == {}: + return jsonify({"details": f'Invalid data'}), 400 + + new_goal = Goal(title=request_body["title"]) - request_body = request.goal_json_object() + db.session.add(new_goal) db.session.commit() - return jsonify({"goal":goal.goal_json_object()}),201 + return jsonify({"goal":new_goal.goal_json_object()}),201 + \ No newline at end of file From 77e97228d40ff8d79a1bf9b5defa3115a1cc8b31 Mon Sep 17 00:00:00 2001 From: Brittany Clemons Date: Thu, 13 May 2021 00:45:21 -0700 Subject: [PATCH 9/9] All waves passed --- app/__init__.py | 3 +- app/models/goal.py | 24 +++++++++++-- app/models/task.py | 7 +++- app/routes.py | 35 +++++++++++++++---- migrations/versions/0b0197f93cdf_.py | 28 --------------- migrations/versions/1cfb6e9ac5ef_.py | 28 --------------- migrations/versions/1d08448e6c2b_.py | 34 ------------------ .../{f92a2eea5f0d_.py => 594ba04b1737_.py} | 16 +++++---- migrations/versions/b30dac682d4f_.py | 28 --------------- migrations/versions/b5e27277c35f_.py | 28 --------------- 10 files changed, 68 insertions(+), 163 deletions(-) delete mode 100644 migrations/versions/0b0197f93cdf_.py delete mode 100644 migrations/versions/1cfb6e9ac5ef_.py delete mode 100644 migrations/versions/1d08448e6c2b_.py rename migrations/versions/{f92a2eea5f0d_.py => 594ba04b1737_.py} (63%) delete mode 100644 migrations/versions/b30dac682d4f_.py delete mode 100644 migrations/versions/b5e27277c35f_.py diff --git a/app/__init__.py b/app/__init__.py index f0dc5e0e5..a6469d387 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -24,7 +24,8 @@ def create_app(test_config=None): app.config["TESTING"] = True app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( "SQLALCHEMY_TEST_DATABASE_URI") - + app.config['JSON_SORT_KEYS']=False + db.init_app(app) migrate.init_app(app, db) diff --git a/app/models/goal.py b/app/models/goal.py index f11e59ee0..f7ac674cc 100644 --- a/app/models/goal.py +++ b/app/models/goal.py @@ -1,15 +1,33 @@ +from types import new_class from flask import current_app from app import db +from app.models.task import Task +# Parent Class + class Goal(db.Model): goal_id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String) + tasks = db.relationship('Task', backref='goal', lazy=True) def goal_json_object(self): return { "id": self.goal_id, "title": self.title } - def bad_request(self): - if self.title == None: - return None \ No newline at end of file + + def goal_json_object_with_tasks(self): + new_list = [] + for task in self.tasks: + new_list.append({ + "id": task.id, + "goal_id": task.goal_id, + "title": task.title, + "description": task.description, + "is_complete": task.completed_at_helper() + }) + return { + "id": self.goal_id, + "title": self.title, + "tasks": new_list + } diff --git a/app/models/task.py b/app/models/task.py index 71614a6b3..048dba037 100644 --- a/app/models/task.py +++ b/app/models/task.py @@ -9,6 +9,7 @@ class Task(db.Model): description = db.Column(db.String) completed_at = db.Column(db.DateTime) + goal_id = db.Column(db.Integer, db.ForeignKey('goal.goal_id'), nullable=True) def completed_at_helper(self): if self.completed_at == None: complete = False @@ -17,11 +18,15 @@ def completed_at_helper(self): return complete def json_object(self): - return { + + new_reponse = { "id": self.id, "title": self.title, "description": self.description, "is_complete": self.completed_at_helper() } + if self.goal_id is not None: + new_reponse["goal_id"] = self.goal_id + return new_reponse # Use this helper function any time the return is expected to be complete ^^^ \ No newline at end of file diff --git a/app/routes.py b/app/routes.py index b8ab93910..3d48bf3be 100644 --- a/app/routes.py +++ b/app/routes.py @@ -9,11 +9,12 @@ import requests import json import os - +goal_bp = Blueprint("goals", __name__, url_prefix="/goals") task_bp = Blueprint("tasks", __name__, url_prefix="/tasks") + +#This is is a new endpoint. @task_bp.route("/", methods=["GET", "PUT", "DELETE"], strict_slashes=False) def get_single_task(task_id): - task = Task.query.get(task_id) if task is None: @@ -39,7 +40,6 @@ def get_single_task(task_id): db.session.commit() return jsonify({"details": f'Task {task.id} "{task.title}" successfully deleted'}), 200 - @task_bp.route("", methods=["GET", "POST"]) def handle_tasks(): if request.method == "GET": @@ -129,7 +129,7 @@ def mark_incomplete(task_id): return jsonify({"task":task.json_object()}),200 -goal_bp = Blueprint("goals", __name__, url_prefix="/goals") + @goal_bp.route("/", methods=["GET", "PUT", "DELETE"], strict_slashes=False) def get_goal(goal_id): @@ -143,7 +143,7 @@ def get_goal(goal_id): elif request.method == "PUT": form_data = request.get_json() - + #Go and get the data from the request goal.title = form_data["title"] db.session.commit() @@ -179,4 +179,27 @@ def one_goal(): db.session.commit() return jsonify({"goal":new_goal.goal_json_object()}),201 - \ No newline at end of file + +#New endpoint to look up goals and task +@goal_bp.route("//tasks", methods=["POST"], strict_slashes=False) +def goals_task(goal_id): + + form_data = request.get_json() + + for task_id in form_data["task_ids"]: + + task = Task.query.get(task_id) + + task.goal_id = goal_id + + db.session.commit() + + return make_response({"id": int(goal_id),"task_ids":form_data["task_ids"]}), 200 + +@goal_bp.route("//tasks", methods=["GET"], strict_slashes=False) +def goals_task_get(goal_id): + if request.method == "GET": + goal = Goal.query.get(goal_id) + if goal is None: + return make_response("", 404) + return jsonify(goal.goal_json_object_with_tasks()) \ No newline at end of file diff --git a/migrations/versions/0b0197f93cdf_.py b/migrations/versions/0b0197f93cdf_.py deleted file mode 100644 index f7bccb000..000000000 --- a/migrations/versions/0b0197f93cdf_.py +++ /dev/null @@ -1,28 +0,0 @@ -"""empty message - -Revision ID: 0b0197f93cdf -Revises: b30dac682d4f -Create Date: 2021-05-05 12:35:41.039681 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '0b0197f93cdf' -down_revision = 'b30dac682d4f' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('task', sa.Column('brittany', sa.String(), nullable=True)) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('task', 'brittany') - # ### end Alembic commands ### diff --git a/migrations/versions/1cfb6e9ac5ef_.py b/migrations/versions/1cfb6e9ac5ef_.py deleted file mode 100644 index d5ff11b21..000000000 --- a/migrations/versions/1cfb6e9ac5ef_.py +++ /dev/null @@ -1,28 +0,0 @@ -"""empty message - -Revision ID: 1cfb6e9ac5ef -Revises: 0b0197f93cdf -Create Date: 2021-05-05 12:37:55.551305 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '1cfb6e9ac5ef' -down_revision = '0b0197f93cdf' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('task', 'brittany') - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('task', sa.Column('brittany', sa.VARCHAR(), autoincrement=False, nullable=True)) - # ### end Alembic commands ### diff --git a/migrations/versions/1d08448e6c2b_.py b/migrations/versions/1d08448e6c2b_.py deleted file mode 100644 index f7c8eae63..000000000 --- a/migrations/versions/1d08448e6c2b_.py +++ /dev/null @@ -1,34 +0,0 @@ -"""empty message - -Revision ID: 1d08448e6c2b -Revises: f92a2eea5f0d -Create Date: 2021-05-04 22:45:56.813749 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '1d08448e6c2b' -down_revision = 'f92a2eea5f0d' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.alter_column('task', 'title', - existing_type=sa.VARCHAR(length=200), - nullable=True) - op.drop_column('task', 'completed_at') - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('task', sa.Column('completed_at', sa.BOOLEAN(), autoincrement=False, nullable=True)) - op.alter_column('task', 'title', - existing_type=sa.VARCHAR(length=200), - nullable=False) - # ### end Alembic commands ### diff --git a/migrations/versions/f92a2eea5f0d_.py b/migrations/versions/594ba04b1737_.py similarity index 63% rename from migrations/versions/f92a2eea5f0d_.py rename to migrations/versions/594ba04b1737_.py index a90e74951..4e8f01e8f 100644 --- a/migrations/versions/f92a2eea5f0d_.py +++ b/migrations/versions/594ba04b1737_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: f92a2eea5f0d +Revision ID: 594ba04b1737 Revises: -Create Date: 2021-05-04 19:17:30.656774 +Create Date: 2021-05-13 00:13:03.256590 """ from alembic import op @@ -10,7 +10,7 @@ # revision identifiers, used by Alembic. -revision = 'f92a2eea5f0d' +revision = '594ba04b1737' down_revision = None branch_labels = None depends_on = None @@ -19,14 +19,18 @@ def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('goal', - sa.Column('goal_id', sa.Integer(), nullable=False), + sa.Column('goal_id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('title', sa.String(), nullable=True), sa.PrimaryKeyConstraint('goal_id') ) op.create_table('task', - sa.Column('task_id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('title', sa.String(), nullable=True), sa.Column('description', sa.String(), nullable=True), - sa.PrimaryKeyConstraint('task_id') + sa.Column('completed_at', sa.DateTime(), nullable=True), + sa.Column('goal_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['goal_id'], ['goal.goal_id'], ), + sa.PrimaryKeyConstraint('id') ) # ### end Alembic commands ### diff --git a/migrations/versions/b30dac682d4f_.py b/migrations/versions/b30dac682d4f_.py deleted file mode 100644 index b964cede8..000000000 --- a/migrations/versions/b30dac682d4f_.py +++ /dev/null @@ -1,28 +0,0 @@ -"""empty message - -Revision ID: b30dac682d4f -Revises: b5e27277c35f -Create Date: 2021-05-05 00:22:39.394816 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'b30dac682d4f' -down_revision = 'b5e27277c35f' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('task', sa.Column('completed_at', sa.DateTime(), nullable=True)) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('task', 'completed_at') - # ### end Alembic commands ### diff --git a/migrations/versions/b5e27277c35f_.py b/migrations/versions/b5e27277c35f_.py deleted file mode 100644 index 81e34e3c5..000000000 --- a/migrations/versions/b5e27277c35f_.py +++ /dev/null @@ -1,28 +0,0 @@ -"""empty message - -Revision ID: b5e27277c35f -Revises: 1d08448e6c2b -Create Date: 2021-05-05 00:17:41.643437 - -""" -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -# revision identifiers, used by Alembic. -revision = 'b5e27277c35f' -down_revision = '1d08448e6c2b' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('task', 'completed_at') - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('task', sa.Column('completed_at', postgresql.ARRAY(postgresql.TIME()), autoincrement=False, nullable=True, comment='Time stamp when completed ')) - # ### end Alembic commands ###