From 3ef86bca1e168cc69313c7dd9fbfe13c9a8d400a Mon Sep 17 00:00:00 2001 From: androiddrew Date: Sun, 10 Jun 2018 17:48:43 -0400 Subject: [PATCH] Fixed migrations and dev requirements --- cookie_api/models.py | 8 ++ dev_requirements.in | 4 + dev_requirements.txt | 11 ++- migrations/env.py | 2 - .../versions/227892845cde_initial_models.py | 28 ------- .../374c36260db7_cookie_domain_model.py | 75 +++++++++++++++++++ .../versions/710505cf5d4c_empty_init.py | 24 ++++++ ...eb9aabef1dc_changed_datetimes_to_be_utc.py | 67 ----------------- .../82595a1e5193_added_confirmed_to_user.py | 30 -------- requirements.txt | 2 +- setup.py | 2 +- 11 files changed, 120 insertions(+), 133 deletions(-) create mode 100644 dev_requirements.in delete mode 100644 migrations/versions/227892845cde_initial_models.py create mode 100644 migrations/versions/374c36260db7_cookie_domain_model.py create mode 100644 migrations/versions/710505cf5d4c_empty_init.py delete mode 100644 migrations/versions/7eb9aabef1dc_changed_datetimes_to_be_utc.py delete mode 100644 migrations/versions/82595a1e5193_added_confirmed_to_user.py diff --git a/cookie_api/models.py b/cookie_api/models.py index e19b4ce..ff75feb 100644 --- a/cookie_api/models.py +++ b/cookie_api/models.py @@ -2,6 +2,7 @@ import bcrypt from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Boolean, Numeric from sqlalchemy.orm import relationship, backref +from sqlalchemy.schema import CreateColumn from sqlalchemy.sql import expression from sqlalchemy.ext.compiler import compiles from sqlalchemy.types import DateTime as DateTimeType @@ -20,6 +21,13 @@ def pg_utcnow(element, compiler, **kw): return "TIMEZONE('utc', CURRENT_TIMESTAMP)" +@compiles(CreateColumn, 'postgresql') +def use_identity(element, compiler, **kw): + text = compiler.visit_create_column(element, **kw) + text = text.replace("SERIAL", "INT GENERATED BY DEFAULT AS IDENTITY") + return text + + Base = declarative_base() diff --git a/dev_requirements.in b/dev_requirements.in new file mode 100644 index 0000000..5bfd6e8 --- /dev/null +++ b/dev_requirements.in @@ -0,0 +1,4 @@ +alembic +pytest +pytest-cov +tox \ No newline at end of file diff --git a/dev_requirements.txt b/dev_requirements.txt index a34dabd..f00f3ab 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -4,17 +4,20 @@ # # pip-compile --output-file dev_requirements.txt dev_requirements.in # +alembic==0.9.9 atomicwrites==1.1.5 # via pytest attrs==18.1.0 # via pytest -click==6.7 # via pip-tools coverage==4.5.1 # via pytest-cov -first==2.0.1 # via pip-tools +mako==1.0.7 # via alembic +markupsafe==1.0 # via mako more-itertools==4.2.0 # via pytest -pip-tools==2.0.2 pluggy==0.6.0 # via pytest, tox py==1.5.3 # via pytest, tox pytest-cov==2.5.1 pytest==3.6.1 -six==1.11.0 # via more-itertools, pip-tools, pytest, tox +python-dateutil==2.7.3 # via alembic +python-editor==1.0.3 # via alembic +six==1.11.0 # via more-itertools, pytest, python-dateutil, tox +sqlalchemy==1.2.8 # via alembic tox==3.0.0 virtualenv==16.0.0 # via tox diff --git a/migrations/env.py b/migrations/env.py index d4a2092..70c3c13 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -18,7 +18,6 @@ fileConfig(config.config_file_name) # target_metadata = mymodel.Base.metadata target_metadata = Base.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") @@ -66,7 +65,6 @@ def run_migrations_online(): with context.begin_transaction(): context.run_migrations() - if context.is_offline_mode(): run_migrations_offline() else: diff --git a/migrations/versions/227892845cde_initial_models.py b/migrations/versions/227892845cde_initial_models.py deleted file mode 100644 index e1fee76..0000000 --- a/migrations/versions/227892845cde_initial_models.py +++ /dev/null @@ -1,28 +0,0 @@ -"""initial models - -Revision ID: 227892845cde -Revises: -Create Date: 2018-01-15 14:58:17.931063 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '227892845cde' -down_revision = None -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - pass - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - pass - # ### end Alembic commands ### diff --git a/migrations/versions/374c36260db7_cookie_domain_model.py b/migrations/versions/374c36260db7_cookie_domain_model.py new file mode 100644 index 0000000..f9f862d --- /dev/null +++ b/migrations/versions/374c36260db7_cookie_domain_model.py @@ -0,0 +1,75 @@ +"""Cookie Domain Model + +Revision ID: 374c36260db7 +Revises: 710505cf5d4c +Create Date: 2018-06-10 17:39:18.891568 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '374c36260db7' +down_revision = '710505cf5d4c' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('cookies', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_date', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', CURRENT_TIMESTAMP)"), nullable=True), + sa.Column('modified_date', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', CURRENT_TIMESTAMP)"), nullable=True), + sa.Column('name', sa.String(length=50), nullable=True), + sa.Column('recipe_url', sa.String(length=255), nullable=True), + sa.Column('sku', sa.String(length=55), nullable=True), + sa.Column('qoh', sa.Integer(), nullable=True), + sa.Column('unit_cost', sa.Numeric(precision=12, scale=2), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_cookies_name'), 'cookies', ['name'], unique=False) + op.create_table('users', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_date', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', CURRENT_TIMESTAMP)"), nullable=True), + sa.Column('modified_date', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', CURRENT_TIMESTAMP)"), nullable=True), + sa.Column('email', sa.String(length=255), nullable=False), + sa.Column('password', sa.String(length=255), nullable=True), + sa.Column('admin', sa.Boolean(), nullable=False), + sa.Column('confirmed', sa.Boolean(), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('email') + ) + op.create_table('orders', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_date', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', CURRENT_TIMESTAMP)"), nullable=True), + sa.Column('modified_date', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', CURRENT_TIMESTAMP)"), nullable=True), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('shipped', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('line_items', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_date', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', CURRENT_TIMESTAMP)"), nullable=True), + sa.Column('modified_date', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', CURRENT_TIMESTAMP)"), nullable=True), + sa.Column('order_id', sa.Integer(), nullable=False), + sa.Column('cookie_id', sa.Integer(), nullable=False), + sa.Column('quantity', sa.Integer(), nullable=True), + sa.Column('extended_cost', sa.Numeric(precision=12, scale=2), nullable=True), + sa.ForeignKeyConstraint(['cookie_id'], ['cookies.id'], ), + sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('line_items') + op.drop_table('orders') + op.drop_table('users') + op.drop_index(op.f('ix_cookies_name'), table_name='cookies') + op.drop_table('cookies') + # ### end Alembic commands ### diff --git a/migrations/versions/710505cf5d4c_empty_init.py b/migrations/versions/710505cf5d4c_empty_init.py new file mode 100644 index 0000000..4d6de2e --- /dev/null +++ b/migrations/versions/710505cf5d4c_empty_init.py @@ -0,0 +1,24 @@ +"""Empty Init + +Revision ID: 710505cf5d4c +Revises: +Create Date: 2018-06-10 17:31:37.014032 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '710505cf5d4c' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + pass + + +def downgrade(): + pass diff --git a/migrations/versions/7eb9aabef1dc_changed_datetimes_to_be_utc.py b/migrations/versions/7eb9aabef1dc_changed_datetimes_to_be_utc.py deleted file mode 100644 index eef833b..0000000 --- a/migrations/versions/7eb9aabef1dc_changed_datetimes_to_be_utc.py +++ /dev/null @@ -1,67 +0,0 @@ -"""Changed Datetimes to be UTC - -Revision ID: 7eb9aabef1dc -Revises: 82595a1e5193 -Create Date: 2018-05-07 13:59:32.923484 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '7eb9aabef1dc' -down_revision = '82595a1e5193' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.alter_column( - table_name='cookies', - column_name='created_date', - type_=sa.DateTime(timezone=True) - ) - op.alter_column( - table_name='cookies', - column_name='modified_date', - type_=sa.DateTime(timezone=True) - ) - op.alter_column( - table_name='users', - column_name='created_date', - type_=sa.DateTime(timezone=True) - ) - op.alter_column( - table_name='users', - column_name='modified_date', - type_=sa.DateTime(timezone=True) - ) - op.alter_column( - table_name='orders', - column_name='created_date', - type_=sa.DateTime(timezone=True) - ) - op.alter_column( - table_name='orders', - column_name='modified_date', - type_=sa.DateTime(timezone=True) - ) - op.alter_column( - table_name='line_items', - column_name='created_date', - type_=sa.DateTime(timezone=True) - ) - op.alter_column( - table_name='line_items', - column_name='modified_date', - type_=sa.DateTime(timezone=True) - ) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - pass - # ### end Alembic commands ### diff --git a/migrations/versions/82595a1e5193_added_confirmed_to_user.py b/migrations/versions/82595a1e5193_added_confirmed_to_user.py deleted file mode 100644 index 6b30523..0000000 --- a/migrations/versions/82595a1e5193_added_confirmed_to_user.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Added confirmed to user - -Revision ID: 82595a1e5193 -Revises: 227892845cde -Create Date: 2018-01-15 15:34:46.028181 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '82595a1e5193' -down_revision = '227892845cde' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('users', sa.Column('confirmed', sa.Boolean())) - op.execute('UPDATE users SET confirmed=FALSE') - op.alter_column('users', 'confirmed', nullable=False) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('users', 'confirmed') - # ### end Alembic commands ### diff --git a/requirements.txt b/requirements.txt index 34f5d36..99e8a43 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,7 +23,7 @@ pyjwt==1.6.4 # via apistar-jwt pyyaml==3.12 # via apistar requests==2.18.4 # via apistar six==1.11.0 # via bcrypt -sqlalchemy==1.2.7 +sqlalchemy==1.2.8 urllib3==1.22 # via requests werkzeug==0.14.1 # via apistar whitenoise==3.3.1 # via apistar diff --git a/setup.py b/setup.py index efdc92a..2c66302 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ requirements = [ 'itsdangerous==0.24', 'logbook==1.3.3', 'psycopg2-binary==2.7.4', - 'sqlalchemy==1.2.7', + 'sqlalchemy==1.2.8', ] test_requirements = [